Class: Querly::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/querly/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

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

#pathsObject (readonly)

Returns the value of attribute paths.



4
5
6
# File 'lib/querly/config.rb', line 4

def paths
  @paths
end

#preprocessorsObject (readonly)

Returns the value of attribute preprocessors.



6
7
8
# File 'lib/querly/config.rb', line 6

def preprocessors
  @preprocessors
end

#rulesObject (readonly)

Returns the value of attribute rules.



3
4
5
# File 'lib/querly/config.rb', line 3

def rules
  @rules
end

#taggingsObject (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) }
    messages = Array(hash["message"])
    justifications = Array(hash["justification"])

    rule = Rule.new(id: id)
    rule.patterns.concat patterns
    rule.messages.concat messages
    rule.justifications.concat justifications
    Array(hash["tags"]).each {|tag| rule.tags << 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