Class: Smplkit::Platform::Service
- Inherits:
-
Object
- Object
- Smplkit::Platform::Service
- Defined in:
- lib/smplkit/platform/models.rb
Overview
Service resource (sync). Mutate fields, then call save.
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #_apply(other) ⇒ Object
-
#delete ⇒ Object
(also: #delete!)
Delete this service from the server.
-
#initialize(client = nil, name:, id: nil, created_at: nil, updated_at: nil) ⇒ Service
constructor
A new instance of Service.
-
#save ⇒ Object
(also: #save!)
Create or update this service on the server.
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(client = nil, name:, id: nil, created_at: nil, updated_at: nil) ⇒ Service
Returns a new instance of Service.
71 72 73 74 75 76 77 |
# File 'lib/smplkit/platform/models.rb', line 71 def initialize(client = nil, name:, id: nil, created_at: nil, updated_at: nil) @client = client @id = id @name = name @created_at = created_at @updated_at = updated_at end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
69 70 71 |
# File 'lib/smplkit/platform/models.rb', line 69 def created_at @created_at end |
#id ⇒ Object
Returns the value of attribute id.
69 70 71 |
# File 'lib/smplkit/platform/models.rb', line 69 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
69 70 71 |
# File 'lib/smplkit/platform/models.rb', line 69 def name @name end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
69 70 71 |
# File 'lib/smplkit/platform/models.rb', line 69 def updated_at @updated_at end |
Instance Method Details
#_apply(other) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/smplkit/platform/models.rb', line 102 def _apply(other) @id = other.id @name = other.name @created_at = other.created_at @updated_at = other.updated_at end |
#delete ⇒ Object Also known as: delete!
Delete this service from the server.
90 91 92 93 94 |
# File 'lib/smplkit/platform/models.rb', line 90 def delete raise "Service was constructed without a client or id; cannot delete" if @client.nil? || @id.nil? @client.delete(@id) end |
#save ⇒ Object Also known as: save!
Create or update this service on the server.
80 81 82 83 84 85 86 |
# File 'lib/smplkit/platform/models.rb', line 80 def save raise "Service was constructed without a client; cannot save" if @client.nil? other = @created_at.nil? ? @client._create(self) : @client._update(self) _apply(other) self end |
#to_s ⇒ Object Also known as: inspect
97 98 99 |
# File 'lib/smplkit/platform/models.rb', line 97 def to_s "Service(id=#{@id.inspect}, name=#{@name.inspect})" end |