class I18nLinter::Config
Constants
- DEFAULT_FILE
- DOTFILE
- I18N_LINTER_HOME
Public Class Methods
new()
click to toggle source
# File lib/i18n_linter/config.rb, line 11 def initialize path = File.exist?(DOTFILE) ? DOTFILE : DEFAULT_FILE @hash = load_yaml_configuration(path) add_missing_rules(@hash['Rules']) end
Public Instance Methods
enabled_negative_rules()
click to toggle source
# File lib/i18n_linter/config.rb, line 29 def enabled_negative_rules all_rules.keys.select { |rule| negative_rule?(rule) && enabled_rule?(rule) } end
enabled_positive_rules()
click to toggle source
# File lib/i18n_linter/config.rb, line 25 def enabled_positive_rules all_rules.keys.select { |rule| positive_rule?(rule) && enabled_rule?(rule) } end
patterns_to_exclude()
click to toggle source
# File lib/i18n_linter/config.rb, line 21 def patterns_to_exclude linter_patterns['Exclude'] || [] end
patterns_to_include()
click to toggle source
# File lib/i18n_linter/config.rb, line 17 def patterns_to_include linter_patterns['Include'] || [] end
Private Instance Methods
[](key)
click to toggle source
# File lib/i18n_linter/config.rb, line 35 def [](key) @hash[key] end
add_missing_rules(loaded_rules)
click to toggle source
# File lib/i18n_linter/config.rb, line 68 def add_missing_rules(loaded_rules) missing = (Rules::POSITIVE_RULES + Rules::NEGATIVE_RULES) - loaded_rules.keys missing.each do |rule| loaded_rules.store(rule, 'Enabled' => true) end end
all_rules()
click to toggle source
# File lib/i18n_linter/config.rb, line 43 def all_rules @all_rules ||= self['Rules'] || {} end
enabled_rule?(rule)
click to toggle source
# File lib/i18n_linter/config.rb, line 47 def enabled_rule?(rule) all_rules[rule]['Enabled'] end
linter_patterns()
click to toggle source
# File lib/i18n_linter/config.rb, line 39 def linter_patterns @linter_patterns ||= self['Linter'] || {} end
load_yaml_configuration(path)
click to toggle source
# File lib/i18n_linter/config.rb, line 59 def load_yaml_configuration(path) yaml_code = File.read(path) hash = YAML.safe_load(yaml_code, [Regexp, Symbol], [], false, path) || {} raise(TypeError, "Malformed configuration in #{path}") unless hash.is_a?(Hash) hash end
negative_rule?(rule)
click to toggle source
# File lib/i18n_linter/config.rb, line 55 def negative_rule?(rule) Rules::NEGATIVE_RULES.include?(rule) end
positive_rule?(rule)
click to toggle source
# File lib/i18n_linter/config.rb, line 51 def positive_rule?(rule) Rules::POSITIVE_RULES.include?(rule) end