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.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/smplkit/config/models.rb', line 85 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.
83 84 85 |
# File 'lib/smplkit/config/models.rb', line 83 def created_at @created_at end |
#description ⇒ Object
Returns the value of attribute description.
83 84 85 |
# File 'lib/smplkit/config/models.rb', line 83 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
83 84 85 |
# File 'lib/smplkit/config/models.rb', line 83 def id @id end |
#key ⇒ Object
Returns the value of attribute key.
83 84 85 |
# File 'lib/smplkit/config/models.rb', line 83 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
83 84 85 |
# File 'lib/smplkit/config/models.rb', line 83 def name @name end |
#parent_id ⇒ Object
Returns the value of attribute parent_id.
83 84 85 |
# File 'lib/smplkit/config/models.rb', line 83 def parent_id @parent_id end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
83 84 85 |
# File 'lib/smplkit/config/models.rb', line 83 def updated_at @updated_at end |
Instance Method Details
#_apply(other) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/smplkit/config/models.rb', line 159 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!
122 123 124 125 126 |
# File 'lib/smplkit/config/models.rb', line 122 def delete raise "Config was constructed without a client; cannot delete" if @client.nil? @client.delete(@key) end |
#environments ⇒ Object
104 105 106 |
# File 'lib/smplkit/config/models.rb', line 104 def environments @environments.dup end |
#items ⇒ Object
100 101 102 |
# File 'lib/smplkit/config/models.rb', line 100 def items @items.dup end |
#remove_item(name, environment: nil) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/smplkit/config/models.rb', line 145 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!
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/smplkit/config/models.rb', line 108 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
137 138 139 |
# File 'lib/smplkit/config/models.rb', line 137 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
141 142 143 |
# File 'lib/smplkit/config/models.rb', line 141 def set_json(name, value, environment: nil, description: nil) set_typed(name, value, ItemType::JSON, environment: environment, description: description) end |