foundry 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/TODO +1 -1
- data/foundry.gemspec +5 -3
- data/lib/foundry.rb +5 -11
- data/lib/foundry/configurator.rb +40 -13
- data/lib/foundry/parsers.rb +2 -0
- data/lib/foundry/parsers/json.rb +11 -0
- data/lib/foundry/parsers/yaml.rb +11 -0
- data/lib/foundry/refinements.rb +1 -0
- data/lib/foundry/sources.rb +2 -0
- data/lib/foundry/sources/uri.rb +4 -0
- data/lib/foundry/template_engines.rb +1 -0
- data/lib/foundry/template_engines/erb.rb +11 -0
- data/lib/foundry/version.rb +1 -1
- data/spec/configurator_spec.rb +33 -17
- data/spec/parsers/json_spec.rb +11 -0
- data/spec/parsers/yaml_spec.rb +11 -0
- data/spec/refinements/hash_spec.rb +1 -0
- data/spec/sources/file_spec.rb +0 -2
- data/spec/sources/uri_spec.rb +0 -1
- data/spec/template_engines/erb_spec.rb +11 -0
- metadata +50 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d2491a84ca38fbb4654e718bc97107610a1d8aa
|
4
|
+
data.tar.gz: 6d1e0e431a2b7f03c2d41753ba5eb334fb12551a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7df5b0ae04f808fbf30c3f5072bd37100c2dd4a47ab033d68bc4bd6b1aeea2cb5dd95be88e3418ccdc0a73b02c19610e09d80816daa38637a213fdc2009d49f
|
7
|
+
data.tar.gz: 8982aa92e9096317c24b982709b3f9145262e3db2069bc8cee7977d49d50a0709de5c81d7c1629ae129d9d5d557663abf97ec5a7c91ddff6cc7a5a739d4d9370
|
data/.travis.yml
CHANGED
data/TODO
CHANGED
@@ -1 +1 @@
|
|
1
|
-
* Add support for
|
1
|
+
* Add support for additional source-file types (e.g XML)
|
data/foundry.gemspec
CHANGED
@@ -22,9 +22,11 @@ Gem::Specification.new do |gem|
|
|
22
22
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
23
23
|
gem.require_paths = ['lib']
|
24
24
|
|
25
|
-
gem.
|
25
|
+
gem.add_dependency('json', '~> 1.8')
|
26
|
+
|
27
|
+
gem.add_development_dependency 'bundler', '~> 1.0'
|
26
28
|
gem.add_development_dependency 'pry', '~> 0.10'
|
27
|
-
gem.add_development_dependency 'rake', '~> 10.
|
28
|
-
gem.add_development_dependency 'rspec', '~> 3.
|
29
|
+
gem.add_development_dependency 'rake', '~> 10.4'
|
30
|
+
gem.add_development_dependency 'rspec', '~> 3.1'
|
29
31
|
gem.add_development_dependency 'webmock', '~> 1.20'
|
30
32
|
end
|
data/lib/foundry.rb
CHANGED
@@ -1,13 +1,7 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
require 'yaml'
|
7
|
-
|
8
|
-
require 'foundry/refinements/hash'
|
1
|
+
require 'foundry/parsers'
|
2
|
+
require 'foundry/refinements'
|
3
|
+
require 'foundry/sources'
|
4
|
+
require 'foundry/template_engines'
|
5
|
+
require 'foundry/version'
|
9
6
|
|
10
7
|
require 'foundry/configurator'
|
11
|
-
require 'foundry/sources/file'
|
12
|
-
require 'foundry/sources/uri'
|
13
|
-
require 'foundry/version'
|
data/lib/foundry/configurator.rb
CHANGED
@@ -1,24 +1,27 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
1
3
|
module Foundry
|
2
4
|
class Configurator
|
3
5
|
def self.configure(opts)
|
4
|
-
|
6
|
+
new.configure(opts)
|
5
7
|
end
|
6
8
|
|
7
9
|
def configure(opts)
|
8
10
|
with_opts(opts) do
|
9
|
-
|
10
|
-
|
11
|
-
structify(merged)
|
11
|
+
relative_path = opts.fetch(:relative_path)
|
12
|
+
structify(mergify(transmorgify(relative_path)))
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
15
16
|
private
|
16
17
|
|
17
|
-
|
18
|
+
DEFAULT_OPTS = {
|
19
|
+
:parser_type => Foundry::Parsers::YAML,
|
20
|
+
:source_type => Foundry::Sources::URI,
|
21
|
+
:template_engine_type => Foundry::TemplateEngines::ERB
|
22
|
+
}
|
18
23
|
|
19
|
-
|
20
|
-
ERB.new(str).result
|
21
|
-
end
|
24
|
+
attr_reader :opts
|
22
25
|
|
23
26
|
def loadify(relative_path)
|
24
27
|
source.load(
|
@@ -32,8 +35,20 @@ module Foundry
|
|
32
35
|
transmorgs.reduce({}) { |memo, transmorg| memo.deep_merge(transmorg) }
|
33
36
|
end
|
34
37
|
|
38
|
+
def opts_value_or_default(key)
|
39
|
+
opts.fetch(key, DEFAULT_OPTS.fetch(key))
|
40
|
+
end
|
41
|
+
|
42
|
+
def parser
|
43
|
+
parser_type.new
|
44
|
+
end
|
45
|
+
|
46
|
+
def parser_type
|
47
|
+
opts_value_or_default(:parser_type)
|
48
|
+
end
|
49
|
+
|
35
50
|
def parsify(str)
|
36
|
-
|
51
|
+
parser.parse(str) || {}
|
37
52
|
end
|
38
53
|
|
39
54
|
def root_path
|
@@ -45,7 +60,7 @@ module Foundry
|
|
45
60
|
end
|
46
61
|
|
47
62
|
def source_type
|
48
|
-
|
63
|
+
opts_value_or_default(:source_type)
|
49
64
|
end
|
50
65
|
|
51
66
|
def structify(object)
|
@@ -65,10 +80,22 @@ module Foundry
|
|
65
80
|
end
|
66
81
|
end
|
67
82
|
|
83
|
+
def template_engine
|
84
|
+
template_engine_type.new
|
85
|
+
end
|
86
|
+
|
87
|
+
def template_engine_type
|
88
|
+
opts_value_or_default(:template_engine_type)
|
89
|
+
end
|
90
|
+
|
91
|
+
def templatify(str)
|
92
|
+
template_engine.evaluate(str)
|
93
|
+
end
|
94
|
+
|
68
95
|
def transmorgify(relative_path)
|
69
|
-
parsed = parsify(
|
70
|
-
|
71
|
-
Array(
|
96
|
+
parsed = parsify(templatify(loadify(relative_path)))
|
97
|
+
next_relative_path = parsed.delete('inherit')
|
98
|
+
Array(next_relative_path && transmorgify(next_relative_path)) << parsed
|
72
99
|
end
|
73
100
|
|
74
101
|
def with_opts(opts)
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'foundry/refinements/hash'
|
data/lib/foundry/sources/uri.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
require 'foundry/template_engines/erb'
|
data/lib/foundry/version.rb
CHANGED
data/spec/configurator_spec.rb
CHANGED
@@ -3,11 +3,9 @@ require 'spec_helper'
|
|
3
3
|
describe Foundry::Configurator do
|
4
4
|
REQUIRED_OPTS = [
|
5
5
|
:root_path,
|
6
|
-
:relative_path
|
7
|
-
:source_type,
|
6
|
+
:relative_path
|
8
7
|
]
|
9
8
|
|
10
|
-
subject { Foundry::Configurator.new }
|
11
9
|
let(:opts) { REQUIRED_OPTS.reduce({}) { |memo, opt| memo[opt] = nil; memo } }
|
12
10
|
|
13
11
|
REQUIRED_OPTS.each do |key|
|
@@ -23,21 +21,25 @@ describe Foundry::Configurator do
|
|
23
21
|
end
|
24
22
|
end
|
25
23
|
|
26
|
-
it 'will fail-fast if the
|
24
|
+
it 'will fail-fast if the parser raises an error' do
|
27
25
|
with_source do |source|
|
28
|
-
|
29
|
-
|
26
|
+
with_parser do |parser|
|
27
|
+
expect(source).to receive(:load)
|
28
|
+
expect(parser).to receive(:parse).and_call_original
|
29
|
+
expect { subject.configure(opts) }.to raise_error
|
30
|
+
end
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
it 'will fail-fast if the
|
34
|
+
it 'will fail-fast if the template-engine raises an error' do
|
34
35
|
with_source do |source|
|
35
36
|
expect(source).to receive(:load) { 'foo: <%= 1/0 %>' }
|
37
|
+
expect(template_engine).to receive(:evaluate).and_call_original
|
36
38
|
expect { subject.configure(opts) }.to raise_error
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
|
-
it 'can parse
|
42
|
+
it 'can load, parse and evaluate then return a valid result' do
|
41
43
|
with_source do |source|
|
42
44
|
expect(source).to receive(:load) { <<-YAML
|
43
45
|
erb: <%= 1 * 2 * 3 %>
|
@@ -79,17 +81,31 @@ describe Foundry::Configurator do
|
|
79
81
|
|
80
82
|
private
|
81
83
|
|
82
|
-
def
|
83
|
-
{
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
def with_defaults_merged(opts={})
|
85
|
+
opts.merge({ :exactly => :once })
|
86
|
+
end
|
87
|
+
|
88
|
+
def with_parser(opts={})
|
89
|
+
with_defaults_merged(opts) do |merged_opts|
|
90
|
+
parser = merged_opts[:parser_type].new
|
91
|
+
expect(subject).to receive(:parser).exactly(opts[:exactly]) { parser }
|
92
|
+
yield parser
|
93
|
+
end
|
87
94
|
end
|
88
95
|
|
89
96
|
def with_source(opts={})
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
97
|
+
with_defaults_merged(opts) do |merged_opts|
|
98
|
+
source = merged_opts[:source_type].new
|
99
|
+
expect(subject).to receive(:source).exactly(opts[:exactly]) { source }
|
100
|
+
yield source
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def with_template_engine(opts={})
|
105
|
+
with_defaults_merged(opts) do |merged_opts|
|
106
|
+
template_engine = merged_opts[:template_engine_type].new
|
107
|
+
expect(subject).to receive(:template_engine).exactly(opts[:exactly]) { template_engine }
|
108
|
+
yield template_engine
|
109
|
+
end
|
94
110
|
end
|
95
111
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Foundry::Parsers::JSON do
|
4
|
+
it 'can parse JSON' do
|
5
|
+
expect(subject.parse('{ "foo": "bar" }')).to eq({ 'foo' => 'bar' })
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'will raise an error if the JSON is unparseable' do
|
9
|
+
expect { subject.parse(nil) }.to raise_error
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Foundry::Parsers::YAML do
|
4
|
+
it 'can parse YAML' do
|
5
|
+
expect(subject.parse('foo: bar')).to eq({ 'foo' => 'bar' })
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'will raise an error if the YAML is unparseable' do
|
9
|
+
expect { subject.parse(nil) }.to raise_error
|
10
|
+
end
|
11
|
+
end
|
data/spec/sources/file_spec.rb
CHANGED
data/spec/sources/uri_spec.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Foundry::TemplateEngines::ERB do
|
4
|
+
it 'can evaluate an ERB template' do
|
5
|
+
expect(subject.evaluate('<%= 1 * 2 * 3 %>')).to eq('6')
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'will raise an error if evaluation of an ERB template fails' do
|
9
|
+
expect { subject.evaluate('<%= 1/0 %>') }.to raise_error
|
10
|
+
end
|
11
|
+
end
|
metadata
CHANGED
@@ -1,83 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foundry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan W. Zaleski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
|
-
- - ~>
|
31
|
+
- - "~>"
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
33
|
+
version: '1.0'
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
|
-
- - ~>
|
38
|
+
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
40
|
+
version: '1.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: pry
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - ~>
|
45
|
+
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '0.10'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - ~>
|
52
|
+
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0.10'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - ~>
|
59
|
+
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '10.
|
61
|
+
version: '10.4'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - ~>
|
66
|
+
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '10.
|
68
|
+
version: '10.4'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rspec
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- - ~>
|
73
|
+
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3.
|
75
|
+
version: '3.1'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- - ~>
|
80
|
+
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '3.
|
82
|
+
version: '3.1'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: webmock
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- - ~>
|
87
|
+
- - "~>"
|
74
88
|
- !ruby/object:Gem::Version
|
75
89
|
version: '1.20'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- - ~>
|
94
|
+
- - "~>"
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '1.20'
|
83
97
|
description: |2
|
@@ -90,8 +104,8 @@ executables: []
|
|
90
104
|
extensions: []
|
91
105
|
extra_rdoc_files: []
|
92
106
|
files:
|
93
|
-
- .gitignore
|
94
|
-
- .travis.yml
|
107
|
+
- ".gitignore"
|
108
|
+
- ".travis.yml"
|
95
109
|
- Gemfile
|
96
110
|
- LICENSE.txt
|
97
111
|
- README.md
|
@@ -100,15 +114,25 @@ files:
|
|
100
114
|
- foundry.gemspec
|
101
115
|
- lib/foundry.rb
|
102
116
|
- lib/foundry/configurator.rb
|
117
|
+
- lib/foundry/parsers.rb
|
118
|
+
- lib/foundry/parsers/json.rb
|
119
|
+
- lib/foundry/parsers/yaml.rb
|
120
|
+
- lib/foundry/refinements.rb
|
103
121
|
- lib/foundry/refinements/hash.rb
|
122
|
+
- lib/foundry/sources.rb
|
104
123
|
- lib/foundry/sources/file.rb
|
105
124
|
- lib/foundry/sources/uri.rb
|
125
|
+
- lib/foundry/template_engines.rb
|
126
|
+
- lib/foundry/template_engines/erb.rb
|
106
127
|
- lib/foundry/version.rb
|
107
128
|
- spec/configurator_spec.rb
|
129
|
+
- spec/parsers/json_spec.rb
|
130
|
+
- spec/parsers/yaml_spec.rb
|
108
131
|
- spec/refinements/hash_spec.rb
|
109
132
|
- spec/sources/file_spec.rb
|
110
133
|
- spec/sources/uri_spec.rb
|
111
134
|
- spec/spec_helper.rb
|
135
|
+
- spec/template_engines/erb_spec.rb
|
112
136
|
homepage: https://github.com/jzaleski/foundry
|
113
137
|
licenses:
|
114
138
|
- MIT
|
@@ -119,23 +143,26 @@ require_paths:
|
|
119
143
|
- lib
|
120
144
|
required_ruby_version: !ruby/object:Gem::Requirement
|
121
145
|
requirements:
|
122
|
-
- -
|
146
|
+
- - ">="
|
123
147
|
- !ruby/object:Gem::Version
|
124
148
|
version: '0'
|
125
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
150
|
requirements:
|
127
|
-
- -
|
151
|
+
- - ">="
|
128
152
|
- !ruby/object:Gem::Version
|
129
153
|
version: '0'
|
130
154
|
requirements: []
|
131
155
|
rubyforge_project:
|
132
|
-
rubygems_version: 2.
|
156
|
+
rubygems_version: 2.4.5
|
133
157
|
signing_key:
|
134
158
|
specification_version: 4
|
135
159
|
summary: An application configuration gem that aims to keep it simple
|
136
160
|
test_files:
|
137
161
|
- spec/configurator_spec.rb
|
162
|
+
- spec/parsers/json_spec.rb
|
163
|
+
- spec/parsers/yaml_spec.rb
|
138
164
|
- spec/refinements/hash_spec.rb
|
139
165
|
- spec/sources/file_spec.rb
|
140
166
|
- spec/sources/uri_spec.rb
|
141
167
|
- spec/spec_helper.rb
|
168
|
+
- spec/template_engines/erb_spec.rb
|