Class: Smplkit::Account::AccountSettings

Inherits:
Object
  • Object
show all
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

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_orderObject

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

#rawObject

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

#saveObject 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_sObject Also known as: inspect



43
44
45
# File 'lib/smplkit/account/models.rb', line 43

def to_s
  "AccountSettings(#{@data.inspect})"
end