Class: GitHooker::Hook

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/githooker/hook.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHook

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

Raises:



52
53
54
55
56
# File 'lib/githooker/hook.rb', line 52

def perform(title, options = {}, &block)
  raise RegistrationError, "#perform called before section defined" unless @section
  raise ArgumentError, "Missing required block to #perform" unless block_given?
  @section << Action.new(title, options.delete(:phase) || @phase, &block)
end

#register(options = {}, &block) ⇒ Object

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/githooker/hook.rb', line 18

def register(options = {}, &block)
  raise ArgumentError, "Missing required block to #register" unless block_given?

  @phase = (options.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

#runObject



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

#sectionsObject



43
44
45
# File 'lib/githooker/hook.rb', line 43

def sections
  @sections
end

#stop_on_error(value) ⇒ Object

Raises:



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