env_vars 0.1.0

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: 368e36e6240a71436160986bc86c3f5786326ff5
4
+ data.tar.gz: 3ae9767e8a829132ac2de6d9a3ac1be24eba7167
5
+ SHA512:
6
+ metadata.gz: 38c614ff2ef3fca9d383e48ddb32d66cfcd60ec642ac30dae87814e5bd709fbcb2712a3b98b51b1d3d297625bfed40bc9062ec555b75add65f7c76337d48001d
7
+ data.tar.gz: d4c12e33c27915af3849fb7b4eace234e915d4c1e8555ff312fc7ed9881bdb3f179290c7f3c18530896ec3f439b84ccaa12db4e15a1bdce8912e72effcb21f83
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ cache: bundler
3
+ sudo: false
4
+ notifications:
5
+ email: false
6
+ rvm:
7
+ - 2.2.2
8
+ before_install: gem install bundler
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Nando Vieira
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Env::Vars
2
+
3
+ [![build status](https://travis-ci.org/fnando/env_vars.svg)](https://travis-ci.org/fnando/env_vars)
4
+
5
+ Access environment variables. Also includes presence validation, type coercion and default values.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'env_vars'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install env_vars
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ Config = Env::Vars.new do
27
+ mandatory :database_url, string
28
+ optional :timeout, int, 10
29
+ optional :force_ssl, bool, false
30
+ end
31
+
32
+ Config.database_url
33
+ Config.timeout
34
+ Config.force_ssl?
35
+ ```
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+
41
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fnando/env_vars. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
46
+
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
51
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/env_vars.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ require File.expand_path('../lib/env_vars', __FILE__)
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'env_vars'
5
+ spec.version = Env::Vars::VERSION
6
+ spec.authors = ['Nando Vieira']
7
+ spec.email = ['fnando.vieira@gmail.com']
8
+
9
+ spec.summary = 'Access environment variables. Also includes presence validation, type coercion and default values.'
10
+ spec.description = spec.summary
11
+ spec.homepage = 'https://github.com/fnando/env_vars'
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
+ spec.require_paths = ['lib']
17
+
18
+ spec.add_development_dependency 'bundler', '~> 1.10'
19
+ spec.add_development_dependency 'rake', '~> 10.0'
20
+ spec.add_development_dependency 'minitest'
21
+ spec.add_development_dependency 'minitest-utils'
22
+ end
data/lib/env_vars.rb ADDED
@@ -0,0 +1,58 @@
1
+ module Env
2
+ class Vars
3
+ VERSION = '0.1.0'
4
+ BOOL_TRUE = ['yes', 'true', '1', true]
5
+ BOOL_FALSE = ['no', 'false']
6
+
7
+ MissingEnvironmentVariable = Class.new(StandardError)
8
+
9
+ def initialize(&block)
10
+ instance_eval(&block)
11
+ end
12
+
13
+ def set(name, type, default = nil, required: false)
14
+ name = name.to_s
15
+ env_var = name.upcase
16
+ name = "#{name}?" if type == bool
17
+
18
+ validate!(env_var, required)
19
+
20
+ define_singleton_method(name) do
21
+ value = ENV[env_var] || default
22
+
23
+ case type
24
+ when bool
25
+ BOOL_TRUE.include?(value)
26
+ when int
27
+ Integer(value) if !BOOL_FALSE.include?(value) && value
28
+ else
29
+ value
30
+ end
31
+ end
32
+ end
33
+
34
+ def validate!(env_var, required)
35
+ raise MissingEnvironmentVariable, "#{env_var} is not defined" if required && !ENV.key?(env_var)
36
+ end
37
+
38
+ def mandatory(name, type)
39
+ set(name, type, required: true)
40
+ end
41
+
42
+ def optional(name, type, default = nil)
43
+ set(name, type, default)
44
+ end
45
+
46
+ def int
47
+ :int
48
+ end
49
+
50
+ def string
51
+ :string
52
+ end
53
+
54
+ def bool
55
+ :bool
56
+ end
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: env_vars
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nando Vieira
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-13 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-utils
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Access environment variables. Also includes presence validation, type
70
+ coercion and default values.
71
+ email:
72
+ - fnando.vieira@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - env_vars.gemspec
85
+ - lib/env_vars.rb
86
+ homepage: https://github.com/fnando/env_vars
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.6
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Access environment variables. Also includes presence validation, type coercion
110
+ and default values.
111
+ test_files: []