rails_config 0.2.5 → 0.2.6
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.
- data/README.md +73 -38
- data/lib/rails_config/integration/rails.rb +2 -2
- data/lib/rails_config/options.rb +7 -0
- data/lib/rails_config/version.rb +1 -1
- data/spec/rails_config_spec.rb +17 -0
- metadata +19 -13
data/README.md
CHANGED
|
@@ -13,7 +13,7 @@ RailsConfig helps you easily manage environment specific Rails settings in an ea
|
|
|
13
13
|
|
|
14
14
|
## Compatibility
|
|
15
15
|
|
|
16
|
-
* Rails 3.
|
|
16
|
+
* Rails 3.x
|
|
17
17
|
* Padrino
|
|
18
18
|
* Sinatra
|
|
19
19
|
|
|
@@ -23,35 +23,44 @@ For older versions of Rails and other Ruby apps, use [AppConfig](http://github.c
|
|
|
23
23
|
|
|
24
24
|
Add this to your `Gemfile`:
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
```ruby
|
|
27
|
+
gem "rails_config"
|
|
28
|
+
```
|
|
28
29
|
|
|
29
30
|
## Installing on Padrino
|
|
30
31
|
|
|
31
32
|
Add this to your `Gemfile`:
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
```ruby
|
|
35
|
+
gem "rails_config"
|
|
36
|
+
```
|
|
34
37
|
|
|
35
38
|
in your app.rb, you'll also need to register RailsConfig
|
|
36
39
|
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
```ruby
|
|
41
|
+
register RailsConfig
|
|
42
|
+
```
|
|
39
43
|
|
|
40
44
|
## Installing on Sinatra
|
|
41
45
|
|
|
42
46
|
Add this to your `Gemfile`:
|
|
43
47
|
|
|
44
|
-
|
|
48
|
+
```ruby
|
|
49
|
+
gem "rails_config"
|
|
50
|
+
```
|
|
45
51
|
|
|
46
52
|
in your app, you'll need to register RailsConfig. You'll also need to give it a root so it can find the config files.
|
|
47
53
|
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
```ruby
|
|
55
|
+
set :root, File.dirname(__FILE__)
|
|
56
|
+
register RailsConfig
|
|
57
|
+
```
|
|
50
58
|
|
|
51
59
|
It's also possible to initialize it manually within your configure block if you want to just give it some yml paths to load from.
|
|
52
60
|
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
```ruby
|
|
62
|
+
RailsConfig.load_and_set_settings("/path/to/yaml1", "/path/to/yaml2", ...)
|
|
63
|
+
```
|
|
55
64
|
|
|
56
65
|
## Customizing RailsConfig
|
|
57
66
|
|
|
@@ -70,11 +79,15 @@ This will generate `config/initializers/rails_config.rb` with a set of default s
|
|
|
70
79
|
|
|
71
80
|
After installing this plugin, the `Settings` object will be available globally. Entries are accessed via object member notation:
|
|
72
81
|
|
|
73
|
-
|
|
82
|
+
```ruby
|
|
83
|
+
Settings.my_config_entry
|
|
84
|
+
```
|
|
74
85
|
|
|
75
86
|
Nested entries are supported:
|
|
76
87
|
|
|
77
|
-
|
|
88
|
+
```ruby
|
|
89
|
+
Settings.my_section.some_entry
|
|
90
|
+
```
|
|
78
91
|
|
|
79
92
|
If you have set a different constant name for the object in the initializer file, use that instead.
|
|
80
93
|
|
|
@@ -98,12 +111,14 @@ You can also reload the `Settings` object from different config files at runtime
|
|
|
98
111
|
|
|
99
112
|
For example, in your tests if you want to test the production settings, you can:
|
|
100
113
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
114
|
+
```ruby
|
|
115
|
+
Rails.env = "production"
|
|
116
|
+
Settings.reload_from_files(
|
|
117
|
+
Rails.root.join("config", "settings.yml").to_s,
|
|
118
|
+
Rails.root.join("config", "settings", "#{Rails.env}.yml").to_s,
|
|
119
|
+
Rails.root.join("config", "environments", "#{Rails.env}.yml").to_s
|
|
120
|
+
)
|
|
121
|
+
```
|
|
107
122
|
|
|
108
123
|
### Environment specific config files
|
|
109
124
|
|
|
@@ -111,25 +126,33 @@ You can have environment specific config files. Environment specific config entr
|
|
|
111
126
|
|
|
112
127
|
Example development environment config file:
|
|
113
128
|
|
|
114
|
-
|
|
129
|
+
```ruby
|
|
130
|
+
#{Rails.root}/config/environments/development.yml
|
|
131
|
+
```
|
|
115
132
|
|
|
116
133
|
Example production environment config file:
|
|
117
134
|
|
|
118
|
-
|
|
135
|
+
```ruby
|
|
136
|
+
#{Rails.root}/config/environments/production.yml
|
|
137
|
+
```
|
|
119
138
|
|
|
120
139
|
### Adding sources at Runtime
|
|
121
140
|
|
|
122
141
|
You can add new YAML config files at runtime. Just use:
|
|
123
142
|
|
|
124
|
-
|
|
125
|
-
|
|
143
|
+
```ruby
|
|
144
|
+
Settings.add_source!("/path/to/source.yml")
|
|
145
|
+
Settings.reload!
|
|
146
|
+
```
|
|
126
147
|
|
|
127
148
|
This will use the given source.yml file and use its settings to overwrite any previous ones.
|
|
128
149
|
|
|
129
150
|
One thing I like to do for my Rails projects is provide a local.yml config file that is .gitignored (so its independent per developer). Then I create a new initializer in `config/initializers/add_local_config.rb` with the contents
|
|
130
151
|
|
|
131
|
-
|
|
132
|
-
|
|
152
|
+
```ruby
|
|
153
|
+
Settings.add_source!("#{Rails.root}/config/settings/local.yml")
|
|
154
|
+
Settings.reload!
|
|
155
|
+
```
|
|
133
156
|
|
|
134
157
|
## Embedded Ruby (ERB)
|
|
135
158
|
|
|
@@ -141,34 +164,46 @@ Consider the two following config files.
|
|
|
141
164
|
|
|
142
165
|
#{Rails.root}/config/settings.yml:
|
|
143
166
|
|
|
144
|
-
|
|
145
|
-
|
|
167
|
+
```yaml
|
|
168
|
+
size: 1
|
|
169
|
+
server: google.com
|
|
170
|
+
```
|
|
146
171
|
|
|
147
172
|
#{Rails.root}/config/environments/development.yml:
|
|
148
173
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
174
|
+
```yaml
|
|
175
|
+
size: 2
|
|
176
|
+
computed: <%= 1 + 2 + 3 %>
|
|
177
|
+
section:
|
|
178
|
+
size: 3
|
|
179
|
+
servers: [ {name: yahoo.com}, {name: amazon.com} ]
|
|
180
|
+
```
|
|
154
181
|
|
|
155
182
|
Notice that the environment specific config entries overwrite the common entries.
|
|
156
183
|
|
|
157
|
-
|
|
158
|
-
|
|
184
|
+
```ruby
|
|
185
|
+
Settings.size # => 2
|
|
186
|
+
Settings.server # => google.com
|
|
187
|
+
```
|
|
159
188
|
|
|
160
189
|
Notice the embedded Ruby.
|
|
161
190
|
|
|
162
|
-
|
|
191
|
+
```ruby
|
|
192
|
+
Settings.computed # => 6
|
|
193
|
+
```
|
|
163
194
|
|
|
164
195
|
Notice that object member notation is maintained even in nested entries.
|
|
165
196
|
|
|
166
|
-
|
|
197
|
+
```ruby
|
|
198
|
+
Settings.section.size # => 3
|
|
199
|
+
```
|
|
167
200
|
|
|
168
201
|
Notice array notation and object member notation is maintained.
|
|
169
202
|
|
|
170
|
-
|
|
171
|
-
|
|
203
|
+
```ruby
|
|
204
|
+
Settings.section.servers[0].name # => yahoo.com
|
|
205
|
+
Settings.section.servers[1].name # => amazon.com
|
|
206
|
+
```
|
|
172
207
|
|
|
173
208
|
## Authors
|
|
174
209
|
|
|
@@ -6,12 +6,12 @@ module RailsConfig
|
|
|
6
6
|
|
|
7
7
|
# manually load the custom initializer before everything else
|
|
8
8
|
initializer :load_custom_rails_config, :before => :bootstrap_hook do
|
|
9
|
-
initializer = Rails.root.join("config", "initializers", "rails_config")
|
|
9
|
+
initializer = Rails.root.join("config", "initializers", "rails_config.rb")
|
|
10
10
|
require initializer if File.exist?(initializer)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
# Parse the settings before any of the initializers
|
|
14
|
-
|
|
14
|
+
initializer :load_rails_config_settings, :after => :load_custom_rails_config do
|
|
15
15
|
RailsConfig.load_and_set_settings(
|
|
16
16
|
Rails.root.join("config", "settings.yml").to_s,
|
|
17
17
|
Rails.root.join("config", "settings", "#{Rails.env}.yml").to_s,
|
data/lib/rails_config/options.rb
CHANGED
|
@@ -53,6 +53,13 @@ module RailsConfig
|
|
|
53
53
|
to_hash.to_json(*args)
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
+
def merge!(hash)
|
|
57
|
+
current = to_hash
|
|
58
|
+
DeepMerge.deep_merge!(current, hash.dup)
|
|
59
|
+
marshal_load(__convert(hash).marshal_dump)
|
|
60
|
+
self
|
|
61
|
+
end
|
|
62
|
+
|
|
56
63
|
protected
|
|
57
64
|
|
|
58
65
|
# Recursively converts Hashes to Options (including Hashes inside Arrays)
|
data/lib/rails_config/version.rb
CHANGED
data/spec/rails_config_spec.rb
CHANGED
|
@@ -154,4 +154,21 @@ describe RailsConfig do
|
|
|
154
154
|
end
|
|
155
155
|
end
|
|
156
156
|
|
|
157
|
+
context "Merging hash at runtime" do
|
|
158
|
+
let(:config) { RailsConfig.load_files(setting_path("settings.yml")) }
|
|
159
|
+
let(:hash) { {:options => {:suboption => 'value'}} }
|
|
160
|
+
|
|
161
|
+
it 'should be chainable' do
|
|
162
|
+
config.merge!({}).should === config
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
it 'should preserve existing keys' do
|
|
166
|
+
expect { config.merge!({}) }.to_not change{ config.keys }
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it 'should recursively merge keys' do
|
|
170
|
+
config.merge!(hash)
|
|
171
|
+
config.options.suboption.should == 'value'
|
|
172
|
+
end
|
|
173
|
+
end
|
|
157
174
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rails_config
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.6
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -10,11 +10,11 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2012-03-15 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: activesupport
|
|
17
|
-
requirement: &
|
|
17
|
+
requirement: &70284216610960 !ruby/object:Gem::Requirement
|
|
18
18
|
none: false
|
|
19
19
|
requirements:
|
|
20
20
|
- - ! '>='
|
|
@@ -22,10 +22,10 @@ dependencies:
|
|
|
22
22
|
version: '3.0'
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
|
-
version_requirements: *
|
|
25
|
+
version_requirements: *70284216610960
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: rake
|
|
28
|
-
requirement: &
|
|
28
|
+
requirement: &70284216610240 !ruby/object:Gem::Requirement
|
|
29
29
|
none: false
|
|
30
30
|
requirements:
|
|
31
31
|
- - ! '>='
|
|
@@ -33,10 +33,10 @@ dependencies:
|
|
|
33
33
|
version: '0'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
|
-
version_requirements: *
|
|
36
|
+
version_requirements: *70284216610240
|
|
37
37
|
- !ruby/object:Gem::Dependency
|
|
38
38
|
name: rspec
|
|
39
|
-
requirement: &
|
|
39
|
+
requirement: &70284216609340 !ruby/object:Gem::Requirement
|
|
40
40
|
none: false
|
|
41
41
|
requirements:
|
|
42
42
|
- - ~>
|
|
@@ -44,10 +44,10 @@ dependencies:
|
|
|
44
44
|
version: '2.0'
|
|
45
45
|
type: :development
|
|
46
46
|
prerelease: false
|
|
47
|
-
version_requirements: *
|
|
47
|
+
version_requirements: *70284216609340
|
|
48
48
|
- !ruby/object:Gem::Dependency
|
|
49
49
|
name: autotest
|
|
50
|
-
requirement: &
|
|
50
|
+
requirement: &70284216608320 !ruby/object:Gem::Requirement
|
|
51
51
|
none: false
|
|
52
52
|
requirements:
|
|
53
53
|
- - ! '>='
|
|
@@ -55,10 +55,10 @@ dependencies:
|
|
|
55
55
|
version: '0'
|
|
56
56
|
type: :development
|
|
57
57
|
prerelease: false
|
|
58
|
-
version_requirements: *
|
|
58
|
+
version_requirements: *70284216608320
|
|
59
59
|
- !ruby/object:Gem::Dependency
|
|
60
60
|
name: growl-glue
|
|
61
|
-
requirement: &
|
|
61
|
+
requirement: &70284216607660 !ruby/object:Gem::Requirement
|
|
62
62
|
none: false
|
|
63
63
|
requirements:
|
|
64
64
|
- - ! '>='
|
|
@@ -66,7 +66,7 @@ dependencies:
|
|
|
66
66
|
version: '0'
|
|
67
67
|
type: :development
|
|
68
68
|
prerelease: false
|
|
69
|
-
version_requirements: *
|
|
69
|
+
version_requirements: *70284216607660
|
|
70
70
|
description: Easy to use Settings helper that loads its data in from config/settings.yml.
|
|
71
71
|
Handles adding multiple sources, and easy reloading.
|
|
72
72
|
email:
|
|
@@ -130,15 +130,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
130
130
|
- - ! '>='
|
|
131
131
|
- !ruby/object:Gem::Version
|
|
132
132
|
version: '0'
|
|
133
|
+
segments:
|
|
134
|
+
- 0
|
|
135
|
+
hash: 2569931913119763966
|
|
133
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
137
|
none: false
|
|
135
138
|
requirements:
|
|
136
139
|
- - ! '>='
|
|
137
140
|
- !ruby/object:Gem::Version
|
|
138
141
|
version: '0'
|
|
142
|
+
segments:
|
|
143
|
+
- 0
|
|
144
|
+
hash: 2569931913119763966
|
|
139
145
|
requirements: []
|
|
140
146
|
rubyforge_project:
|
|
141
|
-
rubygems_version: 1.8.
|
|
147
|
+
rubygems_version: 1.8.17
|
|
142
148
|
signing_key:
|
|
143
149
|
specification_version: 3
|
|
144
150
|
summary: Provides a Settings helper for rails3 that reads from config/settings.yml
|