conf_loader 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 25492b776e0ca7cfb529e5e4a7ba8a6cd6bbf4b9
4
+ data.tar.gz: 8007d6e02988736c9523ae27544b3f51919e945f
5
+ SHA512:
6
+ metadata.gz: de1cbfc5185d4c508e05626893e13aaefc56013caadcab778bc6727af5620f05d5fcc5f797057fcd769ffdc9603b9e23f30dd9796747df3aa594c0e04de3e2bf
7
+ data.tar.gz: f44ba29df38814cd83e0b18258d3c3006c2da6cc5cb607e5f12d1231a5d7b16ae42810dd59edb5d4923875a7cc7edf88db0ae59b9a6526a0551d3eb0897be98a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
17
+ Gemfile.lock
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ config_loader
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ before_script:
5
+ - bundle
6
+ script: bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :development, :test do
4
+ gem 'rspec'
5
+ end
6
+
7
+ group :metrics do
8
+ gem 'flay'
9
+ gem 'flog'
10
+ gem 'reek'
11
+ end
12
+
13
+ # Specify your gem's dependencies in conf_loader.gemspec
14
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Indrek Juhkam
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,26 @@
1
+ # ConfLoader
2
+
3
+ [![Build Status](https://travis-ci.org/salemove/conf_loader.svg?branch=master)](https://travis-ci.org/salemove/conf_loader)
4
+ [![Code Climate](https://codeclimate.com/github/salemove/conf_loader.png)](https://codeclimate.com/github/salemove/conf_loader)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'conf_loader'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ ## Usage
17
+
18
+ See `spec/integration` directory.
19
+
20
+ ## Contributing
21
+
22
+ 1. Fork it
23
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
24
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
25
+ 4. Push to the branch (`git push origin my-new-feature`)
26
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task ci: :spec
7
+ task default: :spec
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'conf_loader/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'conf_loader'
8
+ spec.version = ConfLoader::VERSION
9
+ spec.authors = ['Indrek Juhkam']
10
+ spec.email = ['indrek@salemove.com']
11
+ spec.description = %q{}
12
+ spec.summary = %q{Helps to load conf files in SaleMove ecosystem}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'symbolizer', '~> 0.0.1'
22
+ end
@@ -0,0 +1,25 @@
1
+ require 'yaml'
2
+ require 'symbolizer'
3
+ require 'erb'
4
+
5
+ # Helps to load conf files in salemove ecosystem
6
+ #
7
+ class ConfLoader
8
+ # Load given conf file
9
+ #
10
+ # @path [String] path
11
+ # full path to conf
12
+ # @path [String] env
13
+ # environment to load
14
+ #
15
+ # @return [Hash]
16
+ # hash with symbolized keys
17
+ #
18
+ # @api public
19
+ def self.load(path, env)
20
+ template = ERB.new File.new(path).read
21
+ environments = YAML.load template.result(binding)
22
+ hash = environments[env]
23
+ Symbolizer.symbolize(hash)
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ class ConfLoader
2
+ VERSION = '0.2.1'
3
+ end
@@ -0,0 +1,12 @@
1
+ development:
2
+ some_service:
3
+ host: localhost
4
+
5
+ production:
6
+ some_service:
7
+ host: some_service.production.com
8
+
9
+ flexible:
10
+ foo: <%= ENV['FOO'] %>
11
+ var_with_default_not_in_env: <%= ENV['SOME_VAR_NOT_IN_ENV'] || 'default_value' %>
12
+ var_with_default_in_env: <%= ENV['FOO'] || 'default_value' %>
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe ConfLoader do
4
+ let(:path) { File.dirname(__FILE__) + '/../fixtures/simple.yml' }
5
+
6
+ context 'conf loaded with production deployment setting' do
7
+
8
+ let(:conf) { described_class.load(path, 'production') }
9
+
10
+ it 'exposes production value' do
11
+ expect(conf[:some_service]).to eq(host: 'some_service.production.com')
12
+ end
13
+ end
14
+
15
+ context 'conf loaded with development deployment setting' do
16
+
17
+ let(:conf) { described_class.load(path, 'development') }
18
+
19
+ it 'exposes development value' do
20
+ expect(conf[:some_service]).to eq(host: 'localhost')
21
+ end
22
+ end
23
+
24
+ context 'with ENV variables declared' do
25
+
26
+ let(:conf) { described_class.load(path, 'flexible') }
27
+
28
+ before do
29
+ ENV['FOO'] = 'foo-value'
30
+ end
31
+
32
+ it 'exposes ENV defined value' do
33
+ expect(conf[:foo]).to eq('foo-value')
34
+ end
35
+
36
+ it 'exposes undefined ENV values as nil' do
37
+ expect(conf[:undefined_val]).to be_nil
38
+ end
39
+
40
+ it 'exposes default value when ENV value not supplied' do
41
+ expect(conf[:var_with_default_not_in_env]).to eq('default_value')
42
+ end
43
+
44
+ it 'skips default value when ENV value supplied' do
45
+ expect(conf[:var_with_default_in_env]).to eq('foo-value')
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1 @@
1
+ require 'conf_loader'
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe ConfLoader do
4
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: conf_loader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Indrek Juhkam
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: symbolizer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.1
27
+ description: ''
28
+ email:
29
+ - indrek@salemove.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".ruby-gemset"
36
+ - ".ruby-version"
37
+ - ".travis.yml"
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - conf_loader.gemspec
43
+ - lib/conf_loader.rb
44
+ - lib/conf_loader/version.rb
45
+ - spec/fixtures/simple.yml
46
+ - spec/integration/conf_loader_spec.rb
47
+ - spec/spec_helper.rb
48
+ - spec/unit/conf_loader_spec.rb
49
+ homepage: ''
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.4.5.1
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Helps to load conf files in SaleMove ecosystem
73
+ test_files:
74
+ - spec/fixtures/simple.yml
75
+ - spec/integration/conf_loader_spec.rb
76
+ - spec/spec_helper.rb
77
+ - spec/unit/conf_loader_spec.rb