Class: Smplkit::Config::Config
- Inherits:
-
Object
- Object
- Smplkit::Config::Config
- Defined in:
- lib/smplkit/config/models.rb
Overview
A configuration resource — a typed bag of items with per-environment overrides.
Provides management operations (save, set_string/set_number/…) and runtime evaluation via get on the parent ConfigClient.
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
-
#key ⇒ Object
Returns the value of attribute key.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent_id ⇒ Object
Returns the value of attribute parent_id.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #_apply(other) ⇒ Object
- #delete ⇒ Object (also: #delete!)
- #environments ⇒ Object
-
#initialize(client = nil, key:, id: nil, name: nil, description: nil, parent_id: nil, items: nil, environments: nil, created_at: nil, updated_at: nil) ⇒ Config
constructor
A new instance of Config.
- #items ⇒ Object
- #remove_item(name, environment: nil) ⇒ Object
- #save ⇒ Object (also: #save!)
- #set_boolean(name, value, environment: nil, description: nil) ⇒ Object
- #set_json(name, value, environment: nil, description: nil) ⇒ Object
- #set_number(name, value, environment: nil, description: nil) ⇒ Object
- #set_string(name, value, environment: nil, description: nil) ⇒ Object
Constructor Details
#initialize(client = nil, key:, id: nil, name: nil, description: nil, parent_id: nil, items: nil, environments: nil, created_at: nil, updated_at: nil) ⇒ Config
Returns a new instance of Config.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/smplkit/config/models.rb', line 79 def initialize(client = nil, key:, id: nil, name: nil, description: nil, parent_id: nil, items: nil, environments: nil, created_at: nil, updated_at: nil) @client = client @id = id @key = key @name = name @description = description @parent_id = parent_id @items = items ? items.dup : [] @environments = environments ? environments.dup : {} @created_at = created_at @updated_at = updated_at end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
77 78 79 |
# File 'lib/smplkit/config/models.rb', line 77 def created_at @created_at end |
#description ⇒ Object
Returns the value of attribute description.
77 78 79 |
# File 'lib/smplkit/config/models.rb', line 77 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
77 78 79 |
# File 'lib/smplkit/config/models.rb', line 77 def id @id end |
#key ⇒ Object
Returns the value of attribute key.
77 78 79 |
# File 'lib/smplkit/config/models.rb', line 77 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
77 78 79 |
# File 'lib/smplkit/config/models.rb', line 77 def name @name end |
#parent_id ⇒ Object
Returns the value of attribute parent_id.
77 78 79 |
# File 'lib/smplkit/config/models.rb', line 77 def parent_id @parent_id end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
77 78 79 |
# File 'lib/smplkit/config/models.rb', line 77 def updated_at @updated_at end |
Instance Method Details
#_apply(other) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/smplkit/config/models.rb', line 153 def _apply(other) @id = other.id @key = other.key @name = other.name @description = other.description @parent_id = other.parent_id @items = other.items @environments = other.environments @created_at = other.created_at @updated_at = other.updated_at end |
#delete ⇒ Object Also known as: delete!
116 117 118 119 120 |
# File 'lib/smplkit/config/models.rb', line 116 def delete raise "Config was constructed without a client; cannot delete" if @client.nil? @client.delete(@key) end |
#environments ⇒ Object
98 99 100 |
# File 'lib/smplkit/config/models.rb', line 98 def environments @environments.dup end |
#items ⇒ Object
94 95 96 |
# File 'lib/smplkit/config/models.rb', line 94 def items @items.dup end |
#remove_item(name, environment: nil) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/smplkit/config/models.rb', line 139 def remove_item(name, environment: nil) if environment env = @environments[environment] return unless env raw = env.values_raw raw.delete(name) env._replace_raw(raw) else @items.reject! { |i| i.name == name } end self end |
#save ⇒ Object Also known as: save!
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/smplkit/config/models.rb', line 102 def save raise "Config was constructed without a client; cannot save" if @client.nil? updated = if @created_at.nil? @client._create_config(self) else @client._update_config(self) end _apply(updated) self end |
#set_boolean(name, value, environment: nil, description: nil) ⇒ Object
131 132 133 |
# File 'lib/smplkit/config/models.rb', line 131 def set_boolean(name, value, environment: nil, description: nil) set_typed(name, value, ItemType::BOOLEAN, environment: environment, description: description) end |
#set_json(name, value, environment: nil, description: nil) ⇒ Object
135 136 137 |
# File 'lib/smplkit/config/models.rb', line 135 def set_json(name, value, environment: nil, description: nil) set_typed(name, value, ItemType::JSON, environment: environment, description: description) end |