rails_config 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -107,6 +107,10 @@ Config entries are compiled from:
107
107
  config/settings.yml
108
108
  config/settings/#{environment}.yml
109
109
  config/environments/#{environment}.yml
110
+
111
+ config/settings.local.yml
112
+ config/settings/#{environment}.local.yml
113
+ config/environments/#{environment}.local.yml
110
114
 
111
115
  Settings defined in files that are lower in the list override settings higher.
112
116
 
@@ -145,6 +149,16 @@ Example production environment config file:
145
149
  #{Rails.root}/config/environments/production.yml
146
150
  ```
147
151
 
152
+ ### Developer specific config files
153
+
154
+ If you want to have local settings, specific to your machine or development environment,
155
+ you can use the following files, which are automatically `.gitignored` :
156
+
157
+ Rails.root.join("config", "settings.local.yml").to_s,
158
+ Rails.root.join("config", "settings", "#{Rails.env}.local.yml").to_s,
159
+ Rails.root.join("config", "environments", "#{Rails.env}.local.yml").to_s
160
+
161
+
148
162
  ### Adding sources at Runtime
149
163
 
150
164
  You can add new YAML config files at runtime. Just use:
@@ -163,6 +177,9 @@ Settings.add_source!("#{Rails.root}/config/settings/local.yml")
163
177
  Settings.reload!
164
178
  ```
165
179
 
180
+ > Note: this is an example usage, it is easier to just use the default local files `settings.local.yml, settings/#{Rails.env}.local.yml and environments/#{Rails.env}.local.yml`
181
+ > for your developer specific settings.
182
+
166
183
  ## Embedded Ruby (ERB)
167
184
 
168
185
  Embedded Ruby is allowed in the configuration files. See examples below.
@@ -55,8 +55,8 @@ module RailsConfig
55
55
 
56
56
  def merge!(hash)
57
57
  current = to_hash
58
- DeepMerge.deep_merge!(current, hash.dup)
59
- marshal_load(__convert(hash).marshal_dump)
58
+ DeepMerge.deep_merge!(hash.dup, current)
59
+ marshal_load(__convert(current).marshal_dump)
60
60
  self
61
61
  end
62
62
 
@@ -77,6 +77,7 @@ module RailsConfig
77
77
  s = self.class.new
78
78
 
79
79
  h.each do |k, v|
80
+ k = k.to_s if !k.respond_to?(:to_sym) && k.respond_to?(:to_s)
80
81
  s.new_ostruct_member(k)
81
82
 
82
83
  if v.is_a?(Hash)
@@ -1,3 +1,3 @@
1
1
  module RailsConfig
2
- VERSION = '0.3.0'
3
- end
2
+ VERSION = '0.3.1'
3
+ end
@@ -1,2 +1,3 @@
1
1
  size: 1
2
2
  server: google.com
3
+ 1: "one"
@@ -4,15 +4,15 @@ describe RailsConfig do
4
4
 
5
5
  it "should load a basic config file" do
6
6
  config = RailsConfig.load_files(setting_path("settings.yml"))
7
- config.size.should == 1
8
- config.server.should == "google.com"
7
+ config.size.should eq 1
8
+ config.server.should eq "google.com"
9
9
  end
10
10
 
11
11
  it "should load 2 basic config files" do
12
12
  config = RailsConfig.load_files(setting_path("settings.yml"), setting_path("settings2.yml"))
13
- config.size.should == 1
14
- config.server.should == "google.com"
15
- config.another.should == "something"
13
+ config.size.should eq 1
14
+ config.server.should eq "google.com"
15
+ config.another.should eq "something"
16
16
  end
17
17
 
18
18
  it "should load empty config for a missing file path" do
@@ -50,20 +50,20 @@ describe RailsConfig do
50
50
  it "should allow overrides" do
51
51
  files = [setting_path("settings.yml"), setting_path("development.yml")]
52
52
  config = RailsConfig.load_files(files)
53
- config.server.should == "google.com"
54
- config.size.should == 2
53
+ config.server.should eq "google.com"
54
+ config.size.should eq 2
55
55
  end
56
56
 
57
57
  it "should allow full reload of the settings files" do
58
58
  files = [setting_path("settings.yml")]
59
59
  RailsConfig.load_and_set_settings(files)
60
- Settings.server.should == "google.com"
61
- Settings.size.should == 1
60
+ Settings.server.should eq "google.com"
61
+ Settings.size.should eq 1
62
62
 
63
63
  files = [setting_path("settings.yml"), setting_path("development.yml")]
64
64
  Settings.reload_from_files(files)
65
- Settings.server.should == "google.com"
66
- Settings.size.should == 2
65
+ Settings.server.should eq "google.com"
66
+ Settings.size.should eq 2
67
67
  end
68
68
 
69
69
  context "Nested Settings" do
@@ -72,12 +72,12 @@ describe RailsConfig do
72
72
  end
73
73
 
74
74
  it "should allow nested sections" do
75
- config.section.size.should == 3
75
+ config.section.size.should eq 3
76
76
  end
77
77
 
78
78
  it "should allow configuration collections (arrays)" do
79
- config.section.servers[0].name.should == "yahoo.com"
80
- config.section.servers[1].name.should == "amazon.com"
79
+ config.section.servers[0].name.should eq "yahoo.com"
80
+ config.section.servers[1].name.should eq "amazon.com"
81
81
  end
82
82
  end
83
83
 
@@ -87,12 +87,12 @@ describe RailsConfig do
87
87
  end
88
88
 
89
89
  it "should evaluate ERB tags" do
90
- config.computed.should == 6
90
+ config.computed.should eq 6
91
91
  end
92
92
 
93
93
  it "should evaluated nested ERB tags" do
94
- config.section.computed1.should == 1
95
- config.section.computed2.should == 2
94
+ config.section.computed1.should eq 1
95
+ config.section.computed2.should eq 2
96
96
  end
97
97
  end
98
98
 
@@ -103,13 +103,13 @@ describe RailsConfig do
103
103
  end
104
104
 
105
105
  it "should merge hashes from multiple configs" do
106
- config.inner.marshal_dump.keys.size.should == 3
107
- config.inner2.inner2_inner.marshal_dump.keys.size.should == 3
106
+ config.inner.marshal_dump.keys.size.should eq 3
107
+ config.inner2.inner2_inner.marshal_dump.keys.size.should eq 3
108
108
  end
109
109
 
110
110
  it "should merge arrays from multiple configs" do
111
- config.arraylist1.size.should == 6
112
- config.arraylist2.inner.size.should == 6
111
+ config.arraylist1.size.should eq 6
112
+ config.arraylist2.inner.size.should eq 6
113
113
  end
114
114
  end
115
115
 
@@ -120,19 +120,19 @@ describe RailsConfig do
120
120
  end
121
121
 
122
122
  it "should allow overriding of bool settings" do
123
- config.override_bool.should == false
124
- config.override_bool_opposite.should == true
123
+ config.override_bool.should eq false
124
+ config.override_bool_opposite.should eq true
125
125
  end
126
126
  end
127
127
 
128
128
  context "Custom Configuration" do
129
129
  it "should have the default settings constant as 'Settings'" do
130
- RailsConfig.const_name.should == "Settings"
130
+ RailsConfig.const_name.should eq "Settings"
131
131
  end
132
132
 
133
133
  it "should be able to assign a different settings constant" do
134
134
  RailsConfig.setup{ |config| config.const_name = "Settings2" }
135
- RailsConfig.const_name.should == "Settings2"
135
+ RailsConfig.const_name.should eq "Settings2"
136
136
  end
137
137
  end
138
138
 
@@ -147,19 +147,19 @@ describe RailsConfig do
147
147
  end
148
148
 
149
149
  it "should map the hash values correctly" do
150
- config.prices[1].should == 2.99
151
- config.prices[5].should == 9.99
152
- config.prices[15].should == 19.99
153
- config.prices[30].should == 29.99
150
+ config.prices[1].should eq 2.99
151
+ config.prices[5].should eq 9.99
152
+ config.prices[15].should eq 19.99
153
+ config.prices[30].should eq 29.99
154
154
  end
155
155
  end
156
156
 
157
157
  context "Merging hash at runtime" do
158
158
  let(:config) { RailsConfig.load_files(setting_path("settings.yml")) }
159
- let(:hash) { {:options => {:suboption => 'value'}} }
159
+ let(:hash) { {:options => {:suboption => 'value'}, :server => 'amazon.com'} }
160
160
 
161
161
  it 'should be chainable' do
162
- config.merge!({}).should === config
162
+ config.merge!({}).should eq config
163
163
  end
164
164
 
165
165
  it 'should preserve existing keys' do
@@ -168,7 +168,33 @@ describe RailsConfig do
168
168
 
169
169
  it 'should recursively merge keys' do
170
170
  config.merge!(hash)
171
- config.options.suboption.should == 'value'
171
+ config.options.suboption.should eq 'value'
172
+ end
173
+
174
+ it 'should rewrite a merged value' do
175
+ expect { config.merge!(hash) }.to change{ config.server }.from('google.com').to('amazon.com')
176
+ end
177
+ end
178
+
179
+ context "Merging nested hash at runtime" do
180
+ let(:config) { RailsConfig.load_files(setting_path("deep_merge/config1.yml")) }
181
+ let(:hash) { {:inner => {:something1 => 'changed1', :something3 => 'changed3'} } }
182
+
183
+ it 'should preserve first level keys' do
184
+ expect { config.merge!(hash) }.to_not change{ config.keys }
185
+ end
186
+
187
+ it 'should preserve nested key' do
188
+ config.merge!(hash)
189
+ config.inner.something2.should eq 'blah2'
190
+ end
191
+
192
+ it 'should add new nested key' do
193
+ expect { config.merge!(hash) }.to change { config.inner.something3 }.from(nil).to("changed3")
194
+ end
195
+
196
+ it 'should rewrite a merged value' do
197
+ expect { config.merge!(hash) }.to change{ config.inner.something1 }.from('blah1').to('changed1')
172
198
  end
173
199
  end
174
200
 
@@ -179,14 +205,14 @@ describe RailsConfig do
179
205
  end
180
206
 
181
207
  it "should access attributes using []" do
182
- config.section['size'].should == 3
183
- config.section[:size].should == 3
184
- config[:section][:size].should == 3
208
+ config.section['size'].should eq 3
209
+ config.section[:size].should eq 3
210
+ config[:section][:size].should eq 3
185
211
  end
186
212
 
187
213
  it "should set values using []=" do
188
214
  config.section[:foo] = 'bar'
189
- config.section.foo.should == 'bar'
215
+ config.section.foo.should eq 'bar'
190
216
  end
191
217
  end
192
218
  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.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-05-09 00:00:00.000000000 Z
13
+ date: 2012-07-06 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -155,15 +155,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
155
  - - ! '>='
156
156
  - !ruby/object:Gem::Version
157
157
  version: '0'
158
+ segments:
159
+ - 0
160
+ hash: 128564019799295977
158
161
  required_rubygems_version: !ruby/object:Gem::Requirement
159
162
  none: false
160
163
  requirements:
161
164
  - - ! '>='
162
165
  - !ruby/object:Gem::Version
163
166
  version: '0'
167
+ segments:
168
+ - 0
169
+ hash: 128564019799295977
164
170
  requirements: []
165
171
  rubyforge_project:
166
- rubygems_version: 1.8.21
172
+ rubygems_version: 1.8.24
167
173
  signing_key:
168
174
  specification_version: 3
169
175
  summary: Provides a Settings helper for rails3 that reads from config/settings.yml