Class: Smplkit::Platform::Environment
- Inherits:
-
Object
- Object
- Smplkit::Platform::Environment
- Defined in:
- lib/smplkit/platform/models.rb
Overview
Environment resource (sync). Mutate fields, then call save.
Instance Attribute Summary collapse
-
#classification ⇒ Object
Returns the value of attribute classification.
-
#color ⇒ Object
Returns the value of attribute color.
-
#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 environment from the server.
-
#initialize(client = nil, name:, id: nil, color: nil, classification: EnvironmentClassification::STANDARD, created_at: nil, updated_at: nil) ⇒ Environment
constructor
Create an environment instance.
-
#save ⇒ Environment
(also: #save!)
Create or update this environment on the server.
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(client = nil, name:, id: nil, color: nil, classification: EnvironmentClassification::STANDARD, created_at: nil, updated_at: nil) ⇒ Environment
Create an environment instance.
Prefer client.platform.environments.new(…) to build an unsaved environment; this constructor is also used internally to wrap server responses.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/smplkit/platform/models.rb', line 41 def initialize(client = nil, name:, id: nil, color: nil, classification: EnvironmentClassification::STANDARD, created_at: nil, updated_at: nil) @client = client @id = id @name = name @color = Platform.coerce_color(color) @classification = classification @created_at = created_at @updated_at = updated_at end |
Instance Attribute Details
#classification ⇒ Object
Returns the value of attribute classification.
17 18 19 |
# File 'lib/smplkit/platform/models.rb', line 17 def classification @classification end |
#color ⇒ Object
Returns the value of attribute color.
18 19 20 |
# File 'lib/smplkit/platform/models.rb', line 18 def color @color end |
#created_at ⇒ Object
Returns the value of attribute created_at.
17 18 19 |
# File 'lib/smplkit/platform/models.rb', line 17 def created_at @created_at end |
#id ⇒ Object
Returns the value of attribute id.
17 18 19 |
# File 'lib/smplkit/platform/models.rb', line 17 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
17 18 19 |
# File 'lib/smplkit/platform/models.rb', line 17 def name @name end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
17 18 19 |
# File 'lib/smplkit/platform/models.rb', line 17 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.
94 95 96 97 98 99 100 101 |
# File 'lib/smplkit/platform/models.rb', line 94 def _apply(other) @id = other.id @name = other.name @color = other.color @classification = other.classification @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 environment from the server.
81 82 83 84 85 |
# File 'lib/smplkit/platform/models.rb', line 81 def delete raise "Environment was constructed without a client or id; cannot delete" if @client.nil? || @id.nil? @client.delete(@id) end |
#save ⇒ Environment Also known as: save!
Create or update this environment on the server.
67 68 69 70 71 72 73 |
# File 'lib/smplkit/platform/models.rb', line 67 def save raise "Environment 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
88 89 90 |
# File 'lib/smplkit/platform/models.rb', line 88 def to_s "Environment(id=#{@id.inspect}, name=#{@name.inspect}, classification=#{@classification.inspect})" end |