conflate 0.0.1 → 0.0.2
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/README.markdown +33 -11
- data/lib/conflate/conflation.rb +8 -0
- data/lib/conflate/version.rb +1 -1
- data/spec/conflate/conflation_spec.rb +16 -1
- metadata +4 -4
data/README.markdown
CHANGED
@@ -6,23 +6,45 @@ Conflate
|
|
6
6
|
|
7
7
|
Load YAML files in your config directory into the Rails.application.config.
|
8
8
|
|
9
|
-
|
10
|
-
-------
|
9
|
+
If you're using Rails, you probably want to use [conflate-rails], which automatically loads YAML files from config/ into Rails.application.config.
|
11
10
|
|
12
|
-
|
11
|
+
Usage
|
12
|
+
-----
|
13
|
+
|
14
|
+
Let's suppose you have a file 'config/statsd.yml', with the following contents:
|
13
15
|
|
14
16
|
```yml
|
15
|
-
|
16
|
-
|
17
|
+
# statsd.yml
|
18
|
+
host: "localhost"
|
19
|
+
port: 8125
|
17
20
|
```
|
18
21
|
|
19
|
-
With Conflate, this information
|
22
|
+
With Conflate, load this information (and any other YAML file in your config directory) like so.
|
20
23
|
|
21
24
|
```ruby
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
# => "
|
25
|
+
settings = OpenStruct.new
|
26
|
+
Conflate::Conflator.new("config", settings).perform
|
27
|
+
settings.stats
|
28
|
+
# => {"host" => "localhost", "port" => 8125}
|
26
29
|
```
|
27
30
|
|
28
|
-
|
31
|
+
The [conflate-rails] gem does the following for you in a Rails app.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
Conflate::Conflator.new(Rails.root.join("config"), Rails.application.config).perform
|
35
|
+
Rails.application.config.statsd
|
36
|
+
# => {"host" => "localhost", "port" => 8125}
|
37
|
+
```
|
38
|
+
|
39
|
+
Around the Web
|
40
|
+
--------------
|
41
|
+
|
42
|
+
* [conflate on GitHub][conflate]
|
43
|
+
* [conflate on RubyGems][conflate-gem]
|
44
|
+
* [conflate-rails on GitHub][conflate-rails]
|
45
|
+
* [conflate-rails on RubyGems][conflate-rails-gem]
|
46
|
+
|
47
|
+
[conflate-rails]:https://github.com/sportngin/conflate-rails
|
48
|
+
[conflate-rails-gem]:https://rubygems.org/gems/conflate-rails
|
49
|
+
[conflate]:https://github.com/sportngin/conflate
|
50
|
+
[conflate-gem]:https://rubygems.org/gems/conflate
|
data/lib/conflate/conflation.rb
CHANGED
@@ -17,6 +17,14 @@ module Conflate
|
|
17
17
|
|
18
18
|
# Public: Add the contents of the YAML file to the config object
|
19
19
|
def apply
|
20
|
+
if config_object.respond_to?(name) && !config_object.public_send(name).nil?
|
21
|
+
# doing this to properly handle the slightly different behaviors of
|
22
|
+
# OpenStruct (which does respond to unassigned attributes) or the
|
23
|
+
# Rails.application.config object (which doesn't)
|
24
|
+
warn "#{name} already contains some information, so skipping conflating it with the contents of #{yaml_path}"
|
25
|
+
return # so don't set it
|
26
|
+
end
|
27
|
+
|
20
28
|
config_object.public_send "#{name}=", data
|
21
29
|
end
|
22
30
|
|
data/lib/conflate/version.rb
CHANGED
@@ -27,11 +27,25 @@ module Conflate
|
|
27
27
|
})
|
28
28
|
end
|
29
29
|
|
30
|
-
it "applies the values in the YAML file
|
30
|
+
it "applies the values in the YAML file if the config object does not have an attribute of that name" do
|
31
|
+
# bare stub object, so has no attributes, certainly not `subject.name`
|
31
32
|
config_object.should_receive("#{subject.name}=").with(subject.send(:data))
|
32
33
|
subject.apply
|
33
34
|
end
|
34
35
|
|
36
|
+
it "applies the values in the YAML file to the config object if it has the attribute but the value is nil" do
|
37
|
+
config_object.stub(subject.name) { nil }
|
38
|
+
config_object.should_receive("#{subject.name}=").with(subject.send(:data))
|
39
|
+
subject.apply
|
40
|
+
end
|
41
|
+
|
42
|
+
it "does not apply the value if the config object already has a value at that key" do
|
43
|
+
config_object.stub(subject.name) { stub(:existing_data) }
|
44
|
+
config_object.should_not_receive("#{subject.name}=")
|
45
|
+
subject.should_receive(:warn)
|
46
|
+
subject.apply
|
47
|
+
end
|
48
|
+
|
35
49
|
end
|
36
50
|
|
37
51
|
context "#name" do
|
@@ -69,6 +83,7 @@ module Conflate
|
|
69
83
|
subject.yaml_path = erb
|
70
84
|
expect(subject.send(:data)).to eq({"foo" => "BAR"})
|
71
85
|
end
|
86
|
+
|
72
87
|
end
|
73
88
|
end
|
74
89
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conflate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -101,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
segments:
|
103
103
|
- 0
|
104
|
-
hash:
|
104
|
+
hash: 1307108633160320951
|
105
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
version: '0'
|
111
111
|
segments:
|
112
112
|
- 0
|
113
|
-
hash:
|
113
|
+
hash: 1307108633160320951
|
114
114
|
requirements: []
|
115
115
|
rubyforge_project:
|
116
116
|
rubygems_version: 1.8.25
|