Class: Hyraft::Engine
- Inherits:
-
Object
- Object
- Hyraft::Engine
- Defined in:
- lib/hyraft/circuit/origin.rb
Overview
Engine is the base class for all domain entities in Hyraft applications. It provides common functionality like ID management, timestamps, persistence state tracking, and hash conversion.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#created_at ⇒ Time
readonly
The timestamp when the record was created.
-
#id ⇒ Integer?
readonly
The unique identifier of the record.
-
#updated_at ⇒ Time
readonly
The timestamp when the record was last updated.
Instance Method Summary collapse
-
#initialize(id: nil, created_at: nil, updated_at: nil) ⇒ Engine
constructor
Initialize a new Engine instance.
-
#new_record? ⇒ Boolean
Check if the record is new and not yet persisted.
-
#persisted? ⇒ Boolean
Check if the record has been persisted to the database.
-
#to_h ⇒ Hash
Convert the Engine instance to a hash representation.
-
#touch ⇒ self
Update the updated_at timestamp to the current time.
Constructor Details
#initialize(id: nil, created_at: nil, updated_at: nil) ⇒ Engine
Initialize a new Engine instance
53 54 55 56 57 |
# File 'lib/hyraft/circuit/origin.rb', line 53 def initialize(id: nil, created_at: nil, updated_at: nil) @id = id @created_at = created_at || Time.now @updated_at = updated_at || Time.now end |
Instance Attribute Details
#created_at ⇒ Time (readonly)
Returns The timestamp when the record was created.
36 37 38 |
# File 'lib/hyraft/circuit/origin.rb', line 36 def created_at @created_at end |
#id ⇒ Integer? (readonly)
Returns The unique identifier of the record.
33 34 35 |
# File 'lib/hyraft/circuit/origin.rb', line 33 def id @id end |
#updated_at ⇒ Time (readonly)
Returns The timestamp when the record was last updated.
39 40 41 |
# File 'lib/hyraft/circuit/origin.rb', line 39 def updated_at @updated_at end |
Instance Method Details
#new_record? ⇒ Boolean
Check if the record is new and not yet persisted
85 86 87 |
# File 'lib/hyraft/circuit/origin.rb', line 85 def new_record? @id.nil? end |
#persisted? ⇒ Boolean
Check if the record has been persisted to the database
70 71 72 |
# File 'lib/hyraft/circuit/origin.rb', line 70 def persisted? !@id.nil? end |
#to_h ⇒ Hash
Convert the Engine instance to a hash representation
115 116 117 118 119 120 121 |
# File 'lib/hyraft/circuit/origin.rb', line 115 def to_h { id: @id, created_at: @created_at.iso8601, updated_at: @updated_at.iso8601 } end |
#touch ⇒ self
Update the updated_at timestamp to the current time
98 99 100 101 |
# File 'lib/hyraft/circuit/origin.rb', line 98 def touch @updated_at = Time.now self end |