Class: StateChange Abstract
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- StateChange
- Defined in:
- app/models/state_change.rb
Overview
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
Instance Attribute Summary collapse
- #created_at ⇒ DateTime
- #from ⇒ String
- #machine_type ⇒ String
- #notes ⇒ String
- #state_event ⇒ String
- #to ⇒ String
- #type ⇒ String
- #updated_at ⇒ DateTime
Belongs to collapse
-
#machine ⇒ Machine
The associated state machine (request, reimbursement...).
-
#user ⇒ User
The user creating the change.
Class Method Summary collapse
-
.newest_first ⇒ ActiveRecord::Relation<StateChange>
A relation of StateChanges that are newest first.
-
.oldest_first ⇒ ActiveRecord::Relation<StateChange>
A relation of StateChanges that are oldest first.
Instance Method Summary collapse
-
#human_action_name ⇒ String
Short and human readable explanation of the change.
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes
Instance Attribute Details
#created_at ⇒ DateTime
216 |
# File 'db/schema.rb', line 216 t.datetime "created_at" |
#from ⇒ String
Validations:
25 |
# File 'app/models/state_change.rb', line 25 validates :from, :to, :user, :machine, presence: true |
#machine_type ⇒ String
210 |
# File 'db/schema.rb', line 210 t.string "machine_type", null: false |
#notes ⇒ String
215 |
# File 'db/schema.rb', line 215 t.string "notes" |
#state_event ⇒ String
211 |
# File 'db/schema.rb', line 211 t.string "state_event" |
#to ⇒ String
Validations:
25 |
# File 'app/models/state_change.rb', line 25 validates :from, :to, :user, :machine, presence: true |
#type ⇒ String
218 |
# File 'db/schema.rb', line 218 t.string "type" |
#updated_at ⇒ 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
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
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.
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...)
Validations:
21 |
# File 'app/models/state_change.rb', line 21 belongs_to :machine, polymorphic: true, inverse_of: :state_changes |