Refactor: call it option_name
- also, add a IRREGULAR_OPTIONS hash
This commit is contained in:
parent
9150cdc09e
commit
5071b596d2
|
@ -22,13 +22,13 @@ module GitHubChangelogGenerator
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_line!(line)
|
def parse_line!(line)
|
||||||
key_sym, value = extract_pair(line)
|
option_name, value = extract_pair(line)
|
||||||
@options[translate_option_name(key_sym)] = convert_value(value, key_sym)
|
@options[option_key_for(option_name)] = convert_value(value, option_name)
|
||||||
rescue
|
rescue
|
||||||
raise ParserError, "Config file #{file} is incorrect in line \"#{line.gsub(/[\n\r]+/, '')}\""
|
raise ParserError, "Config file #{file} is incorrect in line \"#{line.gsub(/[\n\r]+/, '')}\""
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a the setting as a symbol and its string value sans newlines.
|
# Returns a the option name as a symbol and its string value sans newlines.
|
||||||
#
|
#
|
||||||
# @param line [String] unparsed line from config file
|
# @param line [String] unparsed line from config file
|
||||||
# @return [Array<Symbol, String>]
|
# @return [Array<Symbol, String>]
|
||||||
|
@ -41,10 +41,10 @@ module GitHubChangelogGenerator
|
||||||
:enhancement_labels, :between_tags, :exclude_tags]
|
:enhancement_labels, :between_tags, :exclude_tags]
|
||||||
KNOWN_INTEGER_KEYS = [:max_issues]
|
KNOWN_INTEGER_KEYS = [:max_issues]
|
||||||
|
|
||||||
def convert_value(value, key_sym)
|
def convert_value(value, option_name)
|
||||||
if KNOWN_ARRAY_KEYS.include?(key_sym)
|
if KNOWN_ARRAY_KEYS.include?(option_name)
|
||||||
value.split(",")
|
value.split(",")
|
||||||
elsif KNOWN_INTEGER_KEYS.include?(key_sym)
|
elsif KNOWN_INTEGER_KEYS.include?(option_name)
|
||||||
value.to_i
|
value.to_i
|
||||||
elsif value =~ /^(true|t|yes|y|1)$/i
|
elsif value =~ /^(true|t|yes|y|1)$/i
|
||||||
true
|
true
|
||||||
|
@ -55,8 +55,7 @@ module GitHubChangelogGenerator
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def translate_option_name(key_sym)
|
IRREGULAR_OPTIONS = {
|
||||||
{
|
|
||||||
bugs_label: :bug_prefix,
|
bugs_label: :bug_prefix,
|
||||||
enhancement_label: :enhancement_prefix,
|
enhancement_label: :enhancement_prefix,
|
||||||
issues_label: :issue_prefix,
|
issues_label: :issue_prefix,
|
||||||
|
@ -68,7 +67,10 @@ module GitHubChangelogGenerator
|
||||||
pull_requests: :pulls,
|
pull_requests: :pulls,
|
||||||
filter_by_milestone: :filter_issues_by_milestone,
|
filter_by_milestone: :filter_issues_by_milestone,
|
||||||
github_api: :github_endpoint
|
github_api: :github_endpoint
|
||||||
}.fetch(key_sym) { key_sym }
|
}
|
||||||
|
|
||||||
|
def option_key_for(option_name)
|
||||||
|
IRREGULAR_OPTIONS.fetch(option_name) { option_name }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user