Class: StateChange Abstract

Inherits:
ApplicationRecord show all
Defined in:
app/models/state_change.rb

Overview

This class is abstract.

Change in the state of a state machine (a request, reimbursement,

etc.). This class is not intended to be used directly, use one of the subclasses instead.

Using a subclass of StateChange is the right way of changing the state of any state machine, since it creates a log of the change, allows the user to add textual information and notifies the change to all involved users. Don't modify the state or call the state machine transition methods directly.

Direct Known Subclasses

StateAdjustment, StateTransition

Instance Attribute Summary collapse

Belongs to collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes

Instance Attribute Details

#created_at ⇒ DateTime

Returns:

  • (DateTime)


216
# File 'db/schema.rb', line 216

t.datetime "created_at"

#from ⇒ String

Returns:

  • (String)

Validations:



25
# File 'app/models/state_change.rb', line 25

validates :from, :to, :user, :machine, presence: true

#machine_type ⇒ String

Returns:

  • (String)


210
# File 'db/schema.rb', line 210

t.string "machine_type", null: false

#notes ⇒ String

Returns:

  • (String)


215
# File 'db/schema.rb', line 215

t.string "notes"

#state_event ⇒ String

Returns:

  • (String)


211
# File 'db/schema.rb', line 211

t.string "state_event"

#to ⇒ String

Returns:

  • (String)

Validations:



25
# File 'app/models/state_change.rb', line 25

validates :from, :to, :user, :machine, presence: true

#type ⇒ String

Returns:

  • (String)


218
# File 'db/schema.rb', line 218

t.string "type"

#updated_at ⇒ DateTime

Returns:

  • (DateTime)


217
# File 'db/schema.rb', line 217

t.datetime "updated_at"

Class Method Details

.newest_first ⇒ ActiveRecord::Relation<StateChange>

A relation of StateChanges that are newest first. Active Record Scope

Returns:

See Also:



30
# File 'app/models/state_change.rb', line 30

scope :newest_first, -> { order('created_at desc, id desc') }

.oldest_first ⇒ ActiveRecord::Relation<StateChange>

A relation of StateChanges that are oldest first. Active Record Scope

Returns:

See Also:



29
# File 'app/models/state_change.rb', line 29

scope :oldest_first, -> { order('created_at asc, id asc') }

Instance Method Details

#human_action_name ⇒ String

Short and human readable explanation of the change. To be implemented by subclasses.

Returns:

  • (String)

Raises:

  • (NotImplementedError)


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

def human_action_name
  raise NotImplementedError
end

#machine ⇒ Machine

The associated state machine (request, reimbursement...)

Returns:

  • (Machine)

See Also:

Validations:



21
# File 'app/models/state_change.rb', line 21

belongs_to :machine, polymorphic: true, inverse_of: :state_changes

#user ⇒ User

The user creating the change

Returns:

See Also:

Validations:



23
# File 'app/models/state_change.rb', line 23

belongs_to :user, inverse_of: :state_changes