Module: Submission::StateMachine::InstanceMethods

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

Instance Method Summary collapse

Instance Method Details

#broadcast_eventsObject


70
71
72
# File 'app/models/submission/state_machine.rb', line 70

def broadcast_events
  orders.each(&:generate_broadcast_event)
end

#callbacksObject


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

def callbacks
  @callbacks ||= {}
end

#cancellable?Boolean

Returns:

  • (Boolean)

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

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

#complete_buildingObject


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

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

#process_callbacks!Object


44
45
46
# File 'app/models/submission/state_machine.rb', line 44

def process_callbacks!
  callbacks.each_value(&:call)
end

#process_submission!Object


40
41
42
# File 'app/models/submission/state_machine.rb', line 40

def process_submission!
  # Does nothing by default!
end

#register_callback(key = nil, &block) ⇒ Object


52
53
54
55
# File 'app/models/submission/state_machine.rb', line 52

def register_callback(key = nil, &block)
  key ||= "k#{@callbacks.size}"
  callbacks[key] = block
end

#requests_cancellable?Boolean

Returns:

  • (Boolean)

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

def requests_cancellable?
  # Default behaviour, overidden in the model itself
  false
end

#unprocessed?Boolean

Returns:

  • (Boolean)

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

def unprocessed?
  UnprocessedStates.include?(state)
end

#valid_for_leaving_building_stateObject


32
33
34
# File 'app/models/submission/state_machine.rb', line 32

def valid_for_leaving_building_state
  raise ActiveRecord::RecordInvalid, self unless valid?
end