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
-
#add_attribute(name, **metadata) ⇒ Object
Add a known-attribute slot.
-
#delete ⇒ Object
(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
A new instance of ContextType.
-
#remove_attribute(name) ⇒ Object
Remove a known-attribute slot.
-
#save ⇒ Object
(also: #save!)
Create or update this context type on the server.
- #to_s ⇒ Object (also: #inspect)
-
#update_attribute(name, **metadata) ⇒ Object
Replace a known-attribute slot’s metadata.
Constructor Details
#initialize(client = nil, name:, id: nil, attributes: nil, created_at: nil, updated_at: nil) ⇒ ContextType
Returns a new instance of ContextType.
114 115 116 117 118 119 120 121 |
# File 'lib/smplkit/platform/models.rb', line 114 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.
112 113 114 |
# File 'lib/smplkit/platform/models.rb', line 112 def attributes @attributes end |
#created_at ⇒ Object
Returns the value of attribute created_at.
112 113 114 |
# File 'lib/smplkit/platform/models.rb', line 112 def created_at @created_at end |
#id ⇒ Object
Returns the value of attribute id.
112 113 114 |
# File 'lib/smplkit/platform/models.rb', line 112 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
112 113 114 |
# File 'lib/smplkit/platform/models.rb', line 112 def name @name end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
112 113 114 |
# File 'lib/smplkit/platform/models.rb', line 112 def updated_at @updated_at end |
Instance Method Details
#_apply(other) ⇒ Object
161 162 163 164 165 166 167 |
# File 'lib/smplkit/platform/models.rb', line 161 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) ⇒ Object
Add a known-attribute slot. Local; call save to persist.
124 125 126 |
# File 'lib/smplkit/platform/models.rb', line 124 def add_attribute(name, **) @attributes[name] = () end |
#delete ⇒ Object Also known as: delete!
Delete this context type from the server.
149 150 151 152 153 |
# File 'lib/smplkit/platform/models.rb', line 149 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) ⇒ Object
Remove a known-attribute slot. Local; call save to persist.
129 130 131 |
# File 'lib/smplkit/platform/models.rb', line 129 def remove_attribute(name) @attributes.delete(name) end |
#save ⇒ Object Also known as: save!
Create or update this context type on the server.
139 140 141 142 143 144 145 |
# File 'lib/smplkit/platform/models.rb', line 139 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
156 157 158 |
# File 'lib/smplkit/platform/models.rb', line 156 def to_s "ContextType(id=#{@id.inspect}, name=#{@name.inspect})" end |
#update_attribute(name, **metadata) ⇒ Object
Replace a known-attribute slot’s metadata. Local; call save.
134 135 136 |
# File 'lib/smplkit/platform/models.rb', line 134 def update_attribute(name, **) @attributes[name] = () end |