rails_config 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -89,6 +89,15 @@ Nested entries are supported:
89
89
  Settings.my_section.some_entry
90
90
  ```
91
91
 
92
+ Alternatively, you can also use the `[]` operator if you don't know which exact setting you need to access ahead of time.
93
+
94
+ ```ruby
95
+ # All the following are equivalent to Settings.my_section.some_entry
96
+ Settings.my_section[:some_entry]
97
+ Settings.my_section['some_entry]
98
+ Settings[:my_section][:some_entry]
99
+ ```
100
+
92
101
  If you have set a different constant name for the object in the initializer file, use that instead.
93
102
 
94
103
  ## Common config file
@@ -5,13 +5,13 @@ module RailsConfig
5
5
  class Railtie < Rails::Railtie
6
6
 
7
7
  # manually load the custom initializer before everything else
8
- initializer :load_custom_rails_config, :before => :bootstrap_hook do
8
+ initializer :load_custom_rails_config, :before => :load_environment_config do
9
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
- initializer :load_rails_config_settings, :after => :load_custom_rails_config, :before => :bootstrap_hook do
14
+ initializer :load_rails_config_settings, :after => :load_custom_rails_config, :before => :load_environment_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,
@@ -59,6 +59,16 @@ module RailsConfig
59
59
  marshal_load(__convert(hash).marshal_dump)
60
60
  self
61
61
  end
62
+
63
+ # An alternative mechanism for property access.
64
+ # This let's you do foo['bar'] along with foo.bar.
65
+ def [](param)
66
+ send("#{param}")
67
+ end
68
+
69
+ def []=(param, value)
70
+ send("#{param}=", value)
71
+ end
62
72
 
63
73
  protected
64
74
 
@@ -1,3 +1,3 @@
1
1
  module RailsConfig
2
- VERSION = '0.2.7'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -171,4 +171,22 @@ describe RailsConfig do
171
171
  config.options.suboption.should == 'value'
172
172
  end
173
173
  end
174
+
175
+ context "[] accessors" do
176
+ let(:config) do
177
+ files = [setting_path("development.yml")]
178
+ RailsConfig.load_files(files)
179
+ end
180
+
181
+ it "should access attributes using []" do
182
+ config.section['size'].should == 3
183
+ config.section[:size].should == 3
184
+ config[:section][:size].should == 3
185
+ end
186
+
187
+ it "should set values using []=" do
188
+ config.section[:foo] = 'bar'
189
+ config.section.foo.should == 'bar'
190
+ end
191
+ end
174
192
  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.7
4
+ version: 0.3.0
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: 2012-03-16 00:00:00.000000000Z
13
+ date: 2012-05-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &70228181862460 !ruby/object:Gem::Requirement
17
+ requirement: !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,15 @@ dependencies:
22
22
  version: '3.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70228181862460
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '3.0'
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: rake
28
- requirement: &70228181862040 !ruby/object:Gem::Requirement
33
+ requirement: !ruby/object:Gem::Requirement
29
34
  none: false
30
35
  requirements:
31
36
  - - ! '>='
@@ -33,10 +38,15 @@ dependencies:
33
38
  version: '0'
34
39
  type: :development
35
40
  prerelease: false
36
- version_requirements: *70228181862040
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: rspec
39
- requirement: &70228181861500 !ruby/object:Gem::Requirement
49
+ requirement: !ruby/object:Gem::Requirement
40
50
  none: false
41
51
  requirements:
42
52
  - - ~>
@@ -44,10 +54,15 @@ dependencies:
44
54
  version: '2.0'
45
55
  type: :development
46
56
  prerelease: false
47
- version_requirements: *70228181861500
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '2.0'
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: autotest
50
- requirement: &70228181861000 !ruby/object:Gem::Requirement
65
+ requirement: !ruby/object:Gem::Requirement
51
66
  none: false
52
67
  requirements:
53
68
  - - ! '>='
@@ -55,10 +70,15 @@ dependencies:
55
70
  version: '0'
56
71
  type: :development
57
72
  prerelease: false
58
- version_requirements: *70228181861000
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
59
79
  - !ruby/object:Gem::Dependency
60
80
  name: growl-glue
61
- requirement: &70228181860540 !ruby/object:Gem::Requirement
81
+ requirement: !ruby/object:Gem::Requirement
62
82
  none: false
63
83
  requirements:
64
84
  - - ! '>='
@@ -66,7 +86,12 @@ dependencies:
66
86
  version: '0'
67
87
  type: :development
68
88
  prerelease: false
69
- version_requirements: *70228181860540
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
70
95
  description: Easy to use Settings helper that loads its data in from config/settings.yml.
71
96
  Handles adding multiple sources, and easy reloading.
72
97
  email:
@@ -138,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
163
  version: '0'
139
164
  requirements: []
140
165
  rubyforge_project:
141
- rubygems_version: 1.8.17
166
+ rubygems_version: 1.8.21
142
167
  signing_key:
143
168
  specification_version: 3
144
169
  summary: Provides a Settings helper for rails3 that reads from config/settings.yml