Merge pull request #297 from olleolleolle/feature/linting-parser-setup

Rubocop: less complex methods in parser.rb
This commit is contained in:
Petr Korolev 2015-10-22 15:24:47 +03:00
commit b1d2b7d828
3 changed files with 22 additions and 26 deletions

View File

@ -7,22 +7,16 @@ module GitHubChangelogGenerator
class Parser class Parser
# parse options with optparse # parse options with optparse
def self.parse_options def self.parse_options
options = get_default_options options = default_options
parser_file = ParserFile.new options ParserFile.new(options).parse!
parser_file.parse!
parser = setup_parser(options) parser = setup_parser(options)
parser.parse! parser.parse!
if options[:user].nil? || options[:project].nil? user_and_project_from_git(options)
detect_user_and_project(options, ARGV[0], ARGV[1])
end
if !options[:user] || !options[:project] abort(parser.banner) unless options[:user] && options[:project]
puts parser.banner
exit
end
print_options(options) print_options(options)
@ -165,8 +159,8 @@ module GitHubChangelogGenerator
end end
# just get default options # just get default options
def self.get_default_options def self.default_options
options = { {
tag1: nil, tag1: nil,
tag2: nil, tag2: nil,
date_format: "%Y-%m-%d", date_format: "%Y-%m-%d",
@ -194,21 +188,25 @@ module GitHubChangelogGenerator
enhancement_prefix: "**Implemented enhancements:**", enhancement_prefix: "**Implemented enhancements:**",
git_remote: "origin" git_remote: "origin"
} }
end
options def self.user_and_project_from_git
if options[:user].nil? || options[:project].nil?
detect_user_and_project(options, ARGV[0], ARGV[1])
end
end end
# Detects user and project from git # Detects user and project from git
def self.detect_user_and_project(options, arg0 = nil, arg1 = nil) def self.detect_user_and_project(options, arg0 = nil, arg1 = nil)
options[:user], options[:project] = user_project_from_option(arg0, arg1, options[:github_site]) options[:user], options[:project] = user_project_from_option(arg0, arg1, options[:github_site])
if !options[:user] || !options[:project] return if options[:user] && options[:project]
if ENV["RUBYLIB"] =~ /ruby-debug-ide/
options[:user] = "skywinder" if ENV["RUBYLIB"] =~ /ruby-debug-ide/
options[:project] = "changelog_test" options[:user] = "skywinder"
else options[:project] = "changelog_test"
remote = `git config --get remote.#{options[:git_remote]}.url` else
options[:user], options[:project] = user_project_from_remote(remote) remote = `git config --get remote.#{options[:git_remote]}.url`
end options[:user], options[:project] = user_project_from_remote(remote)
end end
end end

View File

@ -43,11 +43,9 @@ module GitHubChangelogGenerator
task @name do task @name do
# mimick parse_options # mimick parse_options
options = Parser.get_default_options options = Parser.default_options
if options[:user].nil? || options[:project].nil? Parser.user_and_project_from_git(options)
Parser.detect_user_and_project(options)
end
OPTIONS.each do |o| OPTIONS.each do |o|
v = instance_variable_get("@#{o}") v = instance_variable_get("@#{o}")

View File

@ -24,7 +24,7 @@ describe GitHubChangelogGenerator::ParserFile do
end end
context "when override default values" do context "when override default values" do
let(:default_options) { GitHubChangelogGenerator::Parser.get_default_options } let(:default_options) { GitHubChangelogGenerator::Parser.default_options }
let(:options) { { params_file: "spec/files/github_changelog_params_override" }.merge(default_options) } let(:options) { { params_file: "spec/files/github_changelog_params_override" }.merge(default_options) }
let(:options_before_change) { options.dup } let(:options_before_change) { options.dup }
let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) } let(:parse) { GitHubChangelogGenerator::ParserFile.new(options) }