foundry 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.travis.yml +15 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +11 -0
- data/TODO +2 -0
- data/foundry.gemspec +37 -0
- data/lib/foundry/configurator.rb +52 -0
- data/lib/foundry/loaders/file.rb +9 -0
- data/lib/foundry/loaders/uri.rb +19 -0
- data/lib/foundry/version.rb +3 -0
- data/lib/foundry.rb +11 -0
- data/spec/configurator_spec.rb +56 -0
- data/spec/loaders/file_spec.rb +15 -0
- data/spec/loaders/uri_spec.rb +36 -0
- data/spec/spec_helper.rb +6 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9da30abaa99f3fd6c765f67591499dc5cca98f12
|
4
|
+
data.tar.gz: 6df1988b72d7e206e11253cd80e6d1eed20ac506
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e427ccece01e33d3b1387246a92a73ff9c4d316ad5d77651fd1d67df0a95fbeddabd94bd2b152110f4d3f6e4aba8f2f374b2cb0c873bef1d7a975aadd1cd141
|
7
|
+
data.tar.gz: 1fab1178b3d77026e47e205a004ddb0c430172853e6b334c5b648cfeb642b3eef2b8f2a31a1a2480737f5041a74aaa377c6c2dca33dde602a4d7d743b59db310
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.ruby-gemset
|
6
|
+
.ruby-version
|
7
|
+
coverage
|
8
|
+
Gemfile.lock
|
9
|
+
InstalledFiles
|
10
|
+
lib/bundler/man
|
11
|
+
pkg
|
12
|
+
rdoc
|
13
|
+
spec/reports
|
14
|
+
tags
|
15
|
+
tags.*
|
16
|
+
test/tmp
|
17
|
+
test/version_tmp
|
18
|
+
tmp
|
19
|
+
|
20
|
+
# YARD artifacts
|
21
|
+
.yardoc
|
22
|
+
_yardoc
|
23
|
+
doc/
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Jonathan W. Zaleski
|
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.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Foundry
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/jzaleski/foundry.png?branch=master)](http://travis-ci.org/jzaleski/foundry)
|
4
|
+
[![Dependency Status](https://gemnasium.com/jzaleski/foundry.png)](https://gemnasium.com/jzaleski/foundry)
|
5
|
+
|
6
|
+
An application configuration gem that aims to keep it simple
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'foundry'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install foundry
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Loading from a local-file:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
Foundry::Configurator.configure(:file_name => 'path-to-local-file')
|
28
|
+
```
|
29
|
+
|
30
|
+
Loading from a HTTP/HTTPS endpoint:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
Foundry::Configurator.configure(:uri => 'http-or-https-endpoint')
|
34
|
+
```
|
35
|
+
|
36
|
+
Loading from a HTTP/HTTPS endpoint using "Basic Authentication":
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
Foundry::Configurator.configure(
|
40
|
+
:uri => 'http-or-https-endpoint',
|
41
|
+
:username => 'basic-auth-username',
|
42
|
+
:password => 'basic-auth-password'
|
43
|
+
)
|
44
|
+
```
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it ( http://github.com/jzaleski/foundry/fork )
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/TODO
ADDED
data/foundry.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'foundry/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'foundry'
|
8
|
+
gem.version = Foundry::VERSION
|
9
|
+
gem.authors = ['Jonathan W. Zaleski']
|
10
|
+
gem.email = ['JonathanZaleski@gmail.com']
|
11
|
+
gem.summary = %{An application configuration gem that aims to keep it simple}
|
12
|
+
gem.description = <<-EOL
|
13
|
+
Let's face it, there are a number of problems when application/environment
|
14
|
+
configuration logic is too tightly coupled with the configuration-data itself.
|
15
|
+
This gem aims to keep it simple and fully decouple the two concerns.
|
16
|
+
|
17
|
+
Features:
|
18
|
+
|
19
|
+
* Can load YAML from a local-file
|
20
|
+
* Can load YAML from a HTTP/HTTPS endpoint
|
21
|
+
* Supports Basic Authentication for HTTP{,S} endpoints
|
22
|
+
* Supports ERB interpolation
|
23
|
+
* Returns an easy to navigate object-graph
|
24
|
+
EOL
|
25
|
+
gem.homepage = 'https://github.com/jzaleski/foundry'
|
26
|
+
gem.license = 'MIT'
|
27
|
+
|
28
|
+
gem.files = `git ls-files`.split($/)
|
29
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |file| File.basename(file) }
|
30
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
31
|
+
gem.require_paths = ['lib']
|
32
|
+
|
33
|
+
gem.add_development_dependency 'bundler', '~> 1.6'
|
34
|
+
gem.add_development_dependency 'pry', '~> 0.10'
|
35
|
+
gem.add_development_dependency 'rake', '~> 10.3'
|
36
|
+
gem.add_development_dependency 'rspec', '~> 3.0'
|
37
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Foundry
|
2
|
+
class Configurator
|
3
|
+
class << self
|
4
|
+
def configure(opts={})
|
5
|
+
ostructify(
|
6
|
+
load_yaml(
|
7
|
+
evaluate_erb(
|
8
|
+
load_by_filename_or_uri(opts)
|
9
|
+
)
|
10
|
+
)
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def evaluate_erb(str)
|
17
|
+
ERB.new(str).result
|
18
|
+
end
|
19
|
+
|
20
|
+
def load_by_filename_or_uri(opts)
|
21
|
+
if file_name = opts.delete(:file_name)
|
22
|
+
Foundry::Loaders::File.load(file_name, opts)
|
23
|
+
elsif uri = opts.delete(:uri)
|
24
|
+
Foundry::Loaders::Uri.load(uri, opts)
|
25
|
+
else
|
26
|
+
raise NotImplementedError
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def load_yaml(str)
|
31
|
+
YAML.load(str)
|
32
|
+
end
|
33
|
+
|
34
|
+
def ostructify(object)
|
35
|
+
case object
|
36
|
+
when Array
|
37
|
+
object.map do |value|
|
38
|
+
ostructify(value)
|
39
|
+
end
|
40
|
+
when Hash
|
41
|
+
OpenStruct.new.tap do |ostruct|
|
42
|
+
object.each do |key, value|
|
43
|
+
ostruct.public_send("#{key}=", ostructify(value))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
else
|
47
|
+
object
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Foundry
|
2
|
+
module Loaders
|
3
|
+
class Uri
|
4
|
+
def self.load(uri, opts)
|
5
|
+
parsed_uri = URI.parse(uri)
|
6
|
+
http = Net::HTTP.new(parsed_uri.host, parsed_uri.port)
|
7
|
+
if parsed_uri.scheme == 'https'
|
8
|
+
http.use_ssl = true
|
9
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
10
|
+
end
|
11
|
+
request = Net::HTTP::Get.new(parsed_uri.request_uri)
|
12
|
+
if username = opts.delete(:username) && password = opts.delete(:password)
|
13
|
+
request.basic_auth(username, password)
|
14
|
+
end
|
15
|
+
http.request(request).body
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/foundry.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'foundry/configurator'
|
3
|
+
|
4
|
+
describe Foundry::Configurator do
|
5
|
+
subject { Foundry::Configurator }
|
6
|
+
|
7
|
+
it 'must be passed either a "file_name" or "uri"' do
|
8
|
+
expect { subject.configure }.to raise_error
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'will attempt to load from a file' do
|
12
|
+
expect(Foundry::Loaders::File).to receive(:load) { '' }
|
13
|
+
subject.configure(:file_name => '')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'will attempt to load from a uri' do
|
17
|
+
expect(Foundry::Loaders::Uri).to receive(:load) { '' }
|
18
|
+
subject.configure(:uri => '')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'will fail-fast if the YAML is invalid' do
|
22
|
+
expect(Foundry::Loaders::File).to receive(:load)
|
23
|
+
expect { subject.configure(:file_name => '') }.to raise_error
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'will fail-fast if the ERB raises an error' do
|
27
|
+
expect(Foundry::Loaders::File).to receive(:load) { 'foo: <%= 1/0 %>' }
|
28
|
+
expect { subject.configure(:file_name => '') }.to raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'can parse [nested] YAML/ERB' do
|
32
|
+
expect(Foundry::Loaders::File).to receive(:load) { <<-YAML
|
33
|
+
root:
|
34
|
+
erb: <%= 1 * 2 * 3 %>
|
35
|
+
float: 123.0
|
36
|
+
integer: 42
|
37
|
+
list:
|
38
|
+
- uno
|
39
|
+
- dos
|
40
|
+
- tres
|
41
|
+
string: hello world
|
42
|
+
YAML
|
43
|
+
}
|
44
|
+
expect(subject.configure(:file_name => '')).to eq(
|
45
|
+
OpenStruct.new(
|
46
|
+
'root' => OpenStruct.new(
|
47
|
+
'erb' => 6,
|
48
|
+
'float' => 123.0,
|
49
|
+
'integer' => 42,
|
50
|
+
'list' => %w[uno dos tres],
|
51
|
+
'string' => 'hello world'
|
52
|
+
)
|
53
|
+
)
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'foundry/loaders/file'
|
3
|
+
|
4
|
+
describe Foundry::Loaders::File do
|
5
|
+
subject { Foundry::Loaders::File }
|
6
|
+
|
7
|
+
it 'can load a file' do
|
8
|
+
expect(File).to receive(:read)
|
9
|
+
subject.load('', {})
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'will raise an error if the file does not exist' do
|
13
|
+
expect { subject.load('', {}) }.to raise_error
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'foundry/loaders/uri'
|
3
|
+
|
4
|
+
describe Foundry::Loaders::Uri do
|
5
|
+
subject { Foundry::Loaders::Uri }
|
6
|
+
let(:request) { double }
|
7
|
+
let(:response_body) { 'response_body' }
|
8
|
+
let(:response) { double(:body => response_body) }
|
9
|
+
let(:http) { double(:request => response) }
|
10
|
+
let(:http_url) { 'http://foo.bar.com' }
|
11
|
+
let(:https_url) { http_url.gsub(/\Ahttp:/, 'https:') }
|
12
|
+
|
13
|
+
before do
|
14
|
+
expect(Net::HTTP).to receive(:new) { http }
|
15
|
+
expect(Net::HTTP::Get).to receive(:new) { request }
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'can load from a HTTP endpoint' do
|
19
|
+
expect(subject.load(http_url, {})).to eq(response_body)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'can load from a HTTPS endpoint' do
|
23
|
+
expect(http).to receive_messages([:use_ssl=, :verify_mode=])
|
24
|
+
expect(subject.load(https_url, {})).to eq(response_body)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'can load from a endpoint using basic-auth' do
|
28
|
+
expect(request).to receive(:basic_auth)
|
29
|
+
expect(subject.load(
|
30
|
+
http_url, {
|
31
|
+
:username => 'basic_auth_username',
|
32
|
+
:password => 'basic_auth_password',
|
33
|
+
}
|
34
|
+
)).to eq(response_body)
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: foundry
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan W. Zaleski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: |2
|
70
|
+
Let's face it, there are a number of problems when application/environment
|
71
|
+
configuration logic is too tightly coupled with the configuration-data itself.
|
72
|
+
This gem aims to keep it simple and fully decouple the two concerns.
|
73
|
+
|
74
|
+
Features:
|
75
|
+
|
76
|
+
* Can load YAML from a local-file
|
77
|
+
* Can load YAML from a HTTP/HTTPS endpoint
|
78
|
+
* Supports Basic Authentication for HTTP{,S} endpoints
|
79
|
+
* Supports ERB interpolation
|
80
|
+
* Returns an easy to navigate object-graph
|
81
|
+
email:
|
82
|
+
- JonathanZaleski@gmail.com
|
83
|
+
executables: []
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files: []
|
86
|
+
files:
|
87
|
+
- ".gitignore"
|
88
|
+
- ".travis.yml"
|
89
|
+
- Gemfile
|
90
|
+
- LICENSE.txt
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- TODO
|
94
|
+
- foundry.gemspec
|
95
|
+
- lib/foundry.rb
|
96
|
+
- lib/foundry/configurator.rb
|
97
|
+
- lib/foundry/loaders/file.rb
|
98
|
+
- lib/foundry/loaders/uri.rb
|
99
|
+
- lib/foundry/version.rb
|
100
|
+
- spec/configurator_spec.rb
|
101
|
+
- spec/loaders/file_spec.rb
|
102
|
+
- spec/loaders/uri_spec.rb
|
103
|
+
- spec/spec_helper.rb
|
104
|
+
homepage: https://github.com/jzaleski/foundry
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.2.2
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: An application configuration gem that aims to keep it simple
|
128
|
+
test_files:
|
129
|
+
- spec/configurator_spec.rb
|
130
|
+
- spec/loaders/file_spec.rb
|
131
|
+
- spec/loaders/uri_spec.rb
|
132
|
+
- spec/spec_helper.rb
|