Module: AASM::ClassMethods
- Defined in:
- lib/aasm.rb
Instance Method Summary collapse
- #aasm_event(name, options = {}, &block) ⇒ Object
- #aasm_events ⇒ Object
- #aasm_initial_state(set_state = nil) ⇒ Object
- #aasm_initial_state=(state) ⇒ Object
- #aasm_state(name, options = {}) ⇒ Object
- #aasm_state_machine ⇒ Object
- #aasm_states ⇒ Object
- #aasm_states_for_select ⇒ Object
Instance Method Details
#aasm_event(name, options = {}, &block) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/aasm.rb', line 49 def aasm_event(name, = {}, &block) sm = aasm_state_machine unless sm.events.has_key?(name) sm.events[name] = AASM::SupportingClasses::Event.new(name, , &block) end define_method("#{name.to_s}!") do |*args| aasm_fire_event(name, true, *args) end define_method("#{name.to_s}") do |*args| aasm_fire_event(name, false, *args) end end |
#aasm_events ⇒ Object
69 70 71 |
# File 'lib/aasm.rb', line 69 def aasm_events aasm_state_machine.events end |
#aasm_initial_state(set_state = nil) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/aasm.rb', line 27 def aasm_initial_state(set_state=nil) if set_state aasm_state_machine.initial_state = set_state else aasm_state_machine.initial_state end end |
#aasm_initial_state=(state) ⇒ Object
35 36 37 |
# File 'lib/aasm.rb', line 35 def aasm_initial_state=(state) aasm_state_machine.initial_state = state end |
#aasm_state(name, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/aasm.rb', line 39 def aasm_state(name, ={}) sm = aasm_state_machine sm.create_state(name, ) sm.initial_state = name unless sm.initial_state define_method("#{name.to_s}?") do aasm_current_state == name end end |
#aasm_state_machine ⇒ Object
77 78 79 |
# File 'lib/aasm.rb', line 77 def aasm_state_machine AASM::StateMachine[self] end |
#aasm_states ⇒ Object
65 66 67 |
# File 'lib/aasm.rb', line 65 def aasm_states aasm_state_machine.states end |
#aasm_states_for_select ⇒ Object
73 74 75 |
# File 'lib/aasm.rb', line 73 def aasm_states_for_select aasm_state_machine.states.map { |state| state.for_select } end |