Class: Smplkit::Platform::Service

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

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Service.



71
72
73
74
75
76
77
# File 'lib/smplkit/platform/models.rb', line 71

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

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



69
70
71
# File 'lib/smplkit/platform/models.rb', line 69

def created_at
  @created_at
end

#idObject

Returns the value of attribute id.



69
70
71
# File 'lib/smplkit/platform/models.rb', line 69

def id
  @id
end

#nameObject

Returns the value of attribute name.



69
70
71
# File 'lib/smplkit/platform/models.rb', line 69

def name
  @name
end

#updated_atObject

Returns the value of attribute updated_at.



69
70
71
# File 'lib/smplkit/platform/models.rb', line 69

def updated_at
  @updated_at
end

Instance Method Details

#_apply(other) ⇒ Object



102
103
104
105
106
107
# File 'lib/smplkit/platform/models.rb', line 102

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

#deleteObject Also known as: delete!

Delete this service from the server.



90
91
92
93
94
# File 'lib/smplkit/platform/models.rb', line 90

def delete
  raise "Service 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 service on the server.



80
81
82
83
84
85
86
# File 'lib/smplkit/platform/models.rb', line 80

def save
  raise "Service 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



97
98
99
# File 'lib/smplkit/platform/models.rb', line 97

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