Class: Smplkit::Platform::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/smplkit/platform/models.rb

Overview

Environment resource (sync). Mutate fields, then call save.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client = nil, name:, id: nil, color: nil, classification: EnvironmentClassification::STANDARD, created_at: nil, updated_at: nil) ⇒ Environment

Returns a new instance of Environment.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/smplkit/platform/models.rb', line 18

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

#classificationObject

Returns the value of attribute classification.



15
16
17
# File 'lib/smplkit/platform/models.rb', line 15

def classification
  @classification
end

#colorObject

Returns the value of attribute color.



16
17
18
# File 'lib/smplkit/platform/models.rb', line 16

def color
  @color
end

#created_atObject

Returns the value of attribute created_at.



15
16
17
# File 'lib/smplkit/platform/models.rb', line 15

def created_at
  @created_at
end

#idObject

Returns the value of attribute id.



15
16
17
# File 'lib/smplkit/platform/models.rb', line 15

def id
  @id
end

#nameObject

Returns the value of attribute name.



15
16
17
# File 'lib/smplkit/platform/models.rb', line 15

def name
  @name
end

#updated_atObject

Returns the value of attribute updated_at.



15
16
17
# File 'lib/smplkit/platform/models.rb', line 15

def updated_at
  @updated_at
end

Instance Method Details

#_apply(other) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/smplkit/platform/models.rb', line 57

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

#deleteObject Also known as: delete!

Delete this environment from the server.



45
46
47
48
49
# File 'lib/smplkit/platform/models.rb', line 45

def delete
  raise "Environment was constructed without a client or id; cannot delete" if @client.nil? || @id.nil?

  @client.delete(@id)
end

#saveObject Also known as: save!

Create or update this environment on the server.



35
36
37
38
39
40
41
# File 'lib/smplkit/platform/models.rb', line 35

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_sObject Also known as: inspect



52
53
54
# File 'lib/smplkit/platform/models.rb', line 52

def to_s
  "Environment(id=#{@id.inspect}, name=#{@name.inspect}, classification=#{@classification.inspect})"
end