Class: PassiveRecord::Hooks::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/passive_record/hooks.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind, *meth_syms, &blk) ⇒ Hook

Returns a new instance of Hook.



6
7
8
9
10
# File 'lib/passive_record/hooks.rb', line 6

def initialize(kind,*meth_syms,&blk)
  @kind = kind
  @methods_to_call = meth_syms
  @block_to_invoke = blk
end

Instance Attribute Details

#kindObject (readonly)

Returns the value of attribute kind.



4
5
6
# File 'lib/passive_record/hooks.rb', line 4

def kind
  @kind
end

Instance Method Details

#run(instance) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/passive_record/hooks.rb', line 12

def run(instance)
  @methods_to_call.each do |meth|
    instance.send(meth)
  end

  unless @block_to_invoke.nil?
    instance.instance_eval(&@block_to_invoke)
  end

  instance
end