cjbottaro-app_config 1.0.1 → 1.1.0
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/CHANGELOG +7 -1
- data/README.rdoc +30 -0
- data/VERSION.yml +2 -2
- data/app_config.gemspec +3 -2
- data/lib/app_config.rb +8 -0
- data/test/app_config_test.rb +14 -0
- data/test/environments.yml +17 -0
- metadata +3 -2
data/CHANGELOG
CHANGED
@@ -5,4 +5,10 @@
|
|
5
5
|
* Packaged as a gem (but still works as a Rails plugin).
|
6
6
|
* The app config object is now an instance of ApplicationConfiguration.
|
7
7
|
* NoMethodError raised if you try to access a config element that doesn't exist.
|
8
|
-
* ApplicationConfiguration#reload! to reread the config files and rebuild the app config object.
|
8
|
+
* ApplicationConfiguration#reload! to reread the config files and rebuild the app config object.
|
9
|
+
|
10
|
+
08/27/2009
|
11
|
+
* Updated the ClosedStruct class.
|
12
|
+
|
13
|
+
08/28/2009
|
14
|
+
* Added support for "environments" in the YAML files.
|
data/README.rdoc
CHANGED
@@ -55,5 +55,35 @@ You just need to create an initializer that looks something like this.
|
|
55
55
|
If you installed this as a Rails plugin instead of a gem, that code is already run for you in
|
56
56
|
the plugin's init.rb.
|
57
57
|
|
58
|
+
=== Environments
|
59
|
+
|
60
|
+
Alternatively to splitting out your environments into separate files, you can just have a single file which defines
|
61
|
+
the application configuration for all environments (much like how databases.yml works). Note if you do this, nested
|
62
|
+
configurations will not be recursively merged. See example below.
|
63
|
+
|
64
|
+
<em>app_config.yml</em>
|
65
|
+
defaults: &defaults
|
66
|
+
one: won
|
67
|
+
two: too
|
68
|
+
nested:
|
69
|
+
foo: foo
|
70
|
+
bar: bar
|
71
|
+
|
72
|
+
development:
|
73
|
+
<<: *defaults
|
74
|
+
two: new
|
75
|
+
nested:
|
76
|
+
foo: bar
|
77
|
+
|
78
|
+
_code_
|
79
|
+
RAILS_ENV # => "development"
|
80
|
+
::AppConfig = ApplicationConfiguration.new("app_config.yml")
|
81
|
+
AppConfig.use_environment!(RAILS_ENV)
|
82
|
+
AppConfig.one # => "won"
|
83
|
+
AppConfig.two # => "new"
|
84
|
+
AppConfig.nested.foo # => "bar"
|
85
|
+
AppConfig.nested.bar # raises NoMethodError because nested configurations are not recursively merged
|
86
|
+
|
87
|
+
|
58
88
|
== Author
|
59
89
|
Christopher J. Bottaro
|
data/VERSION.yml
CHANGED
data/app_config.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{app_config}
|
8
|
-
s.version = "1.0
|
8
|
+
s.version = "1.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Christopher J Bottaro"]
|
12
|
-
s.date = %q{2009-08-
|
12
|
+
s.date = %q{2009-08-28}
|
13
13
|
s.description = %q{Application level configuration that supports YAML config file, inheritance, ERB, and object member notation.}
|
14
14
|
s.email = %q{cjbottaro@alumni.cs.utexas.edu}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
"test/development.yml",
|
33
33
|
"test/empty1.yml",
|
34
34
|
"test/empty2.yml",
|
35
|
+
"test/environments.yml",
|
35
36
|
"uninstall.rb"
|
36
37
|
]
|
37
38
|
s.homepage = %q{http://github.com/cjbottaro/app_config}
|
data/lib/app_config.rb
CHANGED
@@ -25,6 +25,14 @@ class ApplicationConfiguration
|
|
25
25
|
@config = ClosedStruct.r_new(conf)
|
26
26
|
end
|
27
27
|
|
28
|
+
def use_environment!(environment)
|
29
|
+
if @config.respond_to?(environment)
|
30
|
+
@config = @config.send(environment)
|
31
|
+
else
|
32
|
+
raise ArgumentError, "environment doesn't exist in app config: #{environment}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
28
36
|
private
|
29
37
|
|
30
38
|
def method_missing(name, *args)
|
data/test/app_config_test.rb
CHANGED
@@ -61,4 +61,18 @@ class AppConfigTest < Test::Unit::TestCase
|
|
61
61
|
assert_equal 1, config.size
|
62
62
|
end
|
63
63
|
|
64
|
+
def test_environments
|
65
|
+
config = ApplicationConfiguration.new('test/environments.yml')
|
66
|
+
config.use_environment!("development")
|
67
|
+
assert_equal 2, config.size
|
68
|
+
assert_equal "google.com", config.server
|
69
|
+
assert_equal 6, config.computed
|
70
|
+
assert_equal 3, config.section.size
|
71
|
+
assert_equal "yahoo.com", config.section.servers[0].name
|
72
|
+
assert_equal "amazon.com", config.section.servers[1].name
|
73
|
+
assert_equal "webmaster@domain.com", config.emails.webmaster
|
74
|
+
assert_equal "feedback@domain.com", config.emails.feedback
|
75
|
+
assert_raise(NoMethodError){ config.emails.support }
|
76
|
+
end
|
77
|
+
|
64
78
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
defaults: &defaults
|
2
|
+
size: 1
|
3
|
+
server: google.com
|
4
|
+
emails:
|
5
|
+
support: support@domain.com
|
6
|
+
webmaster: web@domain.com
|
7
|
+
|
8
|
+
development:
|
9
|
+
<<: *defaults
|
10
|
+
size: 2
|
11
|
+
computed: <%= 1 + 2 + 3 %>
|
12
|
+
section:
|
13
|
+
size: 3
|
14
|
+
servers: [ {name: yahoo.com}, {name: amazon.com} ]
|
15
|
+
emails:
|
16
|
+
webmaster: webmaster@domain.com
|
17
|
+
feedback: feedback@domain.com
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cjbottaro-app_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher J Bottaro
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-28 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- test/development.yml
|
39
39
|
- test/empty1.yml
|
40
40
|
- test/empty2.yml
|
41
|
+
- test/environments.yml
|
41
42
|
- uninstall.rb
|
42
43
|
has_rdoc: false
|
43
44
|
homepage: http://github.com/cjbottaro/app_config
|