Module: AASM::ClassMethods
- Defined in:
- lib/alexrevin-aasm_numerical/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
- #human_event_name(event) ⇒ Object
- #inherited(klass) ⇒ Object
Instance Method Details
#aasm_event(name, options = {}, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/alexrevin-aasm_numerical/aasm.rb', line 46 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 # an addition over standard aasm so that, before firing an event, you can ask # may_event? and get back a boolean that tells you whether the guard method # on the transition will let this happen. define_method("may_#{name.to_s}?") do |*args| aasm_test_event(name, *args) 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
73 74 75 |
# File 'lib/alexrevin-aasm_numerical/aasm.rb', line 73 def aasm_events AASM::StateMachine[self].events end |
#aasm_initial_state(set_state = nil) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/alexrevin-aasm_numerical/aasm.rb', line 24 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
32 33 34 |
# File 'lib/alexrevin-aasm_numerical/aasm.rb', line 32 def aasm_initial_state=(state) AASM::StateMachine[self].initial_state = state end |
#aasm_state(name, options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/alexrevin-aasm_numerical/aasm.rb', line 36 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
69 70 71 |
# File 'lib/alexrevin-aasm_numerical/aasm.rb', line 69 def aasm_states AASM::StateMachine[self].states end |
#aasm_states_for_select ⇒ Object
77 78 79 |
# File 'lib/alexrevin-aasm_numerical/aasm.rb', line 77 def aasm_states_for_select AASM::StateMachine[self].states.map { |state| state.for_select } end |
#human_event_name(event) ⇒ Object
81 82 83 |
# File 'lib/alexrevin-aasm_numerical/aasm.rb', line 81 def human_event_name(event) AASM::Localizer.new.human_event_name(self, event) end |
#inherited(klass) ⇒ Object
19 20 21 22 |
# File 'lib/alexrevin-aasm_numerical/aasm.rb', line 19 def inherited(klass) AASM::StateMachine[klass] = AASM::StateMachine[self].clone super end |