Class: Smplkit::Platform::ContextType
- Inherits:
-
Object
- Object
- Smplkit::Platform::ContextType
- Defined in:
- lib/smplkit/platform/models.rb
Overview
A context type resource (e.g. “user”, “account”).
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #_apply(other) ⇒ Object private
-
#add_attribute(name, **metadata) ⇒ void
Add a known-attribute slot.
-
#delete ⇒ void
(also: #delete!)
Delete this context type from the server.
-
#initialize(client = nil, name:, id: nil, attributes: nil, created_at: nil, updated_at: nil) ⇒ ContextType
constructor
Create a context-type instance.
-
#remove_attribute(name) ⇒ void
Remove a known-attribute slot.
-
#save ⇒ ContextType
(also: #save!)
Create or update this context type on the server.
- #to_s ⇒ Object (also: #inspect)
-
#update_attribute(name, **metadata) ⇒ void
Replace a known-attribute slot’s metadata.
Constructor Details
#initialize(client = nil, name:, id: nil, attributes: nil, created_at: nil, updated_at: nil) ⇒ ContextType
Create a context-type instance.
Prefer client.platform.context_types.new(…) to build an unsaved context type; this constructor is also used internally to wrap server responses.
192 193 194 195 196 197 198 199 |
# File 'lib/smplkit/platform/models.rb', line 192 def initialize(client = nil, name:, id: nil, attributes: nil, created_at: nil, updated_at: nil) @client = client @id = id @name = name @attributes = attributes ? deep_dup_attrs(attributes) : {} @created_at = created_at @updated_at = updated_at end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
171 172 173 |
# File 'lib/smplkit/platform/models.rb', line 171 def attributes @attributes end |
#created_at ⇒ Object
Returns the value of attribute created_at.
171 172 173 |
# File 'lib/smplkit/platform/models.rb', line 171 def created_at @created_at end |
#id ⇒ Object
Returns the value of attribute id.
171 172 173 |
# File 'lib/smplkit/platform/models.rb', line 171 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
171 172 173 |
# File 'lib/smplkit/platform/models.rb', line 171 def name @name end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
171 172 173 |
# File 'lib/smplkit/platform/models.rb', line 171 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.
261 262 263 264 265 266 267 |
# File 'lib/smplkit/platform/models.rb', line 261 def _apply(other) @id = other.id @name = other.name @attributes = deep_dup_attrs(other.attributes) @created_at = other.created_at @updated_at = other.updated_at end |
#add_attribute(name, **metadata) ⇒ void
This method returns an undefined value.
Add a known-attribute slot. Local-only; call save to persist.
206 207 208 |
# File 'lib/smplkit/platform/models.rb', line 206 def add_attribute(name, **) @attributes[name] = () end |
#delete ⇒ void Also known as: delete!
This method returns an undefined value.
Delete this context type from the server.
248 249 250 251 252 |
# File 'lib/smplkit/platform/models.rb', line 248 def delete raise "ContextType was constructed without a client or id; cannot delete" if @client.nil? || @id.nil? @client.delete(@id) end |
#remove_attribute(name) ⇒ void
This method returns an undefined value.
Remove a known-attribute slot. Local-only; call save to persist.
215 216 217 |
# File 'lib/smplkit/platform/models.rb', line 215 def remove_attribute(name) @attributes.delete(name) end |
#save ⇒ ContextType Also known as: save!
Create or update this context type on the server.
234 235 236 237 238 239 240 |
# File 'lib/smplkit/platform/models.rb', line 234 def save raise "ContextType 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_s ⇒ Object Also known as: inspect
255 256 257 |
# File 'lib/smplkit/platform/models.rb', line 255 def to_s "ContextType(id=#{@id.inspect}, name=#{@name.inspect})" end |
#update_attribute(name, **metadata) ⇒ void
This method returns an undefined value.
Replace a known-attribute slot’s metadata. Local-only; call save.
225 226 227 |
# File 'lib/smplkit/platform/models.rb', line 225 def update_attribute(name, **) @attributes[name] = () end |