Class: Querly::Config
- Inherits:
-
Object
- Object
- Querly::Config
- Defined in:
- lib/querly/config.rb
Instance Attribute Summary collapse
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#preprocessors ⇒ Object
readonly
Returns the value of attribute preprocessors.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#taggings ⇒ Object
readonly
Returns the value of attribute taggings.
Instance Method Summary collapse
- #add_file(path) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load_preprocessors(preprocessors) ⇒ Object
- #load_rules(yaml) ⇒ Object
- #load_taggings(yaml) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
8 9 10 11 12 13 |
# File 'lib/querly/config.rb', line 8 def initialize() @rules = [] @paths = [] @taggings = [] @preprocessors = {} end |
Instance Attribute Details
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
4 5 6 |
# File 'lib/querly/config.rb', line 4 def paths @paths end |
#preprocessors ⇒ Object (readonly)
Returns the value of attribute preprocessors.
6 7 8 |
# File 'lib/querly/config.rb', line 6 def preprocessors @preprocessors end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
3 4 5 |
# File 'lib/querly/config.rb', line 3 def rules @rules end |
#taggings ⇒ Object (readonly)
Returns the value of attribute taggings.
5 6 7 |
# File 'lib/querly/config.rb', line 5 def taggings @taggings end |
Instance Method Details
#add_file(path) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/querly/config.rb', line 15 def add_file(path) paths << path content = YAML.load(path.read) load_rules(content) load_taggings(content) load_preprocessors(content["preprocessor"] || {}) end |
#load_preprocessors(preprocessors) ⇒ Object
50 51 52 53 54 |
# File 'lib/querly/config.rb', line 50 def load_preprocessors(preprocessors) @preprocessors = preprocessors.each.with_object({}) do |(key, value), hash| hash[key] = Preprocessor.new(ext: key, command: value) end end |
#load_rules(yaml) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/querly/config.rb', line 24 def load_rules(yaml) yaml["rules"].each do |hash| id = hash["id"] patterns = Array(hash["pattern"]).map {|src| Pattern::Parser.parse(src) } = Array(hash["message"]) justifications = Array(hash["justification"]) rule = Rule.new(id: id) rule.patterns.concat patterns rule..concat rule.justifications.concat justifications Array(hash["tags"]).each {|tag| rule. << tag } rule.before_examples.concat Array(hash["before"]) rule.after_examples.concat Array(hash["after"]) rules << rule end end |
#load_taggings(yaml) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/querly/config.rb', line 43 def load_taggings(yaml) @taggings = Array(yaml["tagging"]).map {|hash| Tagging.new(path_pattern: hash["path"], tags_set: Array(hash["tags"]).map {|string| Set.new(string.split) }) }.sort_by {|tagging| -tagging.path_pattern.size } end |