Class: Subtrigger::Trigger
- Inherits:
-
Object
- Object
- Subtrigger::Trigger
- Defined in:
- lib/subtrigger/trigger.rb
Overview
Call blocks on a matching pattern
This is a framework for combining pairs of matchers and callbacks to run on a commit message. You can define a trigger which this class will apply to a log message.
Example usage
Trigger.define(/foo/) do |matches, repo|
puts "Someone used 'foo' in his commit message"
end
When the above trigger is defined and somebody makes a commit message containing foo the block will be called. matches contains any captured regular expression groups, repo is a Repository object for the current repository revision.
You can define as many triggers as you like. When no triggers are found an exception will be raised. When no trigger applies, it will quit silently.
Class Method Summary collapse
-
.define(pattern, &block) ⇒ Object
Create a new Trigger object and add it to the stack.
- .reset ⇒ Object
-
.run(repo) ⇒ Object
Run all available triggers on the given Repository object.
- .triggers ⇒ Object
Instance Method Summary collapse
-
#initialize(pattern, repo, &block) ⇒ Trigger
constructor
A new instance of Trigger.
Constructor Details
#initialize(pattern, repo, &block) ⇒ Trigger
Returns a new instance of Trigger.
48 49 50 51 |
# File 'lib/subtrigger/trigger.rb', line 48 def initialize(pattern, repo, &block) @pattern, @repo, @callback = pattern, repo, block parse end |
Class Method Details
.define(pattern, &block) ⇒ Object
Create a new Trigger object and add it to the stack.
43 44 45 |
# File 'lib/subtrigger/trigger.rb', line 43 def define(pattern, &block) (@triggers ||= {})[pattern] = block; end |
.reset ⇒ Object
38 39 40 |
# File 'lib/subtrigger/trigger.rb', line 38 def reset @triggers = {} end |
.run(repo) ⇒ Object
Run all available triggers on the given Repository object.
27 28 29 30 31 32 |
# File 'lib/subtrigger/trigger.rb', line 27 def run(repo) raise 'No suitable triggers found.' if @triggers.nil? @triggers.each_pair do |pattern, block| new(pattern, repo, &block) end end |
.triggers ⇒ Object
34 35 36 |
# File 'lib/subtrigger/trigger.rb', line 34 def triggers @triggers ||= {} end |