rails_config 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -6
- data/Gemfile.lock +18 -21
- data/README.md +15 -2
- data/Rakefile +5 -3
- data/VERSION +1 -1
- data/lib/rails_config/options.rb +5 -4
- data/lib/rails_config/railtie.rb +1 -3
- data/lib/rails_config.rb +6 -6
- data/spec/rails_config_spec.rb +12 -0
- metadata +31 -13
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,32 +1,29 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rails_config (0.1.5)
|
5
|
+
activesupport (~> 3.0)
|
6
|
+
|
1
7
|
GEM
|
2
8
|
remote: http://rubygems.org/
|
3
9
|
specs:
|
4
|
-
activesupport (3.0.0
|
5
|
-
autotest (4.3.2)
|
6
|
-
columnize (0.3.1)
|
10
|
+
activesupport (3.0.0)
|
7
11
|
diff-lcs (1.1.2)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
rspec-
|
12
|
-
|
13
|
-
|
14
|
-
rspec-core (2.0.0.beta.19)
|
15
|
-
rspec-expectations (2.0.0.beta.19)
|
12
|
+
rspec (2.0.0)
|
13
|
+
rspec-core (= 2.0.0)
|
14
|
+
rspec-expectations (= 2.0.0)
|
15
|
+
rspec-mocks (= 2.0.0)
|
16
|
+
rspec-core (2.0.0)
|
17
|
+
rspec-expectations (2.0.0)
|
16
18
|
diff-lcs (>= 1.1.2)
|
17
|
-
rspec-mocks (2.0.0
|
18
|
-
|
19
|
-
|
20
|
-
ruby-debug-base (~> 0.10.3.0)
|
21
|
-
ruby-debug-base (0.10.3)
|
22
|
-
linecache (>= 0.3)
|
19
|
+
rspec-mocks (2.0.0)
|
20
|
+
rspec-core (= 2.0.0)
|
21
|
+
rspec-expectations (= 2.0.0)
|
23
22
|
|
24
23
|
PLATFORMS
|
25
24
|
ruby
|
26
25
|
|
27
26
|
DEPENDENCIES
|
28
|
-
activesupport (
|
29
|
-
|
30
|
-
growl-glue
|
27
|
+
activesupport (~> 3.0)
|
28
|
+
rails_config!
|
31
29
|
rspec (>= 2.0.0.beta.19)
|
32
|
-
ruby-debug
|
data/README.md
CHANGED
@@ -58,9 +58,22 @@ Config entries are compiled from
|
|
58
58
|
|
59
59
|
settings defined in files that are lower in the list override settings higher
|
60
60
|
|
61
|
-
### Reloading
|
61
|
+
### Reloading settings
|
62
62
|
|
63
|
-
You can reload the Settings
|
63
|
+
You can reload the Settings object at any time by running Settings.reload!
|
64
|
+
|
65
|
+
### Reloading settings and config files
|
66
|
+
|
67
|
+
You can also reload the Settings object from different config files at runtime.
|
68
|
+
|
69
|
+
For example, in your tests if you want to test the production settings, you can:
|
70
|
+
|
71
|
+
Rails.env = "production"
|
72
|
+
Settings.reload_from_files(
|
73
|
+
Rails.root.join("config", "settings.yml").to_s,
|
74
|
+
Rails.root.join("config", "settings", "#{Rails.env}.yml").to_s,
|
75
|
+
Rails.root.join("config", "environments", "#{Rails.env}.yml").to_s
|
76
|
+
)
|
64
77
|
|
65
78
|
### Environment specific config files
|
66
79
|
|
data/Rakefile
CHANGED
@@ -11,9 +11,11 @@ begin
|
|
11
11
|
s.email = ["railsjedi@gmail.com", "ifredwu@gmail.com"]
|
12
12
|
s.files = FileList["[A-Z]*", "{bin,generators,lib,spec}/**/*"]
|
13
13
|
|
14
|
-
s.add_dependency 'activesupport', "~>3.0"
|
15
|
-
s.add_development_dependency 'rspec', "
|
16
|
-
|
14
|
+
s.add_dependency 'activesupport', "~> 3.0"
|
15
|
+
s.add_development_dependency 'rspec', "~> 2.0"
|
16
|
+
s.add_development_dependency 'autotest'
|
17
|
+
s.add_development_dependency 'growl-glue'
|
18
|
+
s.add_development_dependency 'ruby-debug' if RUBY_VERSION < "1.9"
|
17
19
|
end
|
18
20
|
Jeweler::GemcutterTasks.new
|
19
21
|
rescue LoadError
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
data/lib/rails_config/options.rb
CHANGED
@@ -11,10 +11,6 @@ module RailsConfig
|
|
11
11
|
@config_sources << source
|
12
12
|
end
|
13
13
|
|
14
|
-
def load!
|
15
|
-
reload!
|
16
|
-
end
|
17
|
-
|
18
14
|
# look through all our sources and rebuild the configuration
|
19
15
|
def reload!
|
20
16
|
conf = {}
|
@@ -36,6 +32,11 @@ module RailsConfig
|
|
36
32
|
|
37
33
|
alias :load! :reload!
|
38
34
|
|
35
|
+
def reload_from_files(*files)
|
36
|
+
RailsConfig.load_and_set_settings(files)
|
37
|
+
reload!
|
38
|
+
end
|
39
|
+
|
39
40
|
protected
|
40
41
|
|
41
42
|
# Recursively converts Hashes to Options (including Hashes inside Arrays)
|
data/lib/rails_config/railtie.rb
CHANGED
@@ -10,13 +10,11 @@ if defined?(Rails::Railtie)
|
|
10
10
|
|
11
11
|
# Parse the settings before any of the initializers
|
12
12
|
ActiveSupport.on_load :before_initialize, :yield => true do
|
13
|
-
|
13
|
+
RailsConfig.load_and_set_settings(
|
14
14
|
Rails.root.join("config", "settings.yml").to_s,
|
15
15
|
Rails.root.join("config", "settings", "#{Rails.env}.yml").to_s,
|
16
16
|
Rails.root.join("config", "environments", "#{Rails.env}.yml").to_s
|
17
17
|
)
|
18
|
-
|
19
|
-
Kernel.const_set(RailsConfig.const_name, settings)
|
20
18
|
end
|
21
19
|
|
22
20
|
# Rails Dev environment should reload the Settings on every request
|
data/lib/rails_config.rb
CHANGED
@@ -17,11 +17,6 @@ module RailsConfig
|
|
17
17
|
@@_ran_once = true
|
18
18
|
end
|
19
19
|
|
20
|
-
@@load_paths = []
|
21
|
-
def self.load_paths
|
22
|
-
@@load_paths
|
23
|
-
end
|
24
|
-
|
25
20
|
# Create a populated Options instance from a yaml file. If a second yaml file is given, then the sections of that file will overwrite the sections
|
26
21
|
# if the first file if they exist in the first file.
|
27
22
|
def self.load_files(*files)
|
@@ -32,9 +27,14 @@ module RailsConfig
|
|
32
27
|
config.add_source!(Sources::YAMLSource.new(file))
|
33
28
|
end
|
34
29
|
config.load!
|
35
|
-
|
30
|
+
config
|
36
31
|
end
|
37
32
|
|
33
|
+
# Loads and sets the settings constant!
|
34
|
+
def self.load_and_set_settings(*files)
|
35
|
+
Kernel.send(:remove_const, RailsConfig.const_name) if Kernel.const_defined?(RailsConfig.const_name)
|
36
|
+
Kernel.const_set(RailsConfig.const_name, RailsConfig.load_files(files))
|
37
|
+
end
|
38
38
|
end
|
39
39
|
|
40
40
|
# add railtie
|
data/spec/rails_config_spec.rb
CHANGED
@@ -44,6 +44,18 @@ describe RailsConfig do
|
|
44
44
|
config.size.should == 2
|
45
45
|
end
|
46
46
|
|
47
|
+
it "should allow full reload of the settings files" do
|
48
|
+
files = [setting_path("settings.yml")]
|
49
|
+
RailsConfig.load_and_set_settings(files)
|
50
|
+
Settings.server.should == "google.com"
|
51
|
+
Settings.size.should == 1
|
52
|
+
|
53
|
+
files = [setting_path("settings.yml"), setting_path("development.yml")]
|
54
|
+
Settings.reload_from_files(files)
|
55
|
+
Settings.server.should == "google.com"
|
56
|
+
Settings.size.should == 2
|
57
|
+
end
|
58
|
+
|
47
59
|
context "Nested Settings" do
|
48
60
|
let(:config) do
|
49
61
|
RailsConfig.load_files(setting_path("development.yml"))
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 17
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
8
|
+
- 6
|
9
|
+
version: 0.1.6
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Jacques Crocker
|
@@ -16,7 +15,7 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date: 2010-
|
18
|
+
date: 2010-10-12 00:00:00 +11:00
|
20
19
|
default_executable:
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
@@ -27,7 +26,6 @@ dependencies:
|
|
27
26
|
requirements:
|
28
27
|
- - ~>
|
29
28
|
- !ruby/object:Gem::Version
|
30
|
-
hash: 7
|
31
29
|
segments:
|
32
30
|
- 3
|
33
31
|
- 0
|
@@ -40,18 +38,40 @@ dependencies:
|
|
40
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
40
|
requirements:
|
43
|
-
- -
|
41
|
+
- - ~>
|
44
42
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 62196421
|
46
43
|
segments:
|
47
44
|
- 2
|
48
45
|
- 0
|
49
|
-
|
50
|
-
- beta
|
51
|
-
- 19
|
52
|
-
version: 2.0.0.beta.19
|
46
|
+
version: "2.0"
|
53
47
|
type: :development
|
54
48
|
version_requirements: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: autotest
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: growl-glue
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
type: :development
|
74
|
+
version_requirements: *id004
|
55
75
|
description: Provides an easy to use Application Configuration object
|
56
76
|
email:
|
57
77
|
- railsjedi@gmail.com
|
@@ -113,7 +133,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
133
|
requirements:
|
114
134
|
- - ">="
|
115
135
|
- !ruby/object:Gem::Version
|
116
|
-
hash: 3
|
117
136
|
segments:
|
118
137
|
- 0
|
119
138
|
version: "0"
|
@@ -122,7 +141,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
141
|
requirements:
|
123
142
|
- - ">="
|
124
143
|
- !ruby/object:Gem::Version
|
125
|
-
hash: 3
|
126
144
|
segments:
|
127
145
|
- 0
|
128
146
|
version: "0"
|