Module: Iord::Hooks

Extended by:
ActiveSupport::Concern
Defined in:
lib/iord/hooks.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.register_hook(resource_name, action = :all) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/iord/hooks.rb', line 35

def register_hook(resource_name, action = :all)
  hook = Proc.new
  if action.to_sym == :all
    Iord::HookSet.register_hook(resource_name, :create, hook)
    Iord::HookSet.register_hook(resource_name, :update, hook)
    Iord::HookSet.register_hook(resource_name, :destroy, hook)
  else
    Iord::HookSet.register_hook(resource_name, action, hook)
  end
end

Instance Method Details

#create_resource_with_hooksObject



13
14
15
16
17
# File 'lib/iord/hooks.rb', line 13

def create_resource_with_hooks
  result = create_resource_without_hooks
  execute_hook(resource_name_u, :create)
  result
end

#destroy_resource_with_hooksObject



25
26
27
28
29
# File 'lib/iord/hooks.rb', line 25

def destroy_resource_with_hooks
  result = destroy_resource_without_hooks
  execute_hook(resource_name_u, :destroy)
  result
end

#execute_hook(resource_name, action) ⇒ Object



31
32
33
# File 'lib/iord/hooks.rb', line 31

def execute_hook(resource_name, action)
  Iord::HookSet.execute_hook(resource_name, action, @resource)
end

#update_resource_with_hooksObject



19
20
21
22
23
# File 'lib/iord/hooks.rb', line 19

def update_resource_with_hooks
  result = update_resource_without_hooks
  execute_hook(resource_name_u, :update)
  result
end