foundry 0.4.0 → 0.5.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 +4 -16
- data/README.md +21 -11
- data/foundry.gemspec +5 -4
- data/lib/foundry/configurator.rb +11 -12
- data/lib/foundry/parsers/json.rb +1 -0
- data/lib/foundry/parsers/yaml.rb +1 -0
- data/lib/foundry/sources/uri.rb +3 -1
- data/lib/foundry/template_engines/erb.rb +1 -0
- data/lib/foundry/version.rb +1 -1
- data/spec/configurator_spec.rb +4 -7
- data/spec/parsers/json_spec.rb +1 -1
- data/spec/parsers/yaml_spec.rb +1 -1
- data/spec/sources/file_spec.rb +1 -1
- data/spec/sources/uri_spec.rb +1 -2
- data/spec/template_engines/erb_spec.rb +1 -1
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c5e26aee10f8b0f8ce70041ac8f58bc3d15053c
|
4
|
+
data.tar.gz: 69cc9a43621f3d13eb8a95993574fd942bcf7378
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2d80f91e70408abd0676c7fa09152712d4243c4589fe25f1daa8a3d7b3f88d552e254f3cb65acbee31354488cd9ef2644b5e8c03ad68168941ea53ade1161ec
|
7
|
+
data.tar.gz: 6e3cb8321089f61f99d830ba0305bea7ede7c966e9c59137ea6b0e7248286acac7dd49921fe44812657d9f8c5917f520e453c93a9e79aac4c877cc097070ba16
|
data/.travis.yml
CHANGED
@@ -1,20 +1,8 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
|
-
matrix:
|
4
|
-
allow_failures:
|
5
|
-
- rvm: jruby-19mode
|
6
|
-
- rvm: rbx-2
|
7
|
-
|
8
3
|
rvm:
|
9
|
-
- 1.8.7
|
10
|
-
- 1.9.2
|
11
|
-
- 1.9.3
|
12
4
|
- 2.0.0
|
13
|
-
- 2.1.
|
14
|
-
- 2.
|
15
|
-
- 2.
|
16
|
-
- 2.
|
17
|
-
- 2.1.4
|
18
|
-
- 2.1.5
|
19
|
-
- jruby-19mode
|
20
|
-
- rbx-2
|
5
|
+
- 2.1.9
|
6
|
+
- 2.2.6
|
7
|
+
- 2.3.3
|
8
|
+
- 2.4.0
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Foundry
|
1
|
+
# Foundry
|
2
2
|
|
3
3
|
[![Build Status](https://secure.travis-ci.org/jzaleski/foundry.png?branch=master)](http://travis-ci.org/jzaleski/foundry)
|
4
4
|
[![Dependency Status](https://gemnasium.com/jzaleski/foundry.png)](https://gemnasium.com/jzaleski/foundry)
|
@@ -11,8 +11,8 @@ This gem aims to keep it simple and fully decouple the two concerns.
|
|
11
11
|
|
12
12
|
Features:
|
13
13
|
|
14
|
-
* Can load YAML from a local-file
|
15
|
-
* Can load YAML from a HTTP/HTTPS endpoint
|
14
|
+
* Can load JSON or YAML from a local-file
|
15
|
+
* Can load JSON or YAML from a HTTP/HTTPS endpoint
|
16
16
|
* Supports Basic Authentication for HTTP{,S} endpoints
|
17
17
|
* Supports ERB interpolation
|
18
18
|
* Returns an easy to navigate object-graph
|
@@ -46,20 +46,19 @@ config = Foundry::Configurator.configure(
|
|
46
46
|
Loading from a HTTP/HTTPS endpoint:
|
47
47
|
|
48
48
|
```ruby
|
49
|
+
# defaults to a source-type of `Foundry::Sources::URI` and a parser-type of `Foundry::Parsers::YAML`
|
49
50
|
config = Foundry::Configurator.configure(
|
50
51
|
:root_path => 'http-or-https-root-url',
|
51
52
|
:relative_path => 'relative-path-to-file',
|
52
|
-
:source_type => Foundry::Sources::URI
|
53
53
|
)
|
54
54
|
```
|
55
55
|
|
56
|
-
Loading from a HTTP/HTTPS endpoint using "Basic Authentication":
|
56
|
+
Loading YAML from a HTTP/HTTPS endpoint using "Basic Authentication":
|
57
57
|
|
58
58
|
```ruby
|
59
59
|
config = Foundry::Configurator.configure(
|
60
60
|
:root_path => 'http-or-https-root-url',
|
61
61
|
:relative_path => 'relative-path-to-file',
|
62
|
-
:source_type => Foundry::Sources::URI,
|
63
62
|
:username => 'basic-auth-username',
|
64
63
|
:password => 'basic-auth-password'
|
65
64
|
)
|
@@ -95,9 +94,10 @@ Inheritance support:
|
|
95
94
|
```ruby
|
96
95
|
# The examples below assume that there are two files available, relative to the
|
97
96
|
# `root_path`, named "file1.yml" and "file2.yml" (and that "file2.yml" inherits
|
98
|
-
# from "file1.yml"
|
97
|
+
# from "file1.yml" -- it is immaterial at this point whether the file-format is
|
98
|
+
# JSON or YAML).
|
99
99
|
#
|
100
|
-
#
|
100
|
+
# When using the YAML parser, the file contents would be as follows:
|
101
101
|
#
|
102
102
|
# === file1.yml ===
|
103
103
|
#
|
@@ -110,12 +110,22 @@ Inheritance support:
|
|
110
110
|
# value2: value
|
111
111
|
# inherit: file1.yml
|
112
112
|
#
|
113
|
+
# When using the JSON parser, the file contents would be as follows:
|
114
|
+
#
|
115
|
+
# === file1.json ===
|
116
|
+
#
|
117
|
+
# { "value1": "value" }
|
118
|
+
#
|
119
|
+
# === file2.json ===
|
120
|
+
#
|
121
|
+
# { "inherit": "file1.json", "value2": "value" }
|
122
|
+
#
|
113
123
|
# It is also assumed that the files have already been loaded and processed by a
|
114
124
|
# call to `Foundry::Configurator.configure` (into a variable named `config`).
|
115
125
|
#
|
116
|
-
#
|
117
|
-
# as follows (it is worth noting that the `inherit` key
|
118
|
-
# configuration process):
|
126
|
+
# Regardless of parser-type the result now contains values for both `value1` and
|
127
|
+
# `value2` and can be used as follows (it is worth noting that the `inherit` key
|
128
|
+
# is removed during the configuration process):
|
119
129
|
|
120
130
|
# Fetching `value1` and `value2` using dot-notation
|
121
131
|
value1 = config.value1
|
data/foundry.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'foundry/version'
|
@@ -22,11 +23,11 @@ Gem::Specification.new do |gem|
|
|
22
23
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
23
24
|
gem.require_paths = ['lib']
|
24
25
|
|
25
|
-
gem.add_dependency('json', '~>
|
26
|
+
gem.add_dependency('json', '~> 2.0')
|
26
27
|
|
27
28
|
gem.add_development_dependency 'bundler', '~> 1.0'
|
28
29
|
gem.add_development_dependency 'pry', '~> 0.10'
|
29
|
-
gem.add_development_dependency 'rake', '~>
|
30
|
-
gem.add_development_dependency 'rspec', '~> 3.
|
31
|
-
gem.add_development_dependency 'webmock', '~>
|
30
|
+
gem.add_development_dependency 'rake', '~> 12.0'
|
31
|
+
gem.add_development_dependency 'rspec', '~> 3.0'
|
32
|
+
gem.add_development_dependency 'webmock', '~> 3.0'
|
32
33
|
end
|
data/lib/foundry/configurator.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
|
3
|
+
|
3
4
|
module Foundry
|
4
5
|
class Configurator
|
5
6
|
def self.configure(opts)
|
@@ -9,7 +10,9 @@ module Foundry
|
|
9
10
|
def configure(opts)
|
10
11
|
with_opts(opts) do
|
11
12
|
relative_path = opts.fetch(:relative_path)
|
12
|
-
|
13
|
+
transmorg = transmorgify(relative_path)
|
14
|
+
merged = mergify(transmorg)
|
15
|
+
structify(merged)
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
@@ -18,7 +21,7 @@ module Foundry
|
|
18
21
|
DEFAULT_OPTS = {
|
19
22
|
:parser_type => Foundry::Parsers::YAML,
|
20
23
|
:source_type => Foundry::Sources::URI,
|
21
|
-
:template_engine_type => Foundry::TemplateEngines::ERB
|
24
|
+
:template_engine_type => Foundry::TemplateEngines::ERB,
|
22
25
|
}
|
23
26
|
|
24
27
|
attr_reader :opts
|
@@ -63,20 +66,16 @@ module Foundry
|
|
63
66
|
opts_value_or_default(:source_type)
|
64
67
|
end
|
65
68
|
|
66
|
-
def structify(
|
67
|
-
case
|
69
|
+
def structify(value)
|
70
|
+
case value
|
68
71
|
when Array
|
69
|
-
|
70
|
-
structify(value)
|
71
|
-
end
|
72
|
+
value.map { |item| structify(item) }
|
72
73
|
when Hash
|
73
|
-
OpenStruct.new.tap do |
|
74
|
-
|
75
|
-
open_struct.send("#{key}=", structify(value))
|
76
|
-
end
|
74
|
+
OpenStruct.new.tap do |struct|
|
75
|
+
value.each { |item| struct.send("#{item[0]}=", structify(item[1])) }
|
77
76
|
end
|
78
77
|
else
|
79
|
-
|
78
|
+
value
|
80
79
|
end
|
81
80
|
end
|
82
81
|
|
data/lib/foundry/parsers/json.rb
CHANGED
data/lib/foundry/parsers/yaml.rb
CHANGED
data/lib/foundry/sources/uri.rb
CHANGED
@@ -2,6 +2,7 @@ require 'net/http'
|
|
2
2
|
require 'openssl'
|
3
3
|
require 'uri'
|
4
4
|
|
5
|
+
|
5
6
|
module Foundry
|
6
7
|
module Sources
|
7
8
|
class URI
|
@@ -17,7 +18,8 @@ module Foundry
|
|
17
18
|
request.basic_auth(username, password)
|
18
19
|
end
|
19
20
|
response = client.request(request)
|
20
|
-
raise "Unknown configuration file: #{uri}"
|
21
|
+
raise "Unknown configuration file: #{uri}" \
|
22
|
+
unless response.is_a?(Net::HTTPSuccess)
|
21
23
|
response.body
|
22
24
|
end
|
23
25
|
end
|
data/lib/foundry/version.rb
CHANGED
data/spec/configurator_spec.rb
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Foundry::Configurator do
|
4
|
-
REQUIRED_OPTS = [
|
5
|
-
:root_path,
|
6
|
-
:relative_path
|
7
|
-
]
|
4
|
+
REQUIRED_OPTS = [:relative_path, :root_path]
|
8
5
|
|
9
6
|
let(:opts) { REQUIRED_OPTS.reduce({}) { |memo, opt| memo[opt] = nil; memo } }
|
10
7
|
|
11
8
|
REQUIRED_OPTS.each do |key|
|
12
9
|
it %{must be passed a "#{key}"} do
|
13
|
-
expect { subject.configure(opts.without(key)) }.to raise_error
|
10
|
+
expect { subject.configure(opts.without(key)) }.to raise_error KeyError
|
14
11
|
end
|
15
12
|
end
|
16
13
|
|
@@ -26,7 +23,7 @@ describe Foundry::Configurator do
|
|
26
23
|
with_parser do |parser|
|
27
24
|
expect(source).to receive(:load)
|
28
25
|
expect(parser).to receive(:parse).and_call_original
|
29
|
-
expect { subject.configure(opts) }.to raise_error
|
26
|
+
expect { subject.configure(opts) }.to raise_error ZeroDivision
|
30
27
|
end
|
31
28
|
end
|
32
29
|
end
|
@@ -35,7 +32,7 @@ describe Foundry::Configurator do
|
|
35
32
|
with_source do |source|
|
36
33
|
expect(source).to receive(:load) { 'foo: <%= 1/0 %>' }
|
37
34
|
expect(template_engine).to receive(:evaluate).and_call_original
|
38
|
-
expect { subject.configure(opts) }.to raise_error
|
35
|
+
expect { subject.configure(opts) }.to raise_error ZeroDivision
|
39
36
|
end
|
40
37
|
end
|
41
38
|
|
data/spec/parsers/json_spec.rb
CHANGED
data/spec/parsers/yaml_spec.rb
CHANGED
data/spec/sources/file_spec.rb
CHANGED
data/spec/sources/uri_spec.rb
CHANGED
@@ -14,7 +14,6 @@ describe Foundry::Sources::URI do
|
|
14
14
|
let(:https_response_body) { 'https_response_body' }
|
15
15
|
let(:https_opts) { {} }
|
16
16
|
|
17
|
-
let(:basic_auth_uri) { "http://#{basic_auth_username}:#{basic_auth_password}@#{domain}/#{relative_path}" }
|
18
17
|
let(:basic_auth_root_path) { http_root_path }
|
19
18
|
let(:basic_auth_response_body) { 'basic_auth_response_body' }
|
20
19
|
let(:basic_auth_username) { 'basic_auth_username' }
|
@@ -49,7 +48,7 @@ describe Foundry::Sources::URI do
|
|
49
48
|
end
|
50
49
|
|
51
50
|
it 'can load from a endpoint using basic-auth' do
|
52
|
-
stub_request(:get,
|
51
|
+
stub_request(:get, http_uri).to_return(:body => basic_auth_response_body)
|
53
52
|
|
54
53
|
expect(
|
55
54
|
subject.load(
|
@@ -6,6 +6,6 @@ describe Foundry::TemplateEngines::ERB do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
it 'will raise an error if evaluation of an ERB template fails' do
|
9
|
-
expect { subject.evaluate('<%= 1/0 %>') }.to raise_error
|
9
|
+
expect { subject.evaluate('<%= 1/0 %>') }.to raise_error ZeroDivisionError
|
10
10
|
end
|
11
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foundry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.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: 2017-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,42 +58,42 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '12.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '12.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '3.
|
75
|
+
version: '3.0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '3.
|
82
|
+
version: '3.0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: webmock
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '3.0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '3.0'
|
97
97
|
description: |2
|
98
98
|
Let's face it, there are a number of problems when application/environment
|
99
99
|
configuration logic is too tightly coupled with the configuration-data itself.
|
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
153
|
version: '0'
|
154
154
|
requirements: []
|
155
155
|
rubyforge_project:
|
156
|
-
rubygems_version: 2.
|
156
|
+
rubygems_version: 2.6.10
|
157
157
|
signing_key:
|
158
158
|
specification_version: 4
|
159
159
|
summary: An application configuration gem that aims to keep it simple
|