conflate 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.markdown +28 -0
- data/Rakefile +7 -0
- data/conflate.gemspec +28 -0
- data/lib/conflate.rb +6 -0
- data/lib/conflate/conflation.rb +39 -0
- data/lib/conflate/conflator.rb +40 -0
- data/lib/conflate/version.rb +3 -0
- data/spec/conflate/conflation_spec.rb +74 -0
- data/spec/conflate/conflator_spec.rb +47 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/configs/foo.yml +0 -0
- data/spec/support/configs/ignore.txt +0 -0
- data/spec/support/specific_examples/erb.yml +2 -0
- data/spec/support/specific_examples/hash.yml +2 -0
- data/spec/support/specific_examples/invalid.yml +2 -0
- metadata +128 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/sportngin/conflate.png)](https://travis-ci.org/sportngin/conflate)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/sportngin/conflate.png)](https://codeclimate.com/github/sportngin/conflate)
|
3
|
+
|
4
|
+
Conflate
|
5
|
+
========
|
6
|
+
|
7
|
+
Load YAML files in your config directory into the Rails.application.config.
|
8
|
+
|
9
|
+
Example
|
10
|
+
-------
|
11
|
+
|
12
|
+
Let's suppose you have a file 'config/foo.yml', with the following contents:
|
13
|
+
|
14
|
+
```yml
|
15
|
+
thing1: "qwerty"
|
16
|
+
thing2: "asdf
|
17
|
+
```
|
18
|
+
|
19
|
+
With Conflate, this information gets loaded into the `Rails.application.config` object like so:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
Rails.application.config.foo.thing1
|
23
|
+
# => "qwerty"
|
24
|
+
Rails.application.config.foo.thing2
|
25
|
+
# => "asdf"
|
26
|
+
```
|
27
|
+
|
28
|
+
Use this information in your application or other initializers.
|
data/Rakefile
ADDED
data/conflate.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'conflate/version'
|
5
|
+
|
6
|
+
authors = {
|
7
|
+
"Patrick Byrne" => "patrick.byrne@sportngin.com",
|
8
|
+
}
|
9
|
+
|
10
|
+
Gem::Specification.new do |spec|
|
11
|
+
spec.name = "conflate"
|
12
|
+
spec.version = Conflate::VERSION
|
13
|
+
spec.authors = authors.keys
|
14
|
+
spec.email = authors.values
|
15
|
+
spec.description = %q{Load YAML files in your config directory into the Rails.application.config.}
|
16
|
+
spec.summary = %q{Load YAML files in your config directory into the Rails.application.config.}
|
17
|
+
spec.homepage = "https://github.com/sportngin/conflate"
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
spec.files = `git ls-files`.split($/)
|
21
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
end
|
data/lib/conflate.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
# This class wraps around the YAML files and performs the parsing/applying of
|
4
|
+
# the config values read from them.
|
5
|
+
module Conflate
|
6
|
+
class Conflation
|
7
|
+
attr_accessor :yaml_path, :config_object
|
8
|
+
|
9
|
+
# Public: Initialize a new Conflation
|
10
|
+
#
|
11
|
+
# yaml_path - Path to the YAML file to read config information from
|
12
|
+
# config_object - Object to receive the configuration values (e.g., Rails.application.config)
|
13
|
+
def initialize(yaml_path, config_object)
|
14
|
+
self.yaml_path = yaml_path
|
15
|
+
self.config_object = config_object
|
16
|
+
end
|
17
|
+
|
18
|
+
# Public: Add the contents of the YAML file to the config object
|
19
|
+
def apply
|
20
|
+
config_object.public_send "#{name}=", data
|
21
|
+
end
|
22
|
+
|
23
|
+
# Public: The name of the conflation, based on the YAML file name
|
24
|
+
#
|
25
|
+
# Returns a String
|
26
|
+
def name
|
27
|
+
File.basename(yaml_path, ".yml")
|
28
|
+
end
|
29
|
+
|
30
|
+
# Private: The parsed data from the YAML file
|
31
|
+
def data
|
32
|
+
YAML.load ERB.new(File.read File.expand_path yaml_path).result
|
33
|
+
rescue StandardError, SyntaxError => e
|
34
|
+
{}
|
35
|
+
end
|
36
|
+
private :data
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "conflate/conflation"
|
2
|
+
|
3
|
+
# Scans for YAML files in the config directory and parses them for
|
4
|
+
# configuration values. For example, imagine the file below:
|
5
|
+
#
|
6
|
+
# # foo.yml
|
7
|
+
# thing1: "qwerty"
|
8
|
+
# thing2: "asdf"
|
9
|
+
#
|
10
|
+
# It will add foo.thing1 and foo.thing2 to Rails.application.config with the
|
11
|
+
# values from foo.yml
|
12
|
+
module Conflate
|
13
|
+
class Conflator
|
14
|
+
attr_accessor :path, :config
|
15
|
+
|
16
|
+
# Public: Initialize a new Conflator
|
17
|
+
#
|
18
|
+
# path - Path the directory containing YAML configs (e.g., Rails.root.join("config"))
|
19
|
+
# config - Object to receive the config entries (e.g., Rails.application.config)
|
20
|
+
def initialize(path, config)
|
21
|
+
self.path = path
|
22
|
+
self.config = config
|
23
|
+
end
|
24
|
+
|
25
|
+
# Public: Process the configuration
|
26
|
+
def perform
|
27
|
+
config_paths.each do |filename|
|
28
|
+
Conflation.new(filename, config).apply
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Private: The config files in the given path
|
33
|
+
#
|
34
|
+
# Returns an Array of Strings containing paths
|
35
|
+
def config_paths
|
36
|
+
Dir.glob(File.join path, "*.yml")
|
37
|
+
end
|
38
|
+
private :config_paths
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "conflate/conflation"
|
3
|
+
|
4
|
+
module Conflate
|
5
|
+
describe Conflation do
|
6
|
+
|
7
|
+
let(:yaml_path) { "config/something.yml" }
|
8
|
+
let(:config_object) { stub(:config) }
|
9
|
+
|
10
|
+
subject { Conflation.new yaml_path, config_object }
|
11
|
+
|
12
|
+
context ".new(yaml_path, config_object)" do
|
13
|
+
|
14
|
+
it "remembers the YAML path and config object given to it" do
|
15
|
+
expect(subject.yaml_path).to eq yaml_path
|
16
|
+
expect(subject.config_object).to eq config_object
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
context "#apply" do
|
22
|
+
|
23
|
+
before do
|
24
|
+
subject.stub({
|
25
|
+
name: "something",
|
26
|
+
data: {foo: "bar"},
|
27
|
+
})
|
28
|
+
end
|
29
|
+
|
30
|
+
it "applies the values in the YAML file to the config object" do
|
31
|
+
config_object.should_receive("#{subject.name}=").with(subject.send(:data))
|
32
|
+
subject.apply
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
context "#name" do
|
38
|
+
|
39
|
+
it "parses from the YAML filename" do
|
40
|
+
expect(subject.name).to eq "something"
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
context "#data" do
|
46
|
+
|
47
|
+
let(:base) { File.expand_path File.join(__FILE__, "../../support/specific_examples") }
|
48
|
+
let(:basic_hash) { File.join base, "hash.yml" }
|
49
|
+
let(:invalid) { File.join base, "invalid.yml" }
|
50
|
+
let(:missing) { File.join base, "missing.yml" }
|
51
|
+
let(:erb) { File.join base, "erb.yml" }
|
52
|
+
|
53
|
+
it "reads a hash from the YAML file" do
|
54
|
+
subject.yaml_path = basic_hash
|
55
|
+
expect(subject.send(:data)).to eq({"foo" => "bar"})
|
56
|
+
end
|
57
|
+
|
58
|
+
it "gracefully handles invalid YAML" do
|
59
|
+
subject.yaml_path = invalid
|
60
|
+
expect(subject.send(:data)).to eq({})
|
61
|
+
end
|
62
|
+
|
63
|
+
it "gracefully handles a missing file" do
|
64
|
+
subject.yaml_path = missing
|
65
|
+
expect(subject.send(:data)).to eq({})
|
66
|
+
end
|
67
|
+
|
68
|
+
it "parses ERB in the YAML file" do
|
69
|
+
subject.yaml_path = erb
|
70
|
+
expect(subject.send(:data)).to eq({"foo" => "BAR"})
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "conflate/conflator"
|
3
|
+
|
4
|
+
module Conflate
|
5
|
+
describe Conflator do
|
6
|
+
let(:config) { stub(:rails_config) } # e.g., Rails.application.config
|
7
|
+
let(:path) { File.expand_path File.join(__FILE__, "../../support/configs/") }
|
8
|
+
|
9
|
+
subject { Conflator.new path, config }
|
10
|
+
|
11
|
+
context "#perform" do
|
12
|
+
|
13
|
+
let(:yaml_conflation) { stub(:conflation) }
|
14
|
+
let(:file_path) { File.join path, "foo.yml" }
|
15
|
+
|
16
|
+
before do
|
17
|
+
# subject.stub(:file_paths) { [file_path] }
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should parse only the yml files in the config path" do
|
21
|
+
|
22
|
+
# yaml files
|
23
|
+
Conflation.should_receive(:new).with(File.expand_path(File.join path, "foo.yml"), config) { yaml_conflation }
|
24
|
+
yaml_conflation.should_receive(:apply)
|
25
|
+
# but not other files
|
26
|
+
Conflation.should_not_receive(:new).with(File.expand_path(File.join path, "ignore.txt"))
|
27
|
+
subject.perform
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
context "#config_paths" do
|
33
|
+
# these are files in spec/support/configs and read from disk for real
|
34
|
+
let(:yml_path) { File.join path, "foo.yml" }
|
35
|
+
let(:txt_path) { File.join path, "ignore.txt" }
|
36
|
+
|
37
|
+
it "looks for .yml files" do
|
38
|
+
expect(subject.send :config_paths).to include(yml_path)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "ignores other files" do
|
42
|
+
expect(subject.send :config_paths).to_not include(txt_path)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
File without changes
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: conflate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Patrick Byrne
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Load YAML files in your config directory into the Rails.application.config.
|
63
|
+
email:
|
64
|
+
- patrick.byrne@sportngin.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- .travis.yml
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.markdown
|
75
|
+
- Rakefile
|
76
|
+
- conflate.gemspec
|
77
|
+
- lib/conflate.rb
|
78
|
+
- lib/conflate/conflation.rb
|
79
|
+
- lib/conflate/conflator.rb
|
80
|
+
- lib/conflate/version.rb
|
81
|
+
- spec/conflate/conflation_spec.rb
|
82
|
+
- spec/conflate/conflator_spec.rb
|
83
|
+
- spec/spec_helper.rb
|
84
|
+
- spec/support/configs/foo.yml
|
85
|
+
- spec/support/configs/ignore.txt
|
86
|
+
- spec/support/specific_examples/erb.yml
|
87
|
+
- spec/support/specific_examples/hash.yml
|
88
|
+
- spec/support/specific_examples/invalid.yml
|
89
|
+
homepage: https://github.com/sportngin/conflate
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
hash: 1687607675183126005
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
segments:
|
112
|
+
- 0
|
113
|
+
hash: 1687607675183126005
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 1.8.25
|
117
|
+
signing_key:
|
118
|
+
specification_version: 3
|
119
|
+
summary: Load YAML files in your config directory into the Rails.application.config.
|
120
|
+
test_files:
|
121
|
+
- spec/conflate/conflation_spec.rb
|
122
|
+
- spec/conflate/conflator_spec.rb
|
123
|
+
- spec/spec_helper.rb
|
124
|
+
- spec/support/configs/foo.yml
|
125
|
+
- spec/support/configs/ignore.txt
|
126
|
+
- spec/support/specific_examples/erb.yml
|
127
|
+
- spec/support/specific_examples/hash.yml
|
128
|
+
- spec/support/specific_examples/invalid.yml
|