Class: Smplkit::Management::Environment

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

Overview

An environment resource — a customer-defined deploy target (production, staging, etc.) for which configs and flags can have overrides.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Environment.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/smplkit/management/models.rb', line 10

def initialize(client = nil, key:, id: nil, name: nil, color: nil,
               classification: EnvironmentClassification::STANDARD,
               description: nil, created_at: nil, updated_at: nil)
  @client = client
  @id = id
  @key = key
  @name = name
  @color = color
  @classification = classification
  @description = description
  @created_at = created_at
  @updated_at = updated_at
end

Instance Attribute Details

#classificationObject

Returns the value of attribute classification.



8
9
10
# File 'lib/smplkit/management/models.rb', line 8

def classification
  @classification
end

#colorObject

Returns the value of attribute color.



8
9
10
# File 'lib/smplkit/management/models.rb', line 8

def color
  @color
end

#created_atObject

Returns the value of attribute created_at.



8
9
10
# File 'lib/smplkit/management/models.rb', line 8

def created_at
  @created_at
end

#descriptionObject

Returns the value of attribute description.



8
9
10
# File 'lib/smplkit/management/models.rb', line 8

def description
  @description
end

#idObject

Returns the value of attribute id.



8
9
10
# File 'lib/smplkit/management/models.rb', line 8

def id
  @id
end

#keyObject

Returns the value of attribute key.



8
9
10
# File 'lib/smplkit/management/models.rb', line 8

def key
  @key
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/smplkit/management/models.rb', line 8

def name
  @name
end

#updated_atObject

Returns the value of attribute updated_at.



8
9
10
# File 'lib/smplkit/management/models.rb', line 8

def updated_at
  @updated_at
end

Instance Method Details

#_apply(other) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/smplkit/management/models.rb', line 45

def _apply(other)
  @id = other.id
  @key = other.key
  @name = other.name
  @color = other.color
  @classification = other.classification
  @description = other.description
  @created_at = other.created_at
  @updated_at = other.updated_at
end

#deleteObject Also known as: delete!



38
39
40
41
42
# File 'lib/smplkit/management/models.rb', line 38

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

  @client.delete(@key)
end

#saveObject Also known as: save!



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/smplkit/management/models.rb', line 24

def save
  raise "Environment was constructed without a client; cannot save" if @client.nil?

  updated =
    if @created_at.nil?
      @client._create_environment(self)
    else
      @client._update_environment(self)
    end
  _apply(updated)
  self
end