Class: VCLog::Heuristics::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/vclog/heuristics/rule.rb

Overview

Defines a categorization rule for commits.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern = nil) {|An| ... } ⇒ Rule

Initialize a new log rule.

Parameters:

  • pattern (Regexp) (defaults to: nil)

    An optional regular expression to match agains the commit message. If the pattern does not match the commit message than the rule does not apply.

Yield Parameters:

  • An (Change)

    encapsulation of the commit.

Yield Returns:

  • (Boolean)

    If the return value is nil or false, the rule does not apply. If a rule does not apply then be sure not to alter the commit!



23
24
25
26
# File 'lib/vclog/heuristics/rule.rb', line 23

def initialize(pattern=nil, &block)
  @pattern = pattern
  @block   = block        
end

Instance Attribute Details

#patternObject (readonly)

Message pattern to match for the rule to apply.



29
30
31
# File 'lib/vclog/heuristics/rule.rb', line 29

def pattern
  @pattern
end

Instance Method Details

#call(commit) ⇒ Object

Process the rule.

Since:

  • 1.9.0 If using a message pattern and the block takes two arguments then the first will be the commit object, not the message as was the case in older versions.



38
39
40
41
42
43
44
# File 'lib/vclog/heuristics/rule.rb', line 38

def call(commit)
  if pattern
    call_pattern(commit)
  else
    call_commit(commit)
  end
end

#call_commit(commit) ⇒ Object (private)



65
66
67
# File 'lib/vclog/heuristics/rule.rb', line 65

def call_commit(commit)
  @block.call(commit)
end

#call_pattern(commit) ⇒ Object (private)



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/vclog/heuristics/rule.rb', line 49

def call_pattern(commit)
  if matchdata = @pattern.match(commit.message)
    #case @block.arity
    #when 0
    #  @block.call
    #when 1
    #  @block.call(matchdata)
    #else
      @block.call(commit, matchdata)
    #end
  else
    nil
  end
end