schrank 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +6 -0
- data/lib/schrank.rb +56 -0
- data/lib/schrank/version.rb +3 -0
- data/schrank.gemspec +27 -0
- data/spec/schrank_spec.rb +79 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/support/uses_tmp_dir.rb +12 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1bc6aa17924df10b2ea5c26ed7b992f5ed8981c0
|
4
|
+
data.tar.gz: 7d6aabfbad460abd3cdf6241709bb86f28a765c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9c85dc98a2ca78c584b0e1da1566204cea981f1895062bfec70ffc0223a0145d5493c013164debeadd6ed289ea1be7936319a83f549c8735309aa766fda1daf5
|
7
|
+
data.tar.gz: 6490da451b4f758c5357df0e01384ff617c5aade9cb5b890c415fd20243a40ba5604a24b4b08b1a16e6af08415ab5cb453fe377bf477a6a5042a8106201c6e90
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at [opensource@tape.tv](mailto:opensource@tape.tv).
|
59
|
+
All complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 tape.tv AG
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Schrank
|
2
|
+
|
3
|
+
A simple YAML config file loader.
|
4
|
+
|
5
|
+
[![Build](https://travis-ci.org/tape-tv/schrank.svg?branch=master)](https://travis-ci.org/tape-tv/schrank)
|
6
|
+
[![Docs](https://inch-ci.org/github/tape-tv/schrank.svg?branch=master)](https://inch-ci.org/github/tape-tv/schrank)
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
require 'schrank'
|
12
|
+
```
|
13
|
+
|
14
|
+
Load your config, providing defaults.
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
config = Schrank.load(Rails.root.join('config/production.yml')) do
|
18
|
+
{
|
19
|
+
provider: 's3',
|
20
|
+
prefix: 'folder/'
|
21
|
+
}
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
See [the docs](http://www.rubydoc.info/github/tape-tv/schrank/master) for more details.
|
26
|
+
|
27
|
+
## License
|
28
|
+
|
29
|
+
MIT.
|
30
|
+
|
31
|
+
## Contribution
|
32
|
+
|
33
|
+
Contributions welcome! Create a pull request and we'll get back to you as soon as
|
34
|
+
possible. Open an issue to discuss anything big.
|
35
|
+
|
36
|
+
This project has a code of conduct, found in the root of this repo. Please read it
|
37
|
+
before contributing.
|
data/Rakefile
ADDED
data/lib/schrank.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'schrank/version'
|
2
|
+
require 'yaml'
|
3
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
4
|
+
|
5
|
+
# Namespace module.
|
6
|
+
module Schrank
|
7
|
+
# Attempts to load YAML file. Falls back on defaults
|
8
|
+
# hash when file is not found.
|
9
|
+
#
|
10
|
+
# In development mode, the defaults hash is merged
|
11
|
+
# with the YAML file, with the file taking precedence.
|
12
|
+
# This is intentional, since it allows shared config
|
13
|
+
# to live in your application source code, but
|
14
|
+
# per-user secrets (such as access keys) can be kept
|
15
|
+
# in a file and out of version control.
|
16
|
+
#
|
17
|
+
# @example Simply load your config.
|
18
|
+
# config = Schrank.load(Rails.root.join('config/production.yml'))
|
19
|
+
#
|
20
|
+
# @example Load your config, providing defaults.
|
21
|
+
# config = Schrank.load(Rails.root.join('config/production.yml')) do
|
22
|
+
# {
|
23
|
+
# provider: 's3',
|
24
|
+
# prefix: 'folder/'
|
25
|
+
# }
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# @param [String] path The path to the config file
|
29
|
+
# @yieldreturn [Hash] Default config
|
30
|
+
# @return [ActiveSupport::HashWithIndifferentAccess]
|
31
|
+
def self.load(path, &defaults)
|
32
|
+
config = {}
|
33
|
+
|
34
|
+
if yaml_path(path).exist?
|
35
|
+
config.merge!(defaults.call) if defaults && development?
|
36
|
+
config.merge!(YAML.load(yaml_path(path).open('r:utf-8')))
|
37
|
+
else
|
38
|
+
puts "[Schrank] Could not find config file at #{path}, loading defaults..."
|
39
|
+
config.merge!(defaults.call) if defaults
|
40
|
+
end
|
41
|
+
|
42
|
+
config.with_indifferent_access
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns true when the application is in development mode, otherwise returns false.
|
46
|
+
#
|
47
|
+
# @return [Boolean]
|
48
|
+
def self.development?
|
49
|
+
((defined?(Rails) && Rails.env) || ENV['RACK_ENV'] || ENV['APP_ENV']) == 'development'
|
50
|
+
end
|
51
|
+
|
52
|
+
# @private
|
53
|
+
def self.yaml_path(path)
|
54
|
+
Pathname.new(path)
|
55
|
+
end
|
56
|
+
end
|
data/schrank.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'schrank/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'schrank'
|
9
|
+
spec.version = Schrank::VERSION
|
10
|
+
spec.authors = ['Christof Dorner', 'Joe Corcoran']
|
11
|
+
spec.email = ['opensource@tape.tv']
|
12
|
+
spec.summary = 'Simply load YAML configuration files'
|
13
|
+
spec.description = %Q{A simple tool that helps you to load YAML config
|
14
|
+
files, with specifics to help you in development mode.
|
15
|
+
}
|
16
|
+
spec.homepage = 'https://github.com/tape-tv/schrank'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
spec.files = `git ls-files -z`.split("\x0")
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_dependency 'activesupport', '~> 4.0'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3'
|
26
|
+
spec.add_development_dependency 'yard', '~> 0.8'
|
27
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Schrank do
|
4
|
+
subject { Schrank }
|
5
|
+
|
6
|
+
describe '.yaml_path' do
|
7
|
+
let(:path) { '/tmp/config.yml' }
|
8
|
+
|
9
|
+
it 'returns a Pathname' do
|
10
|
+
expect(subject.yaml_path(path)).to be_instance_of(Pathname)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'initializes a new Pathname with the passed-in path' do
|
14
|
+
expect(Pathname).to receive(:new).with(path)
|
15
|
+
|
16
|
+
subject.yaml_path(path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '.load' do
|
21
|
+
include_context :uses_tmp_dir
|
22
|
+
|
23
|
+
let(:path) { File.join(tmp_dir, 'config.yml') }
|
24
|
+
|
25
|
+
context 'when the passed-in file path exists' do
|
26
|
+
before do
|
27
|
+
File.write(path, YAML.dump({
|
28
|
+
foo: 'bar',
|
29
|
+
'bar' => 'baz',
|
30
|
+
baz: 42
|
31
|
+
}))
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'returns a correct hash based on the YAML' do
|
35
|
+
expect(subject.load(path)).to eq({
|
36
|
+
'foo' => 'bar',
|
37
|
+
'bar' => 'baz',
|
38
|
+
'baz' => 42
|
39
|
+
})
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'allows indifferent access' do
|
43
|
+
expect(subject.load(path)['foo']).to eq('bar')
|
44
|
+
expect(subject.load(path)[:foo]).to eq('bar')
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'defaults' do
|
48
|
+
it 'merges defaults with values from file in development environment' do
|
49
|
+
allow(subject).to receive(:development?) { true }
|
50
|
+
|
51
|
+
config = subject.load(path) do
|
52
|
+
{ foo: 'baz', qux: 'quux' }
|
53
|
+
end
|
54
|
+
|
55
|
+
expect(config[:foo]).to eq('bar')
|
56
|
+
expect(config[:qux]).to eq('quux')
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'does not use the defaults in other environments' do
|
60
|
+
config = subject.load(path) do
|
61
|
+
{ foo: 'baz', qux: 'quux' }
|
62
|
+
end
|
63
|
+
|
64
|
+
expect(config[:foo]).to eq('bar')
|
65
|
+
expect(config[:qux]).to eq(nil)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
context 'when the passed-in file path is missing' do
|
72
|
+
it 'uses the default' do
|
73
|
+
expect(subject.load(path) do
|
74
|
+
{ 'foo' => 'baz' }
|
75
|
+
end[:foo]).to eq('baz')
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'schrank'
|
3
|
+
|
4
|
+
Dir[File.expand_path('../support/*.rb', __FILE__)].sort.each do |file_path|
|
5
|
+
require file_path
|
6
|
+
end
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.filter_run :focus
|
10
|
+
config.run_all_when_everything_filtered = true
|
11
|
+
|
12
|
+
if config.files_to_run.one?
|
13
|
+
config.default_formatter = 'doc'
|
14
|
+
end
|
15
|
+
|
16
|
+
config.profile_examples = 10
|
17
|
+
|
18
|
+
config.order = :random
|
19
|
+
Kernel.srand config.seed
|
20
|
+
|
21
|
+
config.expect_with :rspec do |expectations|
|
22
|
+
expectations.syntax = :expect
|
23
|
+
end
|
24
|
+
|
25
|
+
config.mock_with :rspec do |mocks|
|
26
|
+
mocks.syntax = :expect
|
27
|
+
mocks.verify_partial_doubles = true
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: schrank
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christof Dorner
|
8
|
+
- Joe Corcoran
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-02-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '4.0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '4.0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: yard
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0.8'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.8'
|
70
|
+
description: "A simple tool that helps you to load YAML config\nfiles, with specifics
|
71
|
+
to help you in development mode.\n "
|
72
|
+
email:
|
73
|
+
- opensource@tape.tv
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".travis.yml"
|
81
|
+
- CODE_OF_CONDUCT.md
|
82
|
+
- Gemfile
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- lib/schrank.rb
|
87
|
+
- lib/schrank/version.rb
|
88
|
+
- schrank.gemspec
|
89
|
+
- spec/schrank_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
- spec/support/uses_tmp_dir.rb
|
92
|
+
homepage: https://github.com/tape-tv/schrank
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.4.5.1
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Simply load YAML configuration files
|
116
|
+
test_files:
|
117
|
+
- spec/schrank_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
- spec/support/uses_tmp_dir.rb
|
120
|
+
has_rdoc:
|