enver 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +4 -0
- data/enver.gemspec +24 -0
- data/lib/enver/core_ext/env.rb +2 -0
- data/lib/enver/extension.rb +11 -0
- data/lib/enver/loader.rb +61 -0
- data/lib/enver/version.rb +3 -0
- data/lib/enver.rb +8 -0
- data/spec/enver/core_ext/env_spec.rb +6 -0
- data/spec/enver/loader_spec.rb +65 -0
- data/spec/enver_spec.rb +15 -0
- data/spec/spec_helper.rb +89 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 075036799c1f050fcc176a1b2b4c5f33431399d7
|
4
|
+
data.tar.gz: 51523ea9a5f84fb0cb2169586f0c739f73db8952
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: af58c38f357f81e2b6af606a69e8e21d65030e99c740316e6546a08455d89b5d9225d18c96a68467db8a33a2a1676719b687573cc79abba7ead73366dee9c5ed
|
7
|
+
data.tar.gz: d8943785130e3c7f8d0aa733ff861598472fdc6d550ccf20b8ede80b44f7a7e90269405cf7636f3fdfd072bfd3d601549cc5fafe8f211b54daabb1964d6fa00c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 mashiro
|
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,49 @@
|
|
1
|
+
# Enver [![Build Status](https://travis-ci.org/mashiro/enver.svg)](https://travis-ci.org/mashiro/enver)
|
2
|
+
|
3
|
+
Minimal environment loader
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'enver'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install enver
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```bash
|
24
|
+
export CLIENT_KEY=xxx
|
25
|
+
export CLIENT_SECRET=yyy
|
26
|
+
export SERVERS=4
|
27
|
+
```
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
env = Enver.load do
|
31
|
+
string :client_key, 'CLIENT_KEY'
|
32
|
+
string :client_secret, 'CLIENT_SECRET'
|
33
|
+
integer :servers, 'SERVERS'
|
34
|
+
array :path, 'PATH', pattern: ':'
|
35
|
+
end
|
36
|
+
|
37
|
+
env.client_key # => 'xxx'
|
38
|
+
env.client_secret # => 'yyy'
|
39
|
+
env.servers # => 4
|
40
|
+
env.path # => array of your paths
|
41
|
+
```
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it ( https://github.com/[my-github-username]/enver/fork )
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/enver.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'enver/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "enver"
|
8
|
+
spec.version = Enver::VERSION
|
9
|
+
spec.authors = ["mashiro"]
|
10
|
+
spec.email = ["mail@mashiro.org"]
|
11
|
+
spec.summary = %q{Minimal environment loader.}
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.1.0"
|
24
|
+
end
|
data/lib/enver/loader.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module Enver
|
4
|
+
class Loader
|
5
|
+
attr_reader :store
|
6
|
+
|
7
|
+
def initialize(env, &block)
|
8
|
+
@env = env
|
9
|
+
@store = OpenStruct.new
|
10
|
+
instance_eval(&block) if block
|
11
|
+
end
|
12
|
+
|
13
|
+
def value(name, env_name, options = {})
|
14
|
+
value = fetch env_name, options
|
15
|
+
@store.send("#{name}=", value.is_a?(String) ? yield(value) : value)
|
16
|
+
end
|
17
|
+
|
18
|
+
def string(name, env_name, options = {})
|
19
|
+
value(name, env_name, options) do |v|
|
20
|
+
v
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def integer(name, env_name, options = {})
|
25
|
+
value(name, env_name, options) do |v|
|
26
|
+
Integer(v)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def float(name, env_name, options = {})
|
31
|
+
value(name, env_name, options) do |v|
|
32
|
+
Float(v)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def boolean(name, env_name, options = {})
|
37
|
+
value(name, env_name, options) do |v|
|
38
|
+
true_values = options[:true_values] || %w(1 t true y yes)
|
39
|
+
true_values.include?(v)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def array(name, env_name, options = {})
|
44
|
+
value(name, env_name, options) do |v|
|
45
|
+
pattern = options[:pattern] || ','
|
46
|
+
limit = options[:limit] || 0
|
47
|
+
v.split(pattern, limit)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def fetch(env_name, options = {})
|
54
|
+
if options.has_key? :default
|
55
|
+
@env.fetch(env_name, options[:default])
|
56
|
+
else
|
57
|
+
@env.fetch(env_name)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/enver.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
RSpec.describe Enver::Loader do
|
5
|
+
let(:env) do
|
6
|
+
{
|
7
|
+
'STRING1' => '',
|
8
|
+
'STRING2' => 'test',
|
9
|
+
'INTEGER1' => '',
|
10
|
+
'INTEGER2' => '1',
|
11
|
+
'INTEGER3' => '1.0',
|
12
|
+
'INTEGER4' => '123test',
|
13
|
+
'BOOLEAN1' => '',
|
14
|
+
'BOOLEAN2' => '1',
|
15
|
+
'BOOLEAN3' => '0',
|
16
|
+
'BOOLEAN4' => 't',
|
17
|
+
'BOOLEAN5' => 'f',
|
18
|
+
'BOOLEAN6' => 'true',
|
19
|
+
'BOOLEAN7' => 'false',
|
20
|
+
'BOOLEAN8' => 'yes',
|
21
|
+
'BOOLEAN9' => 'no',
|
22
|
+
'BOOLEAN10' => 'はい',
|
23
|
+
'ARRAY1' => 'foo,bar,buzz',
|
24
|
+
'ARRAY2' => 'foo:bar:buzz',
|
25
|
+
}
|
26
|
+
end
|
27
|
+
let(:loader) { Enver::Loader.new(env) }
|
28
|
+
|
29
|
+
describe '#fetch' do
|
30
|
+
it { expect{loader.send(:fetch, 'NOTHING')}.to raise_error }
|
31
|
+
it { expect(loader.send(:fetch, 'NOTHING', default: 123)).to eq(123) }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#string' do
|
35
|
+
it { expect(loader.string('v', 'STRING1')).to eq('') }
|
36
|
+
it { expect(loader.string('v', 'STRING2')).to eq('test') }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#integer' do
|
40
|
+
it { expect{loader.integer('v', 'INTEGER1')}.to raise_error }
|
41
|
+
it { expect(loader.integer('v', 'INTEGER2')).to eq(1) }
|
42
|
+
it { expect{loader.integer('v', 'INTEGER3')}.to raise_error }
|
43
|
+
it { expect{loader.integer('v', 'INTEGER4')}.to raise_error }
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#boolean' do
|
47
|
+
it { expect(loader.boolean('v', 'BOOLEAN1')).to eq(false) }
|
48
|
+
it { expect(loader.boolean('v', 'BOOLEAN2')).to eq(true) }
|
49
|
+
it { expect(loader.boolean('v', 'BOOLEAN3')).to eq(false) }
|
50
|
+
it { expect(loader.boolean('v', 'BOOLEAN4')).to eq(true) }
|
51
|
+
it { expect(loader.boolean('v', 'BOOLEAN5')).to eq(false) }
|
52
|
+
it { expect(loader.boolean('v', 'BOOLEAN6')).to eq(true) }
|
53
|
+
it { expect(loader.boolean('v', 'BOOLEAN7')).to eq(false) }
|
54
|
+
it { expect(loader.boolean('v', 'BOOLEAN8')).to eq(true) }
|
55
|
+
it { expect(loader.boolean('v', 'BOOLEAN9')).to eq(false) }
|
56
|
+
it { expect(loader.boolean('v', 'BOOLEAN10')).to eq(false) }
|
57
|
+
it { expect(loader.boolean('v', 'BOOLEAN10', true_values: %w(はい))).to eq(true) }
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#array' do
|
61
|
+
it { expect(loader.array('v', 'ARRAY1')).to eq(['foo', 'bar', 'buzz']) }
|
62
|
+
it { expect(loader.array('v', 'ARRAY2', pattern: ':')).to eq(['foo', 'bar', 'buzz']) }
|
63
|
+
it { expect(loader.array('v', 'ARRAY1', limit: 2)).to eq(['foo', 'bar,buzz']) }
|
64
|
+
end
|
65
|
+
end
|
data/spec/enver_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
10
|
+
# a separate helper file that requires the additional dependencies and performs
|
11
|
+
# the additional setup, and require it from the spec files that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
require 'enver'
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# rspec-expectations config goes here. You can use an alternate
|
21
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
|
+
# assertions if you prefer.
|
23
|
+
config.expect_with :rspec do |expectations|
|
24
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
25
|
+
# and `failure_message` of custom matchers include text for helper methods
|
26
|
+
# defined using `chain`, e.g.:
|
27
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
28
|
+
# # => "be bigger than 2 and smaller than 4"
|
29
|
+
# ...rather than:
|
30
|
+
# # => "be bigger than 2"
|
31
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
32
|
+
end
|
33
|
+
|
34
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
35
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
36
|
+
config.mock_with :rspec do |mocks|
|
37
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
38
|
+
# a real object. This is generally recommended, and will default to
|
39
|
+
# `true` in RSpec 4.
|
40
|
+
mocks.verify_partial_doubles = true
|
41
|
+
end
|
42
|
+
|
43
|
+
# The settings below are suggested to provide a good initial experience
|
44
|
+
# with RSpec, but feel free to customize to your heart's content.
|
45
|
+
# These two settings work together to allow you to limit a spec run
|
46
|
+
# to individual examples or groups you care about by tagging them with
|
47
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
48
|
+
# get run.
|
49
|
+
config.filter_run :focus
|
50
|
+
config.run_all_when_everything_filtered = true
|
51
|
+
|
52
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
53
|
+
# For more details, see:
|
54
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
55
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
56
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
57
|
+
config.disable_monkey_patching!
|
58
|
+
|
59
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
60
|
+
# be too noisy due to issues in dependencies.
|
61
|
+
config.warnings = true
|
62
|
+
|
63
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
64
|
+
# file, and it's useful to allow more verbose output when running an
|
65
|
+
# individual spec file.
|
66
|
+
if config.files_to_run.one?
|
67
|
+
# Use the documentation formatter for detailed output,
|
68
|
+
# unless a formatter has already been configured
|
69
|
+
# (e.g. via a command-line flag).
|
70
|
+
config.default_formatter = 'doc'
|
71
|
+
end
|
72
|
+
|
73
|
+
# Print the 10 slowest examples and example groups at the
|
74
|
+
# end of the spec run, to help surface which specs are running
|
75
|
+
# particularly slow.
|
76
|
+
#config.profile_examples = 10
|
77
|
+
|
78
|
+
# Run specs in random order to surface order dependencies. If you find an
|
79
|
+
# order dependency and want to debug it, you can fix the order by providing
|
80
|
+
# the seed, which is printed after each run.
|
81
|
+
# --seed 1234
|
82
|
+
config.order = :random
|
83
|
+
|
84
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
85
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
86
|
+
# test failures related to randomization by passing the same `--seed` value
|
87
|
+
# as the one that triggered the failure.
|
88
|
+
Kernel.srand config.seed
|
89
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: enver
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- mashiro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-02 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.1.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.1.0
|
55
|
+
description: Minimal environment loader.
|
56
|
+
email:
|
57
|
+
- mail@mashiro.org
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- enver.gemspec
|
70
|
+
- lib/enver.rb
|
71
|
+
- lib/enver/core_ext/env.rb
|
72
|
+
- lib/enver/extension.rb
|
73
|
+
- lib/enver/loader.rb
|
74
|
+
- lib/enver/version.rb
|
75
|
+
- spec/enver/core_ext/env_spec.rb
|
76
|
+
- spec/enver/loader_spec.rb
|
77
|
+
- spec/enver_spec.rb
|
78
|
+
- spec/spec_helper.rb
|
79
|
+
homepage: ''
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.2.2
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Minimal environment loader.
|
103
|
+
test_files:
|
104
|
+
- spec/enver/core_ext/env_spec.rb
|
105
|
+
- spec/enver/loader_spec.rb
|
106
|
+
- spec/enver_spec.rb
|
107
|
+
- spec/spec_helper.rb
|