configy 1.1.2 → 1.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/HISTORY.md +6 -1
- data/README.md +121 -30
- data/configy.gemspec +1 -1
- data/lib/configy.rb +5 -17
- data/lib/configy/base.rb +4 -0
- data/spec/load_path_spec.rb +4 -4
- data/spec/nested_config_spec.rb +2 -1
- data/spec/section_spec.rb +4 -13
- data/spec/spec_helper.rb +6 -0
- metadata +9 -10
data/Gemfile.lock
CHANGED
data/HISTORY.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
+
## 1.1.3 (2012-03-31)
|
2
|
+
|
3
|
+
* Allow hash access from main config object
|
4
|
+
* Check environment variables instead of constants
|
5
|
+
|
1
6
|
## 1.1.2 (2012-03-30)
|
2
7
|
|
3
|
-
* If CONFIGY_ENV is set, use that to determine config section to use.
|
8
|
+
* If ENV['CONFIGY_ENV'] is set, use that to determine config section to use.
|
4
9
|
|
5
10
|
## 1.1.1 (2012-03-18)
|
6
11
|
|
data/README.md
CHANGED
@@ -1,55 +1,146 @@
|
|
1
1
|
# Configy
|
2
2
|
|
3
|
-
|
3
|
+
Configy creates a config object based on a YAML file.
|
4
4
|
|
5
|
-
|
6
|
-
It should have a "common" section with all parameters along with default values and can also
|
7
|
-
contain a section for each of the rails environments (development, test, production, or
|
8
|
-
your custom one). The values from the current environment section will override the values in the
|
9
|
-
"common" section.
|
5
|
+
## Summary
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
and a section for each
|
7
|
+
It allows you to have a file (`config/app_config.yml`) with application
|
8
|
+
configuration parameters. It should have a "common" section with all
|
9
|
+
parameters along with default values and can also contain a section for each
|
10
|
+
application environment (development, test, production, or your custom one).
|
11
|
+
The values from the current environment section will override the values in
|
12
|
+
the "common" section.
|
14
13
|
|
15
|
-
|
16
|
-
|
14
|
+
If a developer needs his own specific values for his working copy, he can
|
15
|
+
simply create a `config/app_config.local.yml` file and override any value
|
16
|
+
there, again having a "common" section and a section for each environment.
|
17
17
|
|
18
|
-
|
18
|
+
The files are parsed with ERB. Configy also checks for file modifications so
|
19
|
+
you don't have to restart the server to pick up new values on production.
|
19
20
|
|
20
|
-
|
21
|
+
## Example
|
21
22
|
|
22
|
-
|
23
|
+
config/app_config.yaml:
|
24
|
+
|
25
|
+
``` yaml
|
26
|
+
common:
|
27
|
+
appname: "My App"
|
28
|
+
caching:
|
29
|
+
enabled: false
|
30
|
+
facebook:
|
31
|
+
appid: 123
|
32
|
+
secret: abc
|
33
|
+
|
34
|
+
production:
|
35
|
+
caching:
|
36
|
+
enabled: true
|
37
|
+
default_max_age: <%= 1.hour %>
|
38
|
+
facebook:
|
39
|
+
appid: 456
|
40
|
+
secret: def
|
41
|
+
|
42
|
+
```
|
43
|
+
|
44
|
+
Assuming ENV['RACK_ENV'] == "production"
|
45
|
+
|
46
|
+
``` ruby
|
47
|
+
Configy.create("app_config") # Creates AppConfig constant
|
48
|
+
AppConfig.caching.enabled? # => true
|
49
|
+
AppConfig.caching.default_max_age # => 3600
|
50
|
+
AppConfig.appname # => "My App"
|
51
|
+
AppConfig.facebook.appid # => 456
|
52
|
+
|
53
|
+
# Or with less magic:
|
54
|
+
|
55
|
+
config = Configy::Base.new("app_config", "production", Rails.root.join("config") )
|
56
|
+
config.caching.enabled? # => true
|
57
|
+
config['caching']['enabled'] # => true
|
58
|
+
...
|
59
|
+
|
60
|
+
```
|
61
|
+
|
62
|
+
## Features
|
63
|
+
|
64
|
+
### Sections
|
65
|
+
|
66
|
+
Configy assumes that you are breaking your configurations into sections. It
|
67
|
+
will automatically detect which section to use. It looks for an environment
|
68
|
+
variable in following order
|
69
|
+
|
70
|
+
`ENV['CONFIGY_ENV'], ENV['RAILS_ENV'], ENV['RACK_ENV']`
|
71
|
+
|
72
|
+
and assumes you have a section in your YAML file named the same way, for
|
73
|
+
example:
|
74
|
+
|
75
|
+
``` yaml
|
76
|
+
development:
|
77
|
+
facebook_app_id: 123456
|
78
|
+
facebook_secret: abcdef
|
79
|
+
production:
|
80
|
+
facebook_app_id: 456789
|
81
|
+
facebook_secret: defghi
|
82
|
+
```
|
83
|
+
|
84
|
+
If none of the environment variables above are set, it defaults to `development`.
|
85
|
+
|
86
|
+
### Common section
|
23
87
|
|
24
|
-
|
88
|
+
If you have a section named `common`, that section will provide default values
|
89
|
+
for all other sections. Under the hood, Configy deep merges the environment
|
90
|
+
section into the common section. For example:
|
25
91
|
|
26
92
|
``` yaml
|
27
93
|
common:
|
28
|
-
|
29
|
-
|
30
|
-
media_path: <%= RAILS_ROOT %>/tmp/media
|
94
|
+
newrelic_enabled: true
|
95
|
+
newrelic_key: "123456"
|
31
96
|
|
32
97
|
development:
|
33
|
-
|
98
|
+
newrelic_enabled: false
|
34
99
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
In an initializer:
|
100
|
+
staging:
|
101
|
+
|
102
|
+
production:
|
40
103
|
|
41
|
-
``` ruby
|
42
|
-
Configy.create(:app_config)
|
43
104
|
```
|
44
105
|
|
45
|
-
|
106
|
+
All environments will inherit the `common` section configurations, and the
|
107
|
+
`development` environment overrides the `newrelic_enabled` setting.
|
108
|
+
|
109
|
+
### Nested configs
|
110
|
+
|
111
|
+
You can nest configs as much as you like.
|
112
|
+
|
113
|
+
``` yaml
|
114
|
+
common:
|
115
|
+
facebook:
|
116
|
+
app:
|
117
|
+
id: 123
|
118
|
+
```
|
46
119
|
|
47
120
|
``` ruby
|
48
|
-
AppConfig.
|
121
|
+
AppConfig.facebook.app.id # => 123
|
49
122
|
```
|
50
123
|
|
51
|
-
|
52
|
-
|
124
|
+
### Local config file
|
125
|
+
|
126
|
+
If you have a config file named `config/app_config.yml` and another config
|
127
|
+
file named `config/app_config.local.yml`, the local config file's configurations
|
128
|
+
will override the main config file's configurations.
|
129
|
+
|
130
|
+
### ERB
|
131
|
+
|
132
|
+
Config files are parsed as ERB templates
|
133
|
+
|
134
|
+
### Auto reloading
|
135
|
+
|
136
|
+
Configy will check the config file's mtime to see if it needs to
|
137
|
+
reload it's configuration. You can disable this with `Configy.cache_config = true`
|
138
|
+
|
139
|
+
### Rails generator
|
140
|
+
|
141
|
+
Configy provides an [optional] generator.
|
142
|
+
|
143
|
+
rails g configy:install
|
53
144
|
|
54
145
|
## Authors
|
55
146
|
|
data/configy.gemspec
CHANGED
data/lib/configy.rb
CHANGED
@@ -14,29 +14,17 @@ module Configy
|
|
14
14
|
@load_path
|
15
15
|
elsif defined? Rails
|
16
16
|
Rails.root.join("config")
|
17
|
-
elsif
|
18
|
-
"#{RAILS_ROOT}/config"
|
19
|
-
elsif
|
20
|
-
"#{RACK_ROOT}/config"
|
17
|
+
elsif ENV['RAILS_ROOT']
|
18
|
+
"#{ENV['RAILS_ROOT']}/config"
|
19
|
+
elsif ENV['RACK_ROOT']
|
20
|
+
"#{ENV['RACK_ROOT']}/config"
|
21
21
|
else
|
22
22
|
'config'
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
def section
|
27
|
-
|
28
|
-
@section
|
29
|
-
elsif defined? CONFIGY_ENV
|
30
|
-
CONFIGY_ENV
|
31
|
-
elsif defined? Rails
|
32
|
-
Rails.env
|
33
|
-
elsif defined? RAILS_ENV
|
34
|
-
RAILS_ENV
|
35
|
-
elsif defined? RACK_ENV
|
36
|
-
RACK_ENV
|
37
|
-
else
|
38
|
-
'development'
|
39
|
-
end
|
27
|
+
@section ||= ENV["CONFIGY_ENV"] || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
|
40
28
|
end
|
41
29
|
|
42
30
|
def cache_config
|
data/lib/configy/base.rb
CHANGED
data/spec/load_path_spec.rb
CHANGED
@@ -19,14 +19,14 @@ describe "Configy.load_path" do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should detect rails 2 config dir" do
|
22
|
-
|
23
|
-
Configy.load_path.must_equal "#{RAILS_ROOT}/config"
|
22
|
+
with_env( "RAILS_ROOT", "path/to/rails/root" ) do
|
23
|
+
Configy.load_path.must_equal "#{ENV['RAILS_ROOT']}/config"
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should detect rack config dir" do
|
28
|
-
|
29
|
-
Configy.load_path.must_equal "#{RACK_ROOT}/config"
|
28
|
+
with_env( "RACK_ROOT", "path/to/rack/root" ) do
|
29
|
+
Configy.load_path.must_equal "#{ENV['RACK_ROOT']}/config"
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
data/spec/nested_config_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe Configy do
|
|
7
7
|
Configy.cache_config = nil
|
8
8
|
end
|
9
9
|
|
10
|
-
it "should be accessbile as methods" do
|
10
|
+
it "should be accessbile as methods or hashes" do
|
11
11
|
with_config_file({
|
12
12
|
'common' => {
|
13
13
|
'level1' => {
|
@@ -20,6 +20,7 @@ describe Configy do
|
|
20
20
|
}
|
21
21
|
}, 'nested_config') do
|
22
22
|
Configy.create('nested_config')
|
23
|
+
NestedConfig['level1']['level2']['level3'].must_equal "whynot"
|
23
24
|
NestedConfig.level1.level2.level3.must_equal "whynot"
|
24
25
|
NestedConfig.level1.level2.nokey?.must_equal false
|
25
26
|
NestedConfig.level1.level2.falsekey?.must_equal false
|
data/spec/section_spec.rb
CHANGED
@@ -10,28 +10,19 @@ describe "Configy.section" do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should detect configy environment" do
|
13
|
-
|
13
|
+
with_env( "CONFIGY_ENV", "staging" ) do
|
14
14
|
Configy.section.must_equal "staging"
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
it "should detect rails
|
19
|
-
|
20
|
-
rails3_obj.expect :env, "staging"
|
21
|
-
|
22
|
-
with_const(:Rails, rails3_obj) do
|
23
|
-
Configy.section.must_equal "staging"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should detect rails 2 environment" do
|
28
|
-
with_const( :RAILS_ENV, "test" ) do
|
18
|
+
it "should detect rails environment" do
|
19
|
+
with_env( "RAILS_ENV", "test" ) do
|
29
20
|
Configy.section.must_equal "test"
|
30
21
|
end
|
31
22
|
end
|
32
23
|
|
33
24
|
it "should detect rack environment" do
|
34
|
-
|
25
|
+
with_env( "RACK_ENV", "production" ) do
|
35
26
|
Configy.section.must_equal "production"
|
36
27
|
end
|
37
28
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,11 +13,11 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2012-03-18 00:00:00.
|
16
|
+
date: 2012-03-18 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: hashie
|
20
|
-
requirement: &
|
20
|
+
requirement: &70283820015920 !ruby/object:Gem::Requirement
|
21
21
|
none: false
|
22
22
|
requirements:
|
23
23
|
- - ~>
|
@@ -25,10 +25,10 @@ dependencies:
|
|
25
25
|
version: 1.2.0
|
26
26
|
type: :runtime
|
27
27
|
prerelease: false
|
28
|
-
version_requirements: *
|
28
|
+
version_requirements: *70283820015920
|
29
29
|
- !ruby/object:Gem::Dependency
|
30
30
|
name: bundler
|
31
|
-
requirement: &
|
31
|
+
requirement: &70283820015460 !ruby/object:Gem::Requirement
|
32
32
|
none: false
|
33
33
|
requirements:
|
34
34
|
- - ! '>='
|
@@ -36,10 +36,10 @@ dependencies:
|
|
36
36
|
version: 1.0.0
|
37
37
|
type: :development
|
38
38
|
prerelease: false
|
39
|
-
version_requirements: *
|
39
|
+
version_requirements: *70283820015460
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: minitest
|
42
|
-
requirement: &
|
42
|
+
requirement: &70283820015080 !ruby/object:Gem::Requirement
|
43
43
|
none: false
|
44
44
|
requirements:
|
45
45
|
- - ! '>='
|
@@ -47,7 +47,7 @@ dependencies:
|
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
|
-
version_requirements: *
|
50
|
+
version_requirements: *70283820015080
|
51
51
|
description:
|
52
52
|
email: bmarini@gmail.com
|
53
53
|
executables: []
|
@@ -104,9 +104,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
version: 1.3.6
|
105
105
|
requirements: []
|
106
106
|
rubyforge_project:
|
107
|
-
rubygems_version: 1.8.
|
107
|
+
rubygems_version: 1.8.11
|
108
108
|
signing_key:
|
109
109
|
specification_version: 3
|
110
110
|
summary: Simple yaml driven configuration gem
|
111
111
|
test_files: []
|
112
|
-
has_rdoc:
|