Class: Onceler::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/onceler/configuration.rb

Instance Method Summary collapse

Instance Method Details

#after(scope, &block) ⇒ Object



17
18
19
# File 'lib/onceler/configuration.rb', line 17

def after(scope, &block)
  hooks[:after][scope] << block
end

#before(scope, &block) ⇒ Object



13
14
15
# File 'lib/onceler/configuration.rb', line 13

def before(scope, &block)
  hooks[:before][scope] << block
end

#hooksObject



21
22
23
24
25
26
# File 'lib/onceler/configuration.rb', line 21

def hooks
  @hooks ||= {
    before: { record: [], reset: [] },
    after: { record: [], reset: [] }
  }
end

#run_hooks(timing, scope, context) ⇒ Object



28
29
30
31
32
# File 'lib/onceler/configuration.rb', line 28

def run_hooks(timing, scope, context)
  hooks[timing][scope].each do |hook|
    context ? context.instance_eval(&hook) : hook.call
  end
end