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



15
16
17
# File 'lib/onceler/configuration.rb', line 15

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

#before(scope, &block) ⇒ Object



11
12
13
# File 'lib/onceler/configuration.rb', line 11

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

#hooksObject



19
20
21
22
23
24
# File 'lib/onceler/configuration.rb', line 19

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

#run_hooks(timing, scope, context) ⇒ Object



26
27
28
29
30
# File 'lib/onceler/configuration.rb', line 26

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