configatronn 4.5.2
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 +7 -0
- data/.github/workflows/test.yml +27 -0
- data/.gitignore +22 -0
- data/Gemfile +6 -0
- data/History.txt +82 -0
- data/LICENSE.txt +23 -0
- data/README.md +312 -0
- data/Rakefile +15 -0
- data/configatronn.gemspec +28 -0
- data/lib/configatron/core.rb +6 -0
- data/lib/configatron/delayed.rb +2 -0
- data/lib/configatron/dynamic.rb +7 -0
- data/lib/configatron/errors.rb +9 -0
- data/lib/configatron/ext/kernel.rb +5 -0
- data/lib/configatron/integrations/minitest.rb +29 -0
- data/lib/configatron/integrations/rails.rb +53 -0
- data/lib/configatron/integrations.rb +4 -0
- data/lib/configatron/proc.rb +34 -0
- data/lib/configatron/root_store.rb +126 -0
- data/lib/configatron/store.rb +182 -0
- data/lib/configatron/version.rb +3 -0
- data/lib/configatron.rb +23 -0
- data/lib/generators/configatron/install/install_generator.rb +24 -0
- data/lib/generators/configatron/install/templates/configatron/defaults.rb +7 -0
- data/lib/generators/configatron/install/templates/configatron/development.rb +4 -0
- data/lib/generators/configatron/install/templates/configatron/production.rb +4 -0
- data/lib/generators/configatron/install/templates/configatron/test.rb +4 -0
- data/lib/generators/configatron/install/templates/initializers/configatron.rb +2 -0
- data/test/_lib.rb +17 -0
- data/test/functional/_lib/scripts/core.rb +11 -0
- data/test/functional/_lib.rb +10 -0
- data/test/functional/configatron.rb +194 -0
- data/test/functional/delayed.rb +18 -0
- data/test/functional/loading.rb +10 -0
- data/test/functional/minitest.rb +18 -0
- data/test/functional/rails.rb +94 -0
- data/test/unit/_lib.rb +10 -0
- data/test/unit/configatron/proc.rb +24 -0
- data/test/unit/configatron/root_store.rb +37 -0
- data/test/unit/configatron/store.rb +149 -0
- metadata +203 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 33f037ad90a09009fff36e0668cc8f2232a08a577098a930656da08bab11d653
|
4
|
+
data.tar.gz: d08458dfa3ad8abba43bea11c603a1a01cc5bf70c2e9e96bb9079be355de14b4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 667a6bbc0bf2a2957770d7508e9a349440c20d8f1c5957598c9b0ccc9b9b404b509254b79682d23627692dfc7efac180708aa0747883546f1543308c5777c737
|
7
|
+
data.tar.gz: c625e5f08734f6e7ed45f15b1483f4dc0bc07e110742cbaa5aca4673e45367ddbb1c8bc3dade7962bf7b1a9f413f4b534d9be79bf49fcc9e5ec2cf5083fd0eaa
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: test
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
paths-ignore:
|
6
|
+
- '**.md'
|
7
|
+
pull_request:
|
8
|
+
paths-ignore:
|
9
|
+
- '**.md'
|
10
|
+
schedule:
|
11
|
+
- cron: "0 15 * * 0"
|
12
|
+
|
13
|
+
jobs:
|
14
|
+
test:
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
strategy:
|
17
|
+
matrix:
|
18
|
+
ruby: ['3.0', '3.1', '3.2', '3.3', '3.4']
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v4
|
21
|
+
- name: Set up ruby
|
22
|
+
uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby }}
|
25
|
+
bundler-cache: true
|
26
|
+
- name: Run tests
|
27
|
+
run: bundle update && bundle exec rake test
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
doc
|
2
|
+
*.gem
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
.ruby-version
|
19
|
+
|
20
|
+
.DS_Store
|
21
|
+
*.rbc
|
22
|
+
*.log
|
data/Gemfile
ADDED
data/History.txt
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
=== 4.5.2
|
2
|
+
|
3
|
+
* Fix bug: Configatron::Integrations::Rails.init raise without Rails gem.
|
4
|
+
* Add Ruby 3.2 support, as File.exists? alias was removed.
|
5
|
+
* Remove deprecation warning: use assert_nil if expecting nil by Minitest.
|
6
|
+
|
7
|
+
=== 4.5.1
|
8
|
+
|
9
|
+
* Replace regex with end_with? in lookup
|
10
|
+
|
11
|
+
=== 4.5.0
|
12
|
+
|
13
|
+
* [backwards-incompatible] Switch from DeepClone to copy-on-write for temp. As part of the implementation, *values* are no longer cloned.
|
14
|
+
|
15
|
+
=== 4.4.1
|
16
|
+
|
17
|
+
* Make lock!/unlock! support blocks
|
18
|
+
|
19
|
+
=== 4.4.0
|
20
|
+
|
21
|
+
* [backwards-incompatible] Make temp preserve locking state across invocations
|
22
|
+
|
23
|
+
=== 4.3.0
|
24
|
+
|
25
|
+
* [backwards-incompatible] Make nil into a valid config value
|
26
|
+
* [backwards-incompatible] Make temp clean up after itself when an exception is thrown
|
27
|
+
|
28
|
+
=== 4.2.1
|
29
|
+
|
30
|
+
* Fix a bug with deep cloning which caused temping to break for nested settings
|
31
|
+
|
32
|
+
=== 4.2.0
|
33
|
+
|
34
|
+
* [backwards-incompatible] Make to_h/to_hash recursively hashify Configatron::Stores, and resolve Configatron::Procs.
|
35
|
+
|
36
|
+
=== 4.1.1
|
37
|
+
|
38
|
+
* Fix delayed attributes
|
39
|
+
|
40
|
+
=== 4.1.0
|
41
|
+
|
42
|
+
* Fix bugs from BasicObject fallout
|
43
|
+
* Have KernelStore proxy calls using `public_send` for consistent shadowing
|
44
|
+
|
45
|
+
=== 4.0.3
|
46
|
+
|
47
|
+
* Switch Store and RootStore to descend from BasicObject
|
48
|
+
|
49
|
+
=== 4.0.2
|
50
|
+
|
51
|
+
* Add missing require of Rails integration
|
52
|
+
|
53
|
+
=== 4.0.1
|
54
|
+
|
55
|
+
* Fix #inspect and #to_s methods on KernelStore to pass through to Store
|
56
|
+
|
57
|
+
=== 4.0.0
|
58
|
+
|
59
|
+
This is largely a restructuring of existing functionality, making it
|
60
|
+
simpler and more consistent. The tests have also been fully
|
61
|
+
refactored.
|
62
|
+
|
63
|
+
Added the following:
|
64
|
+
|
65
|
+
* A Minitest integration at Configatron::Integrations::Minitest
|
66
|
+
* Key errors while locked return the name of the relevant configatron
|
67
|
+
* Configatron::RootStore is now the intended way to start a new configatron hiearchy. (You should likely not initialize a Configatron::Store yourself.)
|
68
|
+
|
69
|
+
Deprecated the following:
|
70
|
+
|
71
|
+
* Initializing a Configatron::Store with a custom hash
|
72
|
+
* Calling .nil?/.empty? on a Configatron::Store
|
73
|
+
* Calling locking, temp, or reset methods directly on a Configatron::Store (moved instead to Configatron::RootStore)
|
74
|
+
* A DeepClone module is no longer defined at the top-level
|
75
|
+
* Removed Configatron::KernelStore
|
76
|
+
|
77
|
+
Other backwards-incompatible changes:
|
78
|
+
|
79
|
+
* Renamespaced Configatron::Rails under Configatron::Integrations::Rails.
|
80
|
+
* Moved locking and temp methods to exist just on Configatron::RootStore.
|
81
|
+
* Configatron::Store.inspect no longer takes a name
|
82
|
+
* key? will now return true for sub-Configatron::Stores
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2013 Mark Bates
|
2
|
+
Copyright (c) 2025 Taku Shimizu
|
3
|
+
|
4
|
+
MIT License
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
a copy of this software and associated documentation files (the
|
8
|
+
"Software"), to deal in the Software without restriction, including
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
the following conditions:
|
13
|
+
|
14
|
+
The above copyright notice and this permission notice shall be
|
15
|
+
included in all copies or substantial portions of the Software.
|
16
|
+
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,312 @@
|
|
1
|
+
# Configatron
|
2
|
+
|
3
|
+
|
4
|
+
Configatron makes configuring your applications and scripts incredibly easy. No longer is a there a need to use constants or global variables. Now you can use a simple and painless system to configure your life. And, because it's all Ruby, you can do any crazy thing you would like to!
|
5
|
+
|
6
|
+
One of the more important changes to V3 is that it now resembles more a `Hash` style interface. You can use `[]`, `fetch`, `each`, etc... Actually the hash notation is a bit more robust since the dot notation won't work for a few property names (a few public methods from `Configatron::Store` itself).
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'configatronn'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
```bash
|
19
|
+
$ bundle
|
20
|
+
```
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
```bash
|
25
|
+
$ gem install configatronn --pre
|
26
|
+
```
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Once installed you just need to require it:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
require 'configatronn'
|
34
|
+
```
|
35
|
+
|
36
|
+
### Simple
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
configatron.email = 'me@example.com'
|
40
|
+
configatron.database.url = "postgres://localhost/foo"
|
41
|
+
```
|
42
|
+
|
43
|
+
Now, anywhere in your code you can do the following:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
configatron.email # => "me@example.com"
|
47
|
+
configatron.database.url # => "postgres://localhost/foo"
|
48
|
+
```
|
49
|
+
|
50
|
+
Voila! Simple as can be.
|
51
|
+
|
52
|
+
Now you're saying, what if I want to have a 'default' set of options, but then override them later, based on other information? Simple again. Let's use our above example. We've configured our `database.url` option to be `postgres://localhost/foo`. The problem with that is that is our production database url, not our development url. Fair enough, all you have to do is redeclare it:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
configatron.database.url = "postgres://localhost/foo_development"
|
56
|
+
```
|
57
|
+
|
58
|
+
becomes:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
configatron.email # => "me@example.com"
|
62
|
+
configatron.database.url # => "postgres://localhost/foo_development"
|
63
|
+
```
|
64
|
+
|
65
|
+
Notice how our other configuration parameters haven't changed? Cool, eh?
|
66
|
+
|
67
|
+
### Hash/YAML
|
68
|
+
|
69
|
+
You can configure Configatron from a hash as well (this is particularly useful if you'd like to have configuration files):
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
configatron.configure_from_hash(email: {pop: {address: 'pop.example.com', port: 110}}, smtp: {address: 'smtp.example.com'})
|
73
|
+
|
74
|
+
configatron.email.pop.address # => 'pop.example.com'
|
75
|
+
configatron.email.pop.port # => 110
|
76
|
+
# and so on...
|
77
|
+
```
|
78
|
+
|
79
|
+
### Method vs hash access
|
80
|
+
|
81
|
+
As a note, method (`configatron.foo`) access will be shadowed by public methods defined on the configatron object. (The configatron object descends from [`BasicObject`](http://apidock.com/ruby/BasicObject) and adds a few methods to resemble the `Hash` API and to play nice with `puts`, so it should have a pretty bare set of methods.)
|
82
|
+
|
83
|
+
If you need to use keys that are themselves method names, you can just use hash access (`configatron['foo']`).
|
84
|
+
|
85
|
+
### Namespaces
|
86
|
+
|
87
|
+
The question that should be on your lips is what I need to have namespaced configuration parameters. It's easy! Configatron allows you to create namespaces.
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
configatron.website_url = "http://www.example.com"
|
91
|
+
configatron.email.pop.address = "pop.example.com"
|
92
|
+
configatron.email.pop.port = 110
|
93
|
+
configatron.email.smtp.address = "smtp.example.com"
|
94
|
+
configatron.email.smtp.port = 25
|
95
|
+
|
96
|
+
configatron.to_h # => {:website_url=>"http://www.example.com", :email=>{:pop=>{:address=>"pop.example.com", :port=>110}, :smtp=>{:address=>"smtp.example.com", :port=>25}}}
|
97
|
+
```
|
98
|
+
|
99
|
+
Configatron allows you to nest namespaces to your hearts content! Just keep going, it's that easy.
|
100
|
+
|
101
|
+
Of course you can update a single parameter n levels deep as well:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
configatron.email.pop.address = "pop2.example.com"
|
105
|
+
|
106
|
+
configatron.email.pop.address # => "pop2.example.com"
|
107
|
+
configatron.email.smtp.address # => "smtp.example.com"
|
108
|
+
```
|
109
|
+
|
110
|
+
Configatron will also let you use a block to clean up your configuration. For example the following two ways of setting values are equivalent:
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
configatron.email.pop.address = "pop.example.com"
|
114
|
+
configatron.email.pop.port = 110
|
115
|
+
|
116
|
+
configatron.email.pop do |pop|
|
117
|
+
pop.address = "pop.example.com"
|
118
|
+
pop.port = 110
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
122
|
+
### Temp Configurations
|
123
|
+
|
124
|
+
Sometimes in testing, or other situations, you want to temporarily change some settings. You can do this with the `temp` method (only available on the top-level configatron `RootStore`):
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
configatron.one = 1
|
128
|
+
configatron.letters.a = 'A'
|
129
|
+
configatron.letters.b = 'B'
|
130
|
+
configatron.temp do
|
131
|
+
configatron.letters.b = 'bb'
|
132
|
+
configatron.letters.c = 'c'
|
133
|
+
configatron.one # => 1
|
134
|
+
configatron.letters.a # => 'A'
|
135
|
+
configatron.letters.b # => 'bb'
|
136
|
+
configatron.letters.c # => 'c'
|
137
|
+
end
|
138
|
+
configatron.one # => 1
|
139
|
+
configatron.letters.a # => 'A'
|
140
|
+
configatron.letters.b # => 'B'
|
141
|
+
configatron.letters.c # => {}
|
142
|
+
```
|
143
|
+
|
144
|
+
### Delayed and Dynamic Configurations
|
145
|
+
|
146
|
+
There are times when you want to refer to one configuration setting in another configuration setting. Let's look at a fairly contrived example:
|
147
|
+
|
148
|
+
```ruby
|
149
|
+
configatron.memcached.servers = ['127.0.0.1:11211']
|
150
|
+
configatron.page_caching.servers = configatron.memcached.servers
|
151
|
+
configatron.object_caching.servers = configatron.memcached.servers
|
152
|
+
|
153
|
+
if Rails.env == 'production'
|
154
|
+
configatron.memcached.servers = ['192.168.0.1:11211']
|
155
|
+
configatron.page_caching.servers = configatron.memcached.servers
|
156
|
+
configatron.object_caching.servers = configatron.memcached.servers
|
157
|
+
elsif Rails.env == 'staging'
|
158
|
+
configatron.memcached.servers = ['192.168.0.2:11211']
|
159
|
+
configatron.page_caching.servers = configatron.memcached.servers
|
160
|
+
configatron.object_caching.servers = configatron.memcached.servers
|
161
|
+
end
|
162
|
+
```
|
163
|
+
|
164
|
+
Now, we could've written that slightly differently, but it helps to illustrate the point. With Configatron you can create `Delayed` and `Dynamic` settings.
|
165
|
+
|
166
|
+
#### Delayed
|
167
|
+
|
168
|
+
With `Delayed` settings execution of the setting doesn't happen until the first time it is executed.
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
configatron.memcached.servers = ['127.0.0.1:11211']
|
172
|
+
configatron.page_caching.servers = Configatron::Delayed.new {configatron.memcached.servers}
|
173
|
+
configatron.object_caching.servers = Configatron::Delayed.new {configatron.memcached.servers}
|
174
|
+
|
175
|
+
if Rails.env == 'production'
|
176
|
+
configatron.memcached.servers = ['192.168.0.1:11211']
|
177
|
+
elsif Rails.env == 'staging'
|
178
|
+
configatron.memcached.servers = ['192.168.0.2:11211']
|
179
|
+
end
|
180
|
+
```
|
181
|
+
|
182
|
+
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`.
|
183
|
+
|
184
|
+
#### Dynamic
|
185
|
+
|
186
|
+
`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:
|
187
|
+
|
188
|
+
```ruby
|
189
|
+
configatron.current.time = Configatron::Dynamic.new {Time.now}
|
190
|
+
```
|
191
|
+
|
192
|
+
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.
|
193
|
+
|
194
|
+
### Reseting Configurations
|
195
|
+
|
196
|
+
In some testing scenarios, it can be helpful to restore Configatron to its default state. This can be done with:
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
configatron.reset!
|
200
|
+
```
|
201
|
+
|
202
|
+
### Checking keys
|
203
|
+
|
204
|
+
Even if parameters haven't been set, you can still call them, but you'll get a `Configatron::Store` object back. You can use `.has_key?` to determine if a key already exists.
|
205
|
+
|
206
|
+
```ruby
|
207
|
+
configatron.i.dont.has_key?(:exist) # => false
|
208
|
+
```
|
209
|
+
|
210
|
+
#### (key)!
|
211
|
+
|
212
|
+
You can also append a `!` to the end of any key. If the key exists it will return it, otherwise it will raise a `Configatron::UndefinedKeyError`.
|
213
|
+
|
214
|
+
``` ruby
|
215
|
+
configatron.a.b = 'B'
|
216
|
+
configatron.a.b # => 'B'
|
217
|
+
configatron.a.b! # => 'B'
|
218
|
+
configatron.a.b.c! # => raise Configratron::UndefinedKeyError
|
219
|
+
```
|
220
|
+
|
221
|
+
### Kernel
|
222
|
+
|
223
|
+
The `configatron` "helper" method is stored in the `Kernel` module. You can opt-out of this global monkey-patching by requiring `configatron/core` rather than `configatron`. You'll have to set up your own `Configatron::RootStore` object.
|
224
|
+
|
225
|
+
Example:
|
226
|
+
|
227
|
+
```ruby
|
228
|
+
require 'configatronn/core'
|
229
|
+
|
230
|
+
store = Configatron::RootStore.new
|
231
|
+
store.foo = 'FOO'
|
232
|
+
|
233
|
+
store.to_h #= {foo: 'FOO'}
|
234
|
+
```
|
235
|
+
|
236
|
+
### Locking
|
237
|
+
|
238
|
+
Once you have setup all of your configurations you can call the `lock!` method to lock your settings and raise an error should anyone try to change settings or access an unset setting later.
|
239
|
+
|
240
|
+
Example:
|
241
|
+
|
242
|
+
```ruby
|
243
|
+
configatron.foo = 'FOO'
|
244
|
+
configatron.lock!
|
245
|
+
|
246
|
+
configatron.foo # => 'FOO'
|
247
|
+
|
248
|
+
configatron.bar # => raises Configatron::UndefinedKeyError
|
249
|
+
configatron.bar = 'BAR' # => raises Configatron::LockedError
|
250
|
+
```
|
251
|
+
|
252
|
+
## Rails
|
253
|
+
|
254
|
+
Configatron works great with Rails. Use the built-in generate to generate an initializer file and a series of environment files for you to use to configure your applications.
|
255
|
+
|
256
|
+
``` bash
|
257
|
+
$ rails generate configatron:install
|
258
|
+
```
|
259
|
+
|
260
|
+
Configatron will read in the `config/configatron/defaults.rb` file first and then the environment specific file, such as `config/configatron/development.rb`. Settings in the environment file will merge into and replace the settings in the `defaults.rb` file.
|
261
|
+
|
262
|
+
### Example
|
263
|
+
|
264
|
+
```ruby
|
265
|
+
# config/configatron/defaults.rb
|
266
|
+
configatron.letters.a = 'A'
|
267
|
+
configatron.letters.b = 'B'
|
268
|
+
```
|
269
|
+
|
270
|
+
```ruby
|
271
|
+
# config/configatron/development.rb
|
272
|
+
configatron.letters.b = 'BB'
|
273
|
+
configatron.letters.c = 'C'
|
274
|
+
```
|
275
|
+
|
276
|
+
```ruby
|
277
|
+
configatron.to_h # => {:letters=>{:a=>"A", :b=>"BB", :c=>"C"}}
|
278
|
+
```
|
279
|
+
|
280
|
+
## Contributing
|
281
|
+
|
282
|
+
1. Fork it
|
283
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
284
|
+
3. Write Tests!
|
285
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
286
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
287
|
+
6. Create new Pull Request
|
288
|
+
|
289
|
+
## Contributors (markbates/configatron)
|
290
|
+
|
291
|
+
* Mark Bates
|
292
|
+
* Greg Brockman
|
293
|
+
* Kurtis Rainbolt-Greene
|
294
|
+
* Rob Sanheim
|
295
|
+
* Jérémy Lecour
|
296
|
+
* Cody Maggard
|
297
|
+
* Jean-Denis Vauguet
|
298
|
+
* chatgris
|
299
|
+
* Simon Menke
|
300
|
+
* Mat Brown
|
301
|
+
* Torsten Schönebaum
|
302
|
+
* Gleb Pomykalov
|
303
|
+
* Casper Gripenberg
|
304
|
+
* Artiom Diomin
|
305
|
+
* mattelacchiato
|
306
|
+
* Dan Pickett
|
307
|
+
* Tim Riley
|
308
|
+
* Rick Fletcher
|
309
|
+
* Jose Antonio Pio
|
310
|
+
* Brandon Dimcheff
|
311
|
+
* joe miller
|
312
|
+
* Josh Nichols
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.libs = ["lib"]
|
8
|
+
# t.warning = true
|
9
|
+
t.verbose = true
|
10
|
+
t.test_files = FileList['test/**/*.rb'].reject do |file|
|
11
|
+
file.end_with?('_lib.rb') || file.include?('/_lib/')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
task :default => :test
|
@@ -0,0 +1,28 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'configatron/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'configatronn'
|
7
|
+
gem.version = Configatron::VERSION
|
8
|
+
gem.authors = ['Taku Shimizu']
|
9
|
+
gem.email = ['t_shimizu@soloshmz.com']
|
10
|
+
gem.description = 'A powerful Ruby configuration system.'
|
11
|
+
gem.summary = 'A powerful Ruby configuration system.'
|
12
|
+
gem.homepage = 'https://github.com/shi-tak/configatronn'
|
13
|
+
gem.license = 'MIT'
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ['lib']
|
19
|
+
|
20
|
+
gem.add_development_dependency 'minitest', '>=5.2.3'
|
21
|
+
gem.add_development_dependency 'mocha'
|
22
|
+
gem.add_development_dependency 'rake'
|
23
|
+
gem.add_development_dependency 'rubocop'
|
24
|
+
gem.add_development_dependency 'rubocop-minitest'
|
25
|
+
gem.add_development_dependency 'rubocop-performance'
|
26
|
+
gem.add_development_dependency 'rubocop-rake'
|
27
|
+
gem.add_development_dependency 'subprocess'
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Include in a minitest to restore the global configatron object to
|
2
|
+
# its global state afterwards. Particularly useful if you'd like to test
|
3
|
+
# your application with various config settings.
|
4
|
+
#
|
5
|
+
# ```ruby
|
6
|
+
# class Test::Suite < Minitest::Unit
|
7
|
+
# include Configatron::Integrations::Minitest
|
8
|
+
#
|
9
|
+
# it 'works' do
|
10
|
+
# configatron.unlock! do
|
11
|
+
# configatron.some.setting = true
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# [...]
|
15
|
+
# end
|
16
|
+
# ```
|
17
|
+
module Configatron::Integrations
|
18
|
+
module Minitest
|
19
|
+
def before_setup
|
20
|
+
configatron.temp_start
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def before_teardown
|
25
|
+
super
|
26
|
+
configatron.temp_end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Configatron::Integrations
|
2
|
+
# Helpful for making using configatron with Rails even easier!
|
3
|
+
#
|
4
|
+
# To get started you can use the generator to generate
|
5
|
+
# the necessary stub files.
|
6
|
+
#
|
7
|
+
# $ rails g configatron:install
|
8
|
+
module Rails
|
9
|
+
|
10
|
+
# Loads configatron files in the following order:
|
11
|
+
#
|
12
|
+
# Example:
|
13
|
+
# <Rails.root>/config/configatron/defaults.rb
|
14
|
+
# <Rails.root>/config/configatron/<Rails.env>.rb
|
15
|
+
# # optional:
|
16
|
+
# <Rails.root>/config/configatron/<Rails.env>/defaults.rb
|
17
|
+
# <Rails.root>/config/configatron/<Rails.env>/bar.rb
|
18
|
+
# <Rails.root>/config/configatron/<Rails.env>/foo.rb
|
19
|
+
def self.init(root = nil, env = nil)
|
20
|
+
base_dir = root
|
21
|
+
if root.nil?
|
22
|
+
root = defined?(::Rails) ? ::Rails.root : FileUtils.pwd
|
23
|
+
base_dir = File.expand_path(File.join(root, 'config', 'configatron'))
|
24
|
+
end
|
25
|
+
|
26
|
+
if env.nil?
|
27
|
+
env = defined?(::Rails) ? ::Rails.env : 'development'
|
28
|
+
end
|
29
|
+
|
30
|
+
config_files = []
|
31
|
+
|
32
|
+
config_files << File.join(base_dir, 'defaults.rb')
|
33
|
+
config_files << File.join(base_dir, "#{env}.rb")
|
34
|
+
|
35
|
+
env_dir = File.join(base_dir, env)
|
36
|
+
config_files << File.join(env_dir, 'defaults.rb')
|
37
|
+
|
38
|
+
Dir.glob(File.join(env_dir, '*.rb')).sort.each do |f|
|
39
|
+
config_files << f
|
40
|
+
end
|
41
|
+
|
42
|
+
config_files.collect! {|config| File.expand_path(config)}.uniq!
|
43
|
+
|
44
|
+
config_files.each do |config|
|
45
|
+
if File.exist?(config)
|
46
|
+
# puts "Configuration: #{config}"
|
47
|
+
require config
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end # Rails
|
53
|
+
end # Configatron
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class Configatron
|
2
|
+
|
3
|
+
class Proc
|
4
|
+
|
5
|
+
attr_accessor :execution_count
|
6
|
+
attr_accessor :block
|
7
|
+
|
8
|
+
def initialize(&block)
|
9
|
+
self.execution_count = 0
|
10
|
+
self.block = block
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
unless @val
|
15
|
+
val = self.block.call
|
16
|
+
self.execution_count += 1
|
17
|
+
if finalize?
|
18
|
+
@val = val
|
19
|
+
end
|
20
|
+
end
|
21
|
+
return val || @val
|
22
|
+
end
|
23
|
+
|
24
|
+
def finalize?
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
call.inspect
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|