Module: AASM::ClassMethods
- Defined in:
- lib/aasm/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_states ⇒ Object
- #aasm_states_for_select ⇒ Object
- #inherited(klass) ⇒ Object
Instance Method Details
#aasm_event(name, options = {}, &block) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/aasm/aasm.rb', line 44 def aasm_event(name, = {}, &block) sm = AASM::StateMachine[self] 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
64 65 66 |
# File 'lib/aasm/aasm.rb', line 64 def aasm_events AASM::StateMachine[self].events end |
#aasm_initial_state(set_state = nil) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/aasm/aasm.rb', line 22 def aasm_initial_state(set_state=nil) if set_state AASM::StateMachine[self].initial_state = set_state else AASM::StateMachine[self].initial_state end end |
#aasm_initial_state=(state) ⇒ Object
30 31 32 |
# File 'lib/aasm/aasm.rb', line 30 def aasm_initial_state=(state) AASM::StateMachine[self].initial_state = state end |
#aasm_state(name, options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/aasm/aasm.rb', line 34 def aasm_state(name, ={}) sm = AASM::StateMachine[self] 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_states ⇒ Object
60 61 62 |
# File 'lib/aasm/aasm.rb', line 60 def aasm_states AASM::StateMachine[self].states end |
#aasm_states_for_select ⇒ Object
68 69 70 |
# File 'lib/aasm/aasm.rb', line 68 def aasm_states_for_select AASM::StateMachine[self].states.map { |state| state.for_select } end |
#inherited(klass) ⇒ Object
17 18 19 20 |
# File 'lib/aasm/aasm.rb', line 17 def inherited(klass) AASM::StateMachine[klass] = AASM::StateMachine[self].clone super end |