Class: Gitra::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/gitra/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(rule_file) ⇒ Parser

Returns a new instance of Parser.



5
6
7
8
9
10
11
12
13
14
# File 'lib/gitra/parser.rb', line 5

def initialize(rule_file)
  rule_file ||= '.gitra-rules.yml'
  @rules = YAML.load_file(rule_file)

  @uses = {}
  @rules.each_pair do |name, patterns|
    @uses[name] = {}
    patterns.map! { |p| Regexp.new p }
  end
end

Instance Method Details

#resultObject



28
29
30
# File 'lib/gitra/parser.rb', line 28

def result
  @uses
end

#use(commit) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gitra/parser.rb', line 16

def use(commit)
  @rules.each_pair do |name, patterns|
    patterns.each do |pattern|
      match = pattern.match commit.message
      next unless match

      id = match[1].to_i
      (@uses[name][id] ||= []) << commit
    end
  end
end