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

Create an environment instance.

Prefer client.platform.environments.new(…) to build an unsaved environment; this constructor is also used internally to wrap server responses.

Parameters:

  • client (EnvironmentsClient, nil) (defaults to: nil)

    Client used to persist and delete this environment. nil produces a detached instance that cannot save.

  • name (String)

    Display name shown in the Console.

  • id (String, nil) (defaults to: nil)

    Stable, human-readable identifier for the environment.

  • color (Color, String, nil) (defaults to: nil)

    Accent color, as a Color or a CSS hex string. Defaults to no color.

  • classification (String) (defaults to: EnvironmentClassification::STANDARD)

    Whether the environment participates in the standard environment ordering. Defaults to EnvironmentClassification::STANDARD.

  • created_at (String, nil) (defaults to: nil)

    When the environment was created. Set on instances returned by the server; leave nil for unsaved ones.

  • updated_at (String, nil) (defaults to: nil)

    When the environment was last updated. Set on instances returned by the server; leave nil for unsaved ones.



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

#classificationObject

Returns the value of attribute classification.



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

def classification
  @classification
end

#colorObject

Returns the value of attribute color.



18
19
20
# File 'lib/smplkit/platform/models.rb', line 18

def color
  @color
end

#created_atObject

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#updated_atObject

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

#deletevoid Also known as: delete!

This method returns an undefined value.

Delete this environment from the server.

Raises:

  • (RuntimeError)

    If this environment was constructed without a client or id.



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

#saveEnvironment Also known as: save!

Create or update this environment on the server.

Returns:

  • (Environment)

    self, updated with the server response.

Raises:

  • (RuntimeError)

    If this environment was constructed without a client.



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_sObject 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