Module: Workflower::ActsAsWorkflower::InstanceMethods

Defined in:
lib/workflower/acts_as_workflower.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#allowed_eventsObject

mattr_accessor :workflower_base



10
11
12
# File 'lib/workflower/acts_as_workflower.rb', line 10

def allowed_events
  @allowed_events
end

#allowed_transitionsObject

mattr_accessor :workflower_base



10
11
12
# File 'lib/workflower/acts_as_workflower.rb', line 10

def allowed_transitions
  @allowed_transitions
end

#possible_eventsObject

mattr_accessor :workflower_base



10
11
12
# File 'lib/workflower/acts_as_workflower.rb', line 10

def possible_events
  @possible_events
end

#workflow_transition_event_nameObject

mattr_accessor :workflower_base



10
11
12
# File 'lib/workflower/acts_as_workflower.rb', line 10

def workflow_transition_event_name
  @workflow_transition_event_name
end

#workflow_transition_flowObject

mattr_accessor :workflower_base



10
11
12
# File 'lib/workflower/acts_as_workflower.rb', line 10

def workflow_transition_flow
  @workflow_transition_flow
end

Instance Method Details

#initializeObject



61
62
63
64
65
66
# File 'lib/workflower/acts_as_workflower.rb', line 61

def initialize(*)
  super
  write_attribute :workflow_id, default_workflow_id if workflow_id.blank?

  workflower_initializer
end

#set_initial_stateObject



12
13
14
# File 'lib/workflower/acts_as_workflower.rb', line 12

def set_initial_state
  write_attribute self.class.workflower_state_column_name, workflower_initial_state
end

#source_workflowObject



24
25
26
27
# File 'lib/workflower/acts_as_workflower.rb', line 24

def source_workflow
  @source_workflow_instance ||= source.new(self)
  @source_workflow_instance.get_workflows_for_workflow_id(workflow_id)
end

#workflower_baseObject



20
21
22
# File 'lib/workflower/acts_as_workflower.rb', line 20

def workflower_base
  @workflower_base
end

#workflower_initial_stateObject



16
17
18
# File 'lib/workflower/acts_as_workflower.rb', line 16

def workflower_initial_state
  workflower_base.set_initial_state
end

#workflower_initializerObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/workflower/acts_as_workflower.rb', line 29

def workflower_initializer
  @source_workflow_instance ||= source.new(self)

  @workflower_base ||= Workflower::Manager.new(self, @source_workflow_instance)

  @workflower_base.allowed_transitions.each do |flow|
    define_singleton_method flow.trigger_action_name.to_s do
      @workflow_transition_event_name = flow.event
      @workflow_transition_flow = flow
      @workflower_base.process_transition!(flow)
    end

    define_singleton_method flow.boolean_action_name.to_s do
      @workflower_base.transition_possible?(flow)
    end
  end

  @possible_events     ||= @workflower_base.events
  @allowed_events      ||= @workflower_base.allowed_events
  @allowed_transitions ||= @workflower_base.allowed_transitions
end

#workflower_uninitializer(reset_source_workflow_instance: false) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/workflower/acts_as_workflower.rb', line 51

def workflower_uninitializer(reset_source_workflow_instance: false)
  @workflower_base.uninitialize
  @workflower_base = nil

  @source_workflow_instance = nil if reset_source_workflow_instance
  @possible_events     = nil
  @allowed_events      = nil
  @allowed_transitions = nil
end