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

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_orderArray<String>

Canonical ordering of STANDARD environments. Empty list if unset.

Returns:

  • (Array<String>)

    The environment ids in canonical order.



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.

Parameters:

  • value (Array<String>)

    The environment ids in canonical order.



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

def environment_order=(value)
  @data["environment_order"] = value.to_a
end

#rawHash

The full settings dict. Mutations are persisted on save.

Returns:

  • (Hash)

    The full settings dict.



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.

Parameters:

  • value (Hash)

    The new settings dict.



27
28
29
# File 'lib/smplkit/account/models.rb', line 27

def raw=(value)
  @data = value.dup
end

#saveAccountSettings Also known as: save!

Write the full settings object back to the account.

Returns:

Raises:

  • (RuntimeError)

    If this model was constructed without a client (e.g. built by hand rather than returned from get).



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



60
61
62
# File 'lib/smplkit/account/models.rb', line 60

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