Module: Submission::StateMachine::InstanceMethods

Defined in:
app/models/submission/state_machine.rb

Instance Method Summary collapse

Instance Method Details

#broadcast_eventsObject



79
80
81
# File 'app/models/submission/state_machine.rb', line 79

def broadcast_events
  orders.each(&:generate_broadcast_event)
end

#callbacksObject



49
50
51
# File 'app/models/submission/state_machine.rb', line 49

def callbacks
  @callbacks ||= {}
end

#cancellable?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'app/models/submission/state_machine.rb', line 62

def cancellable?
  (pending? || ready?) && requests_cancellable?
end

#complete_buildingObject



37
38
39
# File 'app/models/submission/state_machine.rb', line 37

def complete_building
  orders.reload.each(&:complete_building)
end

#destroyable?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'app/models/submission/state_machine.rb', line 66

def destroyable?
  building?
end

#editable?Boolean

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


58
59
60
# File 'app/models/submission/state_machine.rb', line 58

def unprocessed?
  UnprocessedStates.include?(state)
end

#valid_for_leaving_building_stateObject



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