Class: Workflower::Flow
- Inherits:
-
Object
- Object
- Workflower::Flow
- Defined in:
- lib/workflower/flow.rb
Instance Attribute Summary collapse
-
#after_transit ⇒ Object
Returns the value of attribute after_transit.
-
#before_transit ⇒ Object
Returns the value of attribute before_transit.
-
#boolean_action_name ⇒ Object
Returns the value of attribute boolean_action_name.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#condition_type ⇒ Object
Returns the value of attribute condition_type.
-
#deviation_id ⇒ Object
Returns the value of attribute deviation_id.
-
#downgrade_sequence ⇒ Object
Returns the value of attribute downgrade_sequence.
-
#event ⇒ Object
Returns the value of attribute event.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
-
#state ⇒ Object
Returns the value of attribute state.
-
#transition_into ⇒ Object
Returns the value of attribute transition_into.
-
#trigger_action_name ⇒ Object
Returns the value of attribute trigger_action_name.
-
#workflow_id ⇒ Object
Returns the value of attribute workflow_id.
Instance Method Summary collapse
- #after_transition_proc_name ⇒ Object
- #before_transition_proc_name ⇒ Object
- #call_after_transition(calling_model) ⇒ Object
- #call_before_transition(calling_model) ⇒ Object
- #condition_is_met?(calling_model) ⇒ Boolean
- #condition_proc_name ⇒ Object
-
#initialize(options) ⇒ Flow
constructor
rubocop:disable Metrics/AbcSize.
- #updateable_attributes(calling_model) ⇒ Object
Constructor Details
#initialize(options) ⇒ Flow
rubocop:disable Metrics/AbcSize
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/workflower/flow.rb', line 7 def initialize() @state = [:state] @transition_into = [:transition_into] @event = [:event] @condition = [:condition] if [:condition] @condition_type = [:condition_type] if [:condition_type] @before_transition = [:before_transition] if [:before_transition] @after_transition = [:after_transition] if [:after_transition] @sequence = [:sequence] @downgrade_sequence = [:downgrade_sequence] || -1 @workflow_id = [:workflow_id] @metadata = [:metadata] @deviation_id = [:deviation_id] || @workflow_id @trigger_action_name = "#{event}!" @boolean_action_name = "can_#{event}?" end |
Instance Attribute Details
#after_transit ⇒ Object
Returns the value of attribute after_transit.
3 4 5 |
# File 'lib/workflower/flow.rb', line 3 def after_transit @after_transit end |
#before_transit ⇒ Object
Returns the value of attribute before_transit.
3 4 5 |
# File 'lib/workflower/flow.rb', line 3 def before_transit @before_transit end |
#boolean_action_name ⇒ Object
Returns the value of attribute boolean_action_name.
3 4 5 |
# File 'lib/workflower/flow.rb', line 3 def boolean_action_name @boolean_action_name end |
#condition ⇒ Object
Returns the value of attribute condition.
3 4 5 |
# File 'lib/workflower/flow.rb', line 3 def condition @condition end |
#condition_type ⇒ Object
Returns the value of attribute condition_type.
3 4 5 |
# File 'lib/workflower/flow.rb', line 3 def condition_type @condition_type end |
#deviation_id ⇒ Object
Returns the value of attribute deviation_id.
3 4 5 |
# File 'lib/workflower/flow.rb', line 3 def deviation_id @deviation_id end |
#downgrade_sequence ⇒ Object
Returns the value of attribute downgrade_sequence.
3 4 5 |
# File 'lib/workflower/flow.rb', line 3 def downgrade_sequence @downgrade_sequence end |
#event ⇒ Object
Returns the value of attribute event.
3 4 5 |
# File 'lib/workflower/flow.rb', line 3 def event @event end |
#metadata ⇒ Object
Returns the value of attribute metadata.
3 4 5 |
# File 'lib/workflower/flow.rb', line 3 def @metadata end |
#sequence ⇒ Object
Returns the value of attribute sequence.
3 4 5 |
# File 'lib/workflower/flow.rb', line 3 def sequence @sequence end |
#state ⇒ Object
Returns the value of attribute state.
3 4 5 |
# File 'lib/workflower/flow.rb', line 3 def state @state end |
#transition_into ⇒ Object
Returns the value of attribute transition_into.
3 4 5 |
# File 'lib/workflower/flow.rb', line 3 def transition_into @transition_into end |
#trigger_action_name ⇒ Object
Returns the value of attribute trigger_action_name.
3 4 5 |
# File 'lib/workflower/flow.rb', line 3 def trigger_action_name @trigger_action_name end |
#workflow_id ⇒ Object
Returns the value of attribute workflow_id.
3 4 5 |
# File 'lib/workflower/flow.rb', line 3 def workflow_id @workflow_id end |
Instance Method Details
#after_transition_proc_name ⇒ Object
32 33 34 |
# File 'lib/workflower/flow.rb', line 32 def after_transition_proc_name @after_transition.blank? ? "after_workflow_#{event}".to_sym : @after_transition.to_sym end |
#before_transition_proc_name ⇒ Object
24 25 26 |
# File 'lib/workflower/flow.rb', line 24 def before_transition_proc_name @before_transition.blank? ? "before_workflow_#{event}".to_sym : @before_transition.to_sym end |
#call_after_transition(calling_model) ⇒ Object
36 37 38 |
# File 'lib/workflower/flow.rb', line 36 def call_after_transition(calling_model) calling_model.send(after_transition_proc_name) if calling_model.respond_to? after_transition_proc_name end |
#call_before_transition(calling_model) ⇒ Object
28 29 30 |
# File 'lib/workflower/flow.rb', line 28 def call_before_transition(calling_model) calling_model.send(before_transition_proc_name) if calling_model.respond_to? before_transition_proc_name end |
#condition_is_met?(calling_model) ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/workflower/flow.rb', line 44 def condition_is_met?(calling_model) if @condition_type == "expression" evaluation_phrase = @condition.split(" ").map do |item| if ["||", "&&", "(", ")", "=="].include?(item) item else "calling_model.#{item}" end end return eval(evaluation_phrase.join(" ")) end if !condition_proc_name.blank? && calling_model.respond_to?(condition_proc_name) return calling_model.send(condition_proc_name) end true end |
#condition_proc_name ⇒ Object
40 41 42 |
# File 'lib/workflower/flow.rb', line 40 def condition_proc_name @condition || nil end |
#updateable_attributes(calling_model) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/workflower/flow.rb', line 65 def updateable_attributes(calling_model) attributes = { calling_model.workflower_state_column_name => @transition_into } attributes[:sequence] = @downgrade_sequence.negative? ? @sequence : @downgrade_sequence attributes end |