Class: TaliaCore::Workflow::SupportingClasses::Event

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



84
85
86
# File 'lib/talia_core/workflow.rb', line 84

def name
  @name
end

#optsObject (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.authorized_as?(@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