Class: Smplkit::Account::AccountSettings
- Inherits:
-
Object
- Object
- Smplkit::Account::AccountSettings
- Defined in:
- lib/smplkit/account/models.rb
Overview
Active-record account-settings model.
The wire format is opaque JSON. Documented keys are exposed as typed properties; unknown keys live in raw. save writes the full settings object back.
Instance Method Summary collapse
- #_apply(other) ⇒ Object private
-
#environment_order ⇒ Array<String>
Canonical ordering of STANDARD environments.
-
#environment_order=(value) ⇒ void
Set the canonical ordering of STANDARD environments.
-
#initialize(client = nil, data: nil) ⇒ AccountSettings
constructor
A new instance of AccountSettings.
-
#raw ⇒ Hash
The full settings dict.
-
#raw=(value) ⇒ void
Replace the full settings dict.
-
#save ⇒ AccountSettings
(also: #save!)
Write the full settings object back to the account.
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(client = nil, data: nil) ⇒ AccountSettings
Returns a new instance of AccountSettings.
11 12 13 14 |
# File 'lib/smplkit/account/models.rb', line 11 def initialize(client = nil, data: nil) @client = client @data = data ? data.dup : {} 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.
66 67 68 |
# File 'lib/smplkit/account/models.rb', line 66 def _apply(other) @data = other.raw.dup end |
#environment_order ⇒ Array<String>
Canonical ordering of STANDARD environments. Empty list if unset.
34 35 36 |
# File 'lib/smplkit/account/models.rb', line 34 def environment_order Array(@data["environment_order"] || []) end |
#environment_order=(value) ⇒ void
This method returns an undefined value.
Set the canonical ordering of STANDARD environments.
42 43 44 |
# File 'lib/smplkit/account/models.rb', line 42 def environment_order=(value) @data["environment_order"] = value.to_a end |
#raw ⇒ Hash
The full settings dict. Mutations are persisted on save.
19 20 21 |
# File 'lib/smplkit/account/models.rb', line 19 def raw @data end |
#raw=(value) ⇒ void
This method returns an undefined value.
Replace the full settings dict.
27 28 29 |
# File 'lib/smplkit/account/models.rb', line 27 def raw=(value) @data = value.dup end |
#save ⇒ AccountSettings Also known as: save!
Write the full settings object back to the account.
51 52 53 54 55 56 57 |
# File 'lib/smplkit/account/models.rb', line 51 def save raise "AccountSettings was constructed without a client; cannot save" if @client.nil? other = @client._save(@data) _apply(other) self end |
#to_s ⇒ Object Also known as: inspect
60 61 62 |
# File 'lib/smplkit/account/models.rb', line 60 def to_s "AccountSettings(#{@data.inspect})" end |