Class: GitHooker::Hook
- Inherits:
-
Object
- Object
- GitHooker::Hook
- Includes:
- Singleton
- Defined in:
- lib/githooker/hook.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Hook
constructor
A new instance of Hook.
- #perform(title, options = {}, &block) ⇒ Object
- #register(options = {}, &block) ⇒ Object
- #run ⇒ Object
-
#section(name) ⇒ Object
DSL methods.
- #sections ⇒ Object
- #stop_on_error(value) ⇒ Object
Constructor Details
#initialize ⇒ Hook
Returns a new instance of Hook.
13 14 15 16 |
# File 'lib/githooker/hook.rb', line 13 def initialize @sections = [] @section = nil end |
Class Method Details
.method_missing(*args, &block) ⇒ Object
8 9 10 11 |
# File 'lib/githooker/hook.rb', line 8 def self.method_missing(*args, &block) return super unless self.instance.respond_to? args.first self.instance.send(*args, &block) end |
Instance Method Details
#perform(title, options = {}, &block) ⇒ Object
52 53 54 55 56 |
# File 'lib/githooker/hook.rb', line 52 def perform(title, = {}, &block) raise RegistrationError, "#perform called before section defined" unless @section raise ArgumentError, "Missing required block to #perform" unless block_given? @section << Action.new(title, .delete(:phase) || @phase, &block) end |
#register(options = {}, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/githooker/hook.rb', line 18 def register( = {}, &block) raise ArgumentError, "Missing required block to #register" unless block_given? @phase = (.delete(:phase) || :any).to_s.to_sym unless GitHooker::VALID_PHASES.include? @phase raise ArgumentError, "Phase must be one of #{GitHooker::VALID_PHASES.join(', ')}" end if Repo.match_phase(@phase) instance_eval(&block) end self end |
#run ⇒ Object
32 33 34 |
# File 'lib/githooker/hook.rb', line 32 def run @sections.collect { |section| section.run }.all? end |
#section(name) ⇒ Object
DSL methods
38 39 40 41 |
# File 'lib/githooker/hook.rb', line 38 def section(name) @sections << (@section = Section.new(name)) self end |
#sections ⇒ Object
43 44 45 |
# File 'lib/githooker/hook.rb', line 43 def sections @sections end |
#stop_on_error(value) ⇒ Object
47 48 49 50 |
# File 'lib/githooker/hook.rb', line 47 def stop_on_error(value) raise RegistrationError, "#stop_on_error called before section defined" unless @section @section.stop_on_error = value end |