Class: Smplkit::Management::Service

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

Overview

A service resource — a backend application or microservice in the customer’s stack that contexts can be evaluated against.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client = nil, key:, id: nil, name: nil, created_at: nil, updated_at: nil) ⇒ Service

Returns a new instance of Service.



108
109
110
111
112
113
114
115
116
# File 'lib/smplkit/management/models.rb', line 108

def initialize(client = nil, key:, id: nil, name: nil,
               created_at: nil, updated_at: nil)
  @client = client
  @id = id
  @key = key
  @name = name
  @created_at = created_at
  @updated_at = updated_at
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



106
107
108
# File 'lib/smplkit/management/models.rb', line 106

def created_at
  @created_at
end

#idObject

Returns the value of attribute id.



106
107
108
# File 'lib/smplkit/management/models.rb', line 106

def id
  @id
end

#keyObject

Returns the value of attribute key.



106
107
108
# File 'lib/smplkit/management/models.rb', line 106

def key
  @key
end

#nameObject

Returns the value of attribute name.



106
107
108
# File 'lib/smplkit/management/models.rb', line 106

def name
  @name
end

#updated_atObject

Returns the value of attribute updated_at.



106
107
108
# File 'lib/smplkit/management/models.rb', line 106

def updated_at
  @updated_at
end

Instance Method Details

#_apply(other) ⇒ Object



139
140
141
142
143
144
145
# File 'lib/smplkit/management/models.rb', line 139

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

#deleteObject Also known as: delete!



132
133
134
135
136
# File 'lib/smplkit/management/models.rb', line 132

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

  @client.delete(@key)
end

#saveObject Also known as: save!



118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/smplkit/management/models.rb', line 118

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

  updated =
    if @created_at.nil?
      @client._create_service(self)
    else
      @client._update_service(self)
    end
  _apply(updated)
  self
end