ambience 1.0.0 → 2.0.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/.travis.yml +2 -1
- data/CHANGELOG.md +6 -0
- data/README.md +11 -10
- data/ambience.gemspec +3 -2
- data/lib/ambience/config.rb +27 -23
- data/lib/ambience/version.rb +1 -1
- data/spec/ambience/ambience_spec.rb +11 -6
- data/spec/fixtures/basic.yml +3 -3
- data/spec/fixtures/env_config.yml +4 -0
- data/spec/fixtures/environments.yml +2 -3
- data/spec/fixtures/symbols.yml +1 -1
- data/spec/spec_helper.rb +4 -0
- metadata +38 -22
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 2.0.0 (2011-11-04)
|
2
|
+
|
3
|
+
* Replaced the automatic loading of a user-local ambience.yml with an option to
|
4
|
+
load an app-specific config by providing a path to the additonal config via
|
5
|
+
an AMBIENCE_CONFIG environment variable.
|
6
|
+
|
1
7
|
== 1.0.0 (2011-06-15)
|
2
8
|
|
3
9
|
* Cleaned up the project's setup.
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
Ambience [](http://travis-ci.org/rubiii/ambience)
|
2
2
|
========
|
3
3
|
|
4
|
-
App configuration feat. YAML and JVM properties. Lets you specify a default configuration in a YAML
|
5
|
-
and overwrite details via local settings and JVM properties for production.
|
4
|
+
App configuration feat. YAML and JVM properties. Lets you specify a default configuration in a YAML
|
5
|
+
file and overwrite details via local settings and JVM properties for production.
|
6
6
|
|
7
7
|
|
8
8
|
Installation
|
@@ -18,7 +18,7 @@ $ gem install ambience
|
|
18
18
|
Getting started
|
19
19
|
---------------
|
20
20
|
|
21
|
-
|
21
|
+
Ambience expects your configuration to live inside a YAML file:
|
22
22
|
|
23
23
|
``` yml
|
24
24
|
auth:
|
@@ -27,20 +27,21 @@ auth:
|
|
27
27
|
password: test
|
28
28
|
```
|
29
29
|
|
30
|
-
You can
|
30
|
+
You can create a new Ambience config by passing in the path to your config file:
|
31
31
|
|
32
32
|
``` ruby
|
33
33
|
AppConfig = Ambience.create Rails.root.join("config", "ambience.yml")
|
34
34
|
```
|
35
35
|
|
36
|
-
Ambience
|
36
|
+
Ambience loads your config and converts it into a Hash:
|
37
37
|
|
38
38
|
``` ruby
|
39
39
|
{ "auth" => { "address" => "http://example.com", "username" => "ferris", "password" => "test" } }
|
40
40
|
```
|
41
41
|
|
42
|
-
Afterwards it tries to merge these settings with
|
43
|
-
|
42
|
+
Afterwards it tries to merge these settings with app-specific setting stored in a file which path is
|
43
|
+
provided through the AMBIENCE_CONFIG environment variable. Also, if you're using JRuby, Ambience will
|
44
|
+
merge all JVM properties with the config Hash:
|
44
45
|
|
45
46
|
``` ruby
|
46
47
|
auth.address = "http://live.example.com"
|
@@ -53,7 +54,7 @@ The result would be something like this:
|
|
53
54
|
{ "auth" => { "address" => "http://live.example.com", "username" => "ferris", "password" => "topsecret" } }
|
54
55
|
```
|
55
56
|
|
56
|
-
|
57
|
+
You can get the final config as a Hash:
|
57
58
|
|
58
59
|
``` ruby
|
59
60
|
AppConfig = Ambience.create(Rails.root.join("config", "ambience.yml")).to_hash
|
@@ -69,6 +70,6 @@ AppConfig = Ambience.create(Rails.root.join("config", "ambience.yml")).to_mash
|
|
69
70
|
Railtie
|
70
71
|
-------
|
71
72
|
|
72
|
-
Ambience comes with a Railtie which looks for `config/ambience.yml` inside your Rails project.
|
73
|
-
If the file exists, Ambience loads the config and stores it in an `AppConfig` constant.
|
73
|
+
Ambience comes with a Railtie which looks for `config/ambience.yml` inside your Rails project.
|
74
|
+
If the file exists, Ambience loads the config and stores it in an `AppConfig` constant.
|
74
75
|
All this happens before Rails evaluates your environment config.
|
data/ambience.gemspec
CHANGED
@@ -14,8 +14,9 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.add_dependency "hashie", ">= 0.2.0"
|
16
16
|
|
17
|
-
s.add_development_dependency "
|
18
|
-
s.add_development_dependency "
|
17
|
+
s.add_development_dependency "rake", "0.8.7"
|
18
|
+
s.add_development_dependency "rspec", "~> 2.6.0"
|
19
|
+
s.add_development_dependency "mocha", "~> 0.9.12"
|
19
20
|
s.add_development_dependency "autotest"
|
20
21
|
|
21
22
|
s.files = `git ls-files`.split("\n")
|
data/lib/ambience/config.rb
CHANGED
@@ -17,26 +17,28 @@ module Ambience
|
|
17
17
|
# in a YAML file and overwrite details via local settings and JVM properties for production.
|
18
18
|
class Config
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
class << self
|
21
|
+
|
22
|
+
def env_config
|
23
|
+
@env_config ||= "AMBIENCE_CONFIG"
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_writer :env_config
|
24
27
|
|
25
|
-
# Returns the path to a local ambience config file for specifying user-specific
|
26
|
-
# settings that don't belong into the application config file.
|
27
|
-
def self.local_config
|
28
|
-
@@local_config ||= File.join ENV["HOME"].to_s, ".ambience", "ambience.yml"
|
29
28
|
end
|
30
29
|
|
31
|
-
def initialize(
|
32
|
-
|
30
|
+
def initialize(base_config, env = nil)
|
31
|
+
self.base_config = base_config
|
32
|
+
self.env = env
|
33
33
|
end
|
34
34
|
|
35
|
+
attr_accessor :base_config, :env
|
36
|
+
|
35
37
|
# Returns the Ambience config as a Hash.
|
36
38
|
def to_hash
|
37
|
-
config =
|
38
|
-
config = config.deep_merge
|
39
|
-
config.deep_merge
|
39
|
+
config = load_base_config
|
40
|
+
config = config.deep_merge(load_env_config)
|
41
|
+
config.deep_merge(load_jvm_config)
|
40
42
|
end
|
41
43
|
|
42
44
|
# Returns the Ambience config as a Hashie::Mash.
|
@@ -46,28 +48,30 @@ module Ambience
|
|
46
48
|
|
47
49
|
private
|
48
50
|
|
51
|
+
def load_base_config
|
52
|
+
load_config base_config
|
53
|
+
end
|
54
|
+
|
55
|
+
def load_env_config
|
56
|
+
config = ENV[self.class.env_config]
|
57
|
+
config ? load_config(config) : {}
|
58
|
+
end
|
59
|
+
|
49
60
|
def load_config(config_file)
|
50
|
-
raise ArgumentError, "Missing config: #{config_file}" unless File.exist?
|
61
|
+
raise ArgumentError, "Missing config file: #{config_file}" unless File.exist?(config_file)
|
51
62
|
|
52
63
|
config = File.read config_file
|
53
64
|
config = YAML.load ERB.new(config).result || {}
|
54
|
-
config = config[
|
65
|
+
config = config[env.to_s] || config[env.to_sym] if env
|
55
66
|
config
|
56
67
|
end
|
57
68
|
|
58
|
-
|
59
|
-
def local_config
|
60
|
-
File.exist?(self.class.local_config) ? load_config(self.class.local_config) : {}
|
61
|
-
end
|
62
|
-
|
63
|
-
## Returns a Hash containing any JVM properties.
|
64
|
-
def jvm_config
|
69
|
+
def load_jvm_config
|
65
70
|
jvm_properties.inject({}) do |hash, (key, value)|
|
66
71
|
hash.deep_merge hash_from_property(key, value)
|
67
72
|
end
|
68
73
|
end
|
69
74
|
|
70
|
-
# Returns the JVM properties.
|
71
75
|
def jvm_properties
|
72
76
|
Ambience.jruby? ? java.lang.System.get_properties : {}
|
73
77
|
end
|
data/lib/ambience/version.rb
CHANGED
@@ -36,11 +36,12 @@ describe Ambience do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "raises an ArgumentError when the given config file could not be found" do
|
39
|
-
|
39
|
+
expect { Ambience.create("missing_config.yml").to_hash }.to raise_error(ArgumentError)
|
40
40
|
end
|
41
41
|
|
42
42
|
context "when using JRuby" do
|
43
43
|
before do
|
44
|
+
Ambience.stubs(:jruby?).returns(true)
|
44
45
|
Ambience::Config.send(:define_method, :java) { JavaMock }
|
45
46
|
end
|
46
47
|
|
@@ -49,11 +50,6 @@ describe Ambience do
|
|
49
50
|
end
|
50
51
|
|
51
52
|
it "merges the config with any JVM properties" do
|
52
|
-
Ambience.stubs(:jruby?).returns(true)
|
53
|
-
Ambience::Config.any_instance.stubs(:jvm_properties).returns(
|
54
|
-
"auth.address" => "http://live.example.com",
|
55
|
-
"auth.password" => "topsecret"
|
56
|
-
)
|
57
53
|
config = Ambience.create(config_file(:basic)).to_mash
|
58
54
|
|
59
55
|
config.should be_a(Hashie::Mash)
|
@@ -63,6 +59,15 @@ describe Ambience do
|
|
63
59
|
end
|
64
60
|
end
|
65
61
|
|
62
|
+
context "with an env config file" do
|
63
|
+
it "merges the config with the env config" do
|
64
|
+
ENV["AMBIENCE_CONFIG"] = config_file(:env_config)
|
65
|
+
config = Ambience.create(config_file(:basic)).to_mash
|
66
|
+
|
67
|
+
config.auth.address.should == "http://live.example.com"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
66
71
|
def config_file(name)
|
67
72
|
File.expand_path("../../fixtures/#{name}.yml", __FILE__)
|
68
73
|
end
|
data/spec/fixtures/basic.yml
CHANGED
data/spec/fixtures/symbols.yml
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ambience
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
9
|
- 0
|
10
|
-
version:
|
10
|
+
version: 2.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel Harrington
|
@@ -15,13 +15,10 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-11-04 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
-
prerelease: false
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
22
|
none: false
|
26
23
|
requirements:
|
27
24
|
- - ">="
|
@@ -32,12 +29,28 @@ dependencies:
|
|
32
29
|
- 2
|
33
30
|
- 0
|
34
31
|
version: 0.2.0
|
32
|
+
name: hashie
|
35
33
|
type: :runtime
|
36
|
-
|
34
|
+
prerelease: false
|
35
|
+
requirement: *id001
|
37
36
|
- !ruby/object:Gem::Dependency
|
38
|
-
|
37
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - "="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 49
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
- 8
|
46
|
+
- 7
|
47
|
+
version: 0.8.7
|
48
|
+
name: rake
|
49
|
+
type: :development
|
39
50
|
prerelease: false
|
40
|
-
requirement:
|
51
|
+
requirement: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
41
54
|
none: false
|
42
55
|
requirements:
|
43
56
|
- - ~>
|
@@ -48,12 +61,12 @@ dependencies:
|
|
48
61
|
- 6
|
49
62
|
- 0
|
50
63
|
version: 2.6.0
|
64
|
+
name: rspec
|
51
65
|
type: :development
|
52
|
-
version_requirements: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: mocha
|
55
66
|
prerelease: false
|
56
|
-
requirement:
|
67
|
+
requirement: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
57
70
|
none: false
|
58
71
|
requirements:
|
59
72
|
- - ~>
|
@@ -64,12 +77,12 @@ dependencies:
|
|
64
77
|
- 9
|
65
78
|
- 12
|
66
79
|
version: 0.9.12
|
80
|
+
name: mocha
|
67
81
|
type: :development
|
68
|
-
version_requirements: *id003
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: autotest
|
71
82
|
prerelease: false
|
72
|
-
requirement:
|
83
|
+
requirement: *id004
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
73
86
|
none: false
|
74
87
|
requirements:
|
75
88
|
- - ">="
|
@@ -78,8 +91,10 @@ dependencies:
|
|
78
91
|
segments:
|
79
92
|
- 0
|
80
93
|
version: "0"
|
94
|
+
name: autotest
|
81
95
|
type: :development
|
82
|
-
|
96
|
+
prerelease: false
|
97
|
+
requirement: *id005
|
83
98
|
description: App configuration feat. YAML and JVM properties
|
84
99
|
email: me@rubiii.com
|
85
100
|
executables: []
|
@@ -105,11 +120,11 @@ files:
|
|
105
120
|
- lib/ambience/version.rb
|
106
121
|
- spec/ambience/ambience_spec.rb
|
107
122
|
- spec/fixtures/basic.yml
|
123
|
+
- spec/fixtures/env_config.yml
|
108
124
|
- spec/fixtures/environments.yml
|
109
125
|
- spec/fixtures/symbols.yml
|
110
126
|
- spec/spec_helper.rb
|
111
127
|
- spec/support/java_mock.rb
|
112
|
-
has_rdoc: true
|
113
128
|
homepage: http://github.com/rubiii/ambience
|
114
129
|
licenses: []
|
115
130
|
|
@@ -139,13 +154,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
154
|
requirements: []
|
140
155
|
|
141
156
|
rubyforge_project: ambience
|
142
|
-
rubygems_version: 1.
|
157
|
+
rubygems_version: 1.8.6
|
143
158
|
signing_key:
|
144
159
|
specification_version: 3
|
145
160
|
summary: App configuration feat. YAML and JVM properties
|
146
161
|
test_files:
|
147
162
|
- spec/ambience/ambience_spec.rb
|
148
163
|
- spec/fixtures/basic.yml
|
164
|
+
- spec/fixtures/env_config.yml
|
149
165
|
- spec/fixtures/environments.yml
|
150
166
|
- spec/fixtures/symbols.yml
|
151
167
|
- spec/spec_helper.rb
|