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 private
-
#delete ⇒ void
(also: #delete!)
Delete this service from the server.
-
#initialize(client = nil, name:, id: nil, created_at: nil, updated_at: nil) ⇒ Service
constructor
Create a service instance.
-
#save ⇒ Service
(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
Create a service instance.
Prefer client.platform.services.new(…) to build an unsaved service; this constructor is also used internally to wrap server responses.
122 123 124 125 126 127 128 |
# File 'lib/smplkit/platform/models.rb', line 122 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.
106 107 108 |
# File 'lib/smplkit/platform/models.rb', line 106 def created_at @created_at end |
#id ⇒ Object
Returns the value of attribute id.
106 107 108 |
# File 'lib/smplkit/platform/models.rb', line 106 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
106 107 108 |
# File 'lib/smplkit/platform/models.rb', line 106 def name @name end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
106 107 108 |
# File 'lib/smplkit/platform/models.rb', line 106 def updated_at @updated_at end |
Instance Method Details
#_apply(other) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
161 162 163 164 165 166 |
# File 'lib/smplkit/platform/models.rb', line 161 def _apply(other) @id = other.id @name = other.name @created_at = other.created_at @updated_at = other.updated_at end |
#delete ⇒ void Also known as: delete!
This method returns an undefined value.
Delete this service from the server.
148 149 150 151 152 |
# File 'lib/smplkit/platform/models.rb', line 148 def delete raise "Service was constructed without a client or id; cannot delete" if @client.nil? || @id.nil? @client.delete(@id) end |
#save ⇒ Service Also known as: save!
Create or update this service on the server.
134 135 136 137 138 139 140 |
# File 'lib/smplkit/platform/models.rb', line 134 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
155 156 157 |
# File 'lib/smplkit/platform/models.rb', line 155 def to_s "Service(id=#{@id.inspect}, name=#{@name.inspect})" end |