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
-
#environment_order ⇒ Object
Canonical ordering of STANDARD environments.
- #environment_order=(value) ⇒ Object
-
#initialize(client = nil, data: nil) ⇒ AccountSettings
constructor
A new instance of AccountSettings.
-
#raw ⇒ Object
The full settings dict.
- #raw=(value) ⇒ Object
- #save ⇒ Object (also: #save!)
- #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
48 49 50 |
# File 'lib/smplkit/account/models.rb', line 48 def _apply(other) @data = other.raw.dup end |
#environment_order ⇒ Object
Canonical ordering of STANDARD environments. Empty list if unset.
26 27 28 |
# File 'lib/smplkit/account/models.rb', line 26 def environment_order Array(@data["environment_order"] || []) end |
#environment_order=(value) ⇒ Object
30 31 32 |
# File 'lib/smplkit/account/models.rb', line 30 def environment_order=(value) @data["environment_order"] = value.to_a end |
#raw ⇒ Object
The full settings dict. Mutations are persisted on save.
17 18 19 |
# File 'lib/smplkit/account/models.rb', line 17 def raw @data end |
#raw=(value) ⇒ Object
21 22 23 |
# File 'lib/smplkit/account/models.rb', line 21 def raw=(value) @data = value.dup end |
#save ⇒ Object Also known as: save!
34 35 36 37 38 39 40 |
# File 'lib/smplkit/account/models.rb', line 34 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
43 44 45 |
# File 'lib/smplkit/account/models.rb', line 43 def to_s "AccountSettings(#{@data.inspect})" end |