Class: Gitra::Parser
- Inherits:
-
Object
- Object
- Gitra::Parser
- Defined in:
- lib/gitra/parser.rb
Instance Method Summary collapse
-
#initialize(rule_file) ⇒ Parser
constructor
A new instance of Parser.
- #result ⇒ Object
- #use(commit) ⇒ Object
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
#result ⇒ Object
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. next unless match id = match[1].to_i (@uses[name][id] ||= []) << commit end end end |