Class: TaliaCore::Workflow::SupportingClasses::Event
- Defined in:
- lib/talia_core/workflow.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#transitions(trans_opts) ⇒ Object
readonly
Returns the value of attribute transitions.
Instance Method Summary collapse
- #fire(record, user, args = nil) ⇒ Object
-
#initialize(name, opts, transition_table, &block) ⇒ Event
constructor
A new instance of Event.
- #next_states(record) ⇒ Object
Constructor Details
#initialize(name, opts, transition_table, &block) ⇒ Event
Returns a new instance of Event.
88 89 90 91 92 93 94 95 96 |
# File 'lib/talia_core/workflow.rb', line 88 def initialize(name, opts, transition_table, &block) @name = name.to_sym @transitions = transition_table[@name] = [] instance_eval(&block) if block @opts = opts @opts.freeze @transitions.freeze freeze end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
84 85 86 |
# File 'lib/talia_core/workflow.rb', line 84 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
86 87 88 |
# File 'lib/talia_core/workflow.rb', line 86 def opts @opts end |
#transitions(trans_opts) ⇒ Object (readonly)
Returns the value of attribute transitions.
85 86 87 |
# File 'lib/talia_core/workflow.rb', line 85 def transitions @transitions end |
Instance Method Details
#fire(record, user, args = nil) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/talia_core/workflow.rb', line 102 def fire(record, user, args = nil) # check user role unless @opts[:require_role].nil? raise NoAuthorizedException unless user.(@opts[:require_role]) end # perform transition next_states(record).each do |transition| break true if transition.perform(record, args) end end |
#next_states(record) ⇒ Object
98 99 100 |
# File 'lib/talia_core/workflow.rb', line 98 def next_states(record) @transitions.select { |t| t.from == record.current_state } end |