configatron 3.1.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +52 -2
- data/lib/configatron/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43ae27d34852f0d6b2bc628059ad7189f2695d04
|
4
|
+
data.tar.gz: 5c8e68f8aafbf7d9f30ddc3a95110cee6405f0fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f5ba8a9bcc0785bea2cbd94f8c3983485953456be4e308bdc49bb32c93ba0a31aa6c69afe97ca67a48525262b99294ff7425948b82ad0e01349235614d0ee16
|
7
|
+
data.tar.gz: cb430f0b8c6fbe6051745b23eb26e06f45ed78814fef5f1f464e1083368fe620c7ebc3ea4c02e8732292735ab8593543fdc8cc12cf7ae6afe1b5353bddbb826e
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -139,6 +139,56 @@ configatron.letters.b # => 'B'
|
|
139
139
|
configatron.letters.c # => {}
|
140
140
|
```
|
141
141
|
|
142
|
+
### Delayed and Dynamic Configurations
|
143
|
+
|
144
|
+
There are times when you want to refer to one configuration setting in another configuration setting. Let's look at a fairly contrived example:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
configatron.memcached.servers = ['127.0.0.1:11211']
|
148
|
+
configatron.page_caching.servers = configatron.memcached.servers
|
149
|
+
configatron.object_caching.servers = configatron.memcached.servers
|
150
|
+
|
151
|
+
if Rails.env == 'production'
|
152
|
+
configatron.memcached.servers = ['192.168.0.1:11211']
|
153
|
+
configatron.page_caching.servers = configatron.memcached.servers
|
154
|
+
configatron.object_caching.servers = configatron.memcached.servers
|
155
|
+
elsif Rails.env == 'staging'
|
156
|
+
configatron.memcached.servers = ['192.168.0.2:11211']
|
157
|
+
configatron.page_caching.servers = configatron.memcached.servers
|
158
|
+
configatron.object_caching.servers = configatron.memcached.servers
|
159
|
+
end
|
160
|
+
```
|
161
|
+
|
162
|
+
Now, we could've written that slightly differently, but it helps to illustrate the point. With Configatron you can create `Delayed` and `Dynamic` settings.
|
163
|
+
|
164
|
+
#### Delayed
|
165
|
+
|
166
|
+
With `Delayed` settings execution of the setting doesn't happen until the first time it is executed.
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
configatron.memcached.servers = ['127.0.0.1:11211']
|
170
|
+
configatron.page_caching.servers = Configatron::Delayed.new {configatron.memcached.servers}
|
171
|
+
configatron.object_caching.servers = Configatron::Delayed.new {configatron.memcached.servers}
|
172
|
+
|
173
|
+
if Rails.env == 'production'
|
174
|
+
configatron.memcached.servers = ['192.168.0.1:11211']
|
175
|
+
elsif Rails.env == 'staging'
|
176
|
+
configatron.memcached.servers = ['192.168.0.2:11211']
|
177
|
+
end
|
178
|
+
```
|
179
|
+
|
180
|
+
Execution occurs once and after that the result of that execution is returned. So in our case the first time someone calls the setting `configatron.page_caching.servers` it will find the `configatron.memcached.servers` setting and return that. After that point if the `configatron.memcached.servers` setting is changed, the original settings are returned by `configatron.page_caching.servers`.
|
181
|
+
|
182
|
+
#### Dynamic
|
183
|
+
|
184
|
+
`Dynamic` settings are very similar to `Delayed` settings, but with one big difference. Every time you call a `Dynamic` setting is executed. Take this example:
|
185
|
+
|
186
|
+
```ruby
|
187
|
+
configatron.current.time = Configatron::Dynamic.new {Time.now}
|
188
|
+
```
|
189
|
+
|
190
|
+
Each time you call `configatron.current.time` it will return a new value to you. While this seems a bit useless, it is pretty useful if you have ever changing configurations.
|
191
|
+
|
142
192
|
### nil
|
143
193
|
|
144
194
|
Even if parameters haven't been set, you can still call them, but you'll get a `Configatron::Store` object back. The `Configatron::Store` class, however, will respond true to `.nil?` or `.blank?` if there are no parameters configured on it.
|
@@ -241,8 +291,8 @@ configatron.to_h # => {:letters=>{:a=>"A", :b=>"BB", :c=>"C"}}
|
|
241
291
|
* Mark Bates
|
242
292
|
* Kurtis Rainbolt-Greene
|
243
293
|
* Rob Sanheim
|
244
|
-
* Greg Brockman
|
245
294
|
* Jérémy Lecour
|
295
|
+
* Greg Brockman
|
246
296
|
* Cody Maggard
|
247
297
|
* Jean-Denis Vauguet
|
248
298
|
* Torsten Schönebaum
|
@@ -258,4 +308,4 @@ configatron.to_h # => {:letters=>{:a=>"A", :b=>"BB", :c=>"C"}}
|
|
258
308
|
* joe miller
|
259
309
|
* Brandon Dimcheff
|
260
310
|
* Rick Fletcher
|
261
|
-
* Josh
|
311
|
+
* Josh Nichols
|
data/lib/configatron/version.rb
CHANGED