Module: Submission::StateMachine::InstanceMethods
- Defined in:
- app/models/submission/state_machine.rb
Instance Method Summary collapse
- #broadcast_events ⇒ Object
- #callbacks ⇒ Object
- #cancellable? ⇒ Boolean
- #complete_building ⇒ Object
- #destroyable? ⇒ Boolean
- #editable? ⇒ Boolean
- #process_callbacks! ⇒ Object
- #process_submission! ⇒ Object
- #register_callback(key = nil, &block) ⇒ Object
- #requests_cancellable? ⇒ Boolean
- #unprocessed? ⇒ Boolean
- #valid_for_leaving_building_state ⇒ Object
Instance Method Details
#broadcast_events ⇒ Object
79 80 81 |
# File 'app/models/submission/state_machine.rb', line 79 def broadcast_events orders.each(&:generate_broadcast_event) end |
#callbacks ⇒ Object
49 50 51 |
# File 'app/models/submission/state_machine.rb', line 49 def callbacks @callbacks ||= {} end |
#cancellable? ⇒ Boolean
62 63 64 |
# File 'app/models/submission/state_machine.rb', line 62 def cancellable? (pending? || ready?) && requests_cancellable? end |
#complete_building ⇒ Object
37 38 39 |
# File 'app/models/submission/state_machine.rb', line 37 def complete_building orders.reload.each(&:complete_building) end |
#destroyable? ⇒ Boolean
66 67 68 |
# File 'app/models/submission/state_machine.rb', line 66 def destroyable? building? end |
#editable? ⇒ Boolean
70 71 72 |
# File 'app/models/submission/state_machine.rb', line 70 def editable? building? || failed? end |
#process_callbacks! ⇒ Object
45 46 47 |
# File 'app/models/submission/state_machine.rb', line 45 def process_callbacks! callbacks.each_value(&:call) end |
#process_submission! ⇒ Object
41 42 43 |
# File 'app/models/submission/state_machine.rb', line 41 def process_submission! # Does nothing by default! end |
#register_callback(key = nil, &block) ⇒ Object
53 54 55 56 |
# File 'app/models/submission/state_machine.rb', line 53 def register_callback(key = nil, &block) key ||= "k#{@callbacks.size}" callbacks[key] = block end |
#requests_cancellable? ⇒ Boolean
74 75 76 77 |
# File 'app/models/submission/state_machine.rb', line 74 def requests_cancellable? # Default behaviour, overidden in the model itself false end |
#unprocessed? ⇒ Boolean
58 59 60 |
# File 'app/models/submission/state_machine.rb', line 58 def unprocessed? UnprocessedStates.include?(state) end |
#valid_for_leaving_building_state ⇒ Object
33 34 35 |
# File 'app/models/submission/state_machine.rb', line 33 def valid_for_leaving_building_state raise ActiveRecord::RecordInvalid, self unless valid? end |