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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b28681a81e233360028348be15505ab62d698a9c
4
- data.tar.gz: 060e3a8c45400254f9fb8e926b75683f82a4fed9
3
+ metadata.gz: 0d2491a84ca38fbb4654e718bc97107610a1d8aa
4
+ data.tar.gz: 6d1e0e431a2b7f03c2d41753ba5eb334fb12551a
5
5
  SHA512:
6
- metadata.gz: 52e33f3b602ff5a8dd9fdc6728a8898e42d3572bc4c147f4755cab966d4ceece89ce46639619302677882028620084aaf60c93cebf92e8490515fdfb8fb13a7d
7
- data.tar.gz: 3bf3b2b64289087f2abd06816434e51590fd59add1fb82b0aee96522d1a5571d58a0496fc993d420e97b78191219324bd183a78b55e62a0de7bf4a50f508e8fe
6
+ metadata.gz: b7df5b0ae04f808fbf30c3f5072bd37100c2dd4a47ab033d68bc4bd6b1aeea2cb5dd95be88e3418ccdc0a73b02c19610e09d80816daa38637a213fdc2009d49f
7
+ data.tar.gz: 8982aa92e9096317c24b982709b3f9145262e3db2069bc8cee7977d49d50a0709de5c81d7c1629ae129d9d5d557663abf97ec5a7c91ddff6cc7a5a739d4d9370
@@ -14,5 +14,7 @@ rvm:
14
14
  - 2.1.1
15
15
  - 2.1.2
16
16
  - 2.1.3
17
+ - 2.1.4
18
+ - 2.1.5
17
19
  - jruby-19mode
18
20
  - rbx-2
data/TODO CHANGED
@@ -1 +1 @@
1
- * Add support for other source-file types (JSON? XML (::shiver::)?)
1
+ * Add support for additional source-file types (e.g XML)
@@ -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.add_development_dependency 'bundler', '~> 1.6'
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.3'
28
- gem.add_development_dependency 'rspec', '~> 3.0'
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
@@ -1,13 +1,7 @@
1
- require 'erb'
2
- require 'net/http'
3
- require 'openssl'
4
- require 'ostruct'
5
- require 'uri'
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'
@@ -1,24 +1,27 @@
1
+ require 'ostruct'
2
+
1
3
  module Foundry
2
4
  class Configurator
3
5
  def self.configure(opts)
4
- Configurator.new.configure(opts)
6
+ new.configure(opts)
5
7
  end
6
8
 
7
9
  def configure(opts)
8
10
  with_opts(opts) do
9
- transmorgs = transmorgify(opts.fetch(:relative_path))
10
- merged = mergify(transmorgs)
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
- attr_reader :opts
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
- def erbify(str)
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
- YAML.load(str) || {}
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
- opts.fetch(:source_type)
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(erbify(loadify(relative_path)))
70
- inherit = parsed.delete('inherit')
71
- Array(inherit && transmorgify(inherit)) << parsed
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,2 @@
1
+ require 'foundry/parsers/json'
2
+ require 'foundry/parsers/yaml'
@@ -0,0 +1,11 @@
1
+ require 'json'
2
+
3
+ module Foundry
4
+ module Parsers
5
+ class JSON
6
+ def parse(str)
7
+ ::JSON.parse(str)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'yaml'
2
+
3
+ module Foundry
4
+ module Parsers
5
+ class YAML
6
+ def parse(str)
7
+ ::YAML.load(str)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1 @@
1
+ require 'foundry/refinements/hash'
@@ -0,0 +1,2 @@
1
+ require 'foundry/sources/file'
2
+ require 'foundry/sources/uri'
@@ -1,3 +1,7 @@
1
+ require 'net/http'
2
+ require 'openssl'
3
+ require 'uri'
4
+
1
5
  module Foundry
2
6
  module Sources
3
7
  class URI
@@ -0,0 +1 @@
1
+ require 'foundry/template_engines/erb'
@@ -0,0 +1,11 @@
1
+ require 'erb'
2
+
3
+ module Foundry
4
+ module TemplateEngines
5
+ class ERB
6
+ def evaluate(str)
7
+ ::ERB.new(str).result
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Foundry
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -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 YAML is invalid' do
24
+ it 'will fail-fast if the parser raises an error' do
27
25
  with_source do |source|
28
- expect(source).to receive(:load)
29
- expect { subject.configure(opts) }.to raise_error
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 ERB raises an error' do
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 YAML/ERB' do
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 default_opts
83
- {
84
- :exactly => :once,
85
- :type => Foundry::Sources::File,
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
- merged_opts = default_opts.merge(opts)
91
- source = merged_opts[:type].new
92
- expect(subject).to receive(:source).exactly(merged_opts[:exactly]) { source }
93
- yield source
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
@@ -9,6 +9,7 @@ describe Hash do
9
9
  :D => nil,
10
10
  }
11
11
  end
12
+
12
13
  let(:keys) do
13
14
  [
14
15
  :A,
@@ -1,8 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Foundry::Sources::File do
4
- subject { Foundry::Sources::File.new }
5
-
6
4
  it 'can load a file' do
7
5
  expect(File).to receive(:read)
8
6
  subject.load('', '', {})
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Foundry::Sources::URI do
4
- subject { Foundry::Sources::URI.new }
5
4
  let(:domain) { 'foo.bar.com' }
6
5
  let(:relative_path) { 'config.yml' }
7
6
 
@@ -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.3.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: 2014-10-30 00:00:00.000000000 Z
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.6'
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.6'
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.3'
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.3'
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.0'
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.0'
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.2.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