Class: Workflow::Callbacks::TransitionCallbackWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/workflow/callbacks/transition_callback_wrapper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(callback_type, raw_proc) ⇒ TransitionCallbackWrapper

Returns a new instance of TransitionCallbackWrapper.



5
6
7
8
# File 'lib/workflow/callbacks/transition_callback_wrapper.rb', line 5

def initialize(callback_type, raw_proc)
  @callback_type = callback_type
  @raw_proc      = raw_proc
end

Instance Attribute Details

#callback_typeObject (readonly)

Returns the value of attribute callback_type.



4
5
6
# File 'lib/workflow/callbacks/transition_callback_wrapper.rb', line 4

def callback_type
  @callback_type
end

#raw_procObject (readonly)

Returns the value of attribute raw_proc.



4
5
6
# File 'lib/workflow/callbacks/transition_callback_wrapper.rb', line 4

def raw_proc
  @raw_proc
end

Class Method Details

.build_wrapper(callback_type, raw_proc) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/workflow/callbacks/transition_callback_wrapper.rb', line 10

def self.build_wrapper(callback_type, raw_proc)
  if raw_proc.kind_of? ::Proc
    new(callback_type, raw_proc).wrapper
  else
    raw_proc
  end
end

Instance Method Details

#wrapperObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/workflow/callbacks/transition_callback_wrapper.rb', line 18

def wrapper
  arguments = [
    name_arguments_string,
    rest_param_string,
    kw_arguments_string,
    keyrest_string,
    procedure_string].compact.join(', ')

  raw_proc = self.raw_proc
  str = "    Proc.new do |target\#{', callbacks' if around_callback?}|\n      attributes = transition_context.attributes.dup\n      target.instance_exec(\#{arguments})\n    end\n  EOF\n  eval(str)\nend\n"