env_inquiry 0.5.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: ea9175faad2a8d5250bb437f60b80531a337679c
4
+ data.tar.gz: b63a477e9bf305704e1c905665b92490a6f2680f
5
+ SHA512:
6
+ metadata.gz: f80ea761717701a1ce9a9b4e86491a872bbfc6756e919a6eafefaa50a776f2380ee14c75b72333c76ed0562e620dbadfbcfd8b7a3324fb2c34d405a8d1ce8835
7
+ data.tar.gz: f617d02bc5580975081a626c111af5d61b61d401416449d327ac91a78a6d782a63ce3caebd5704b2499b03ed899db4b91a57d6aad026b8e640d22cdb627cbecb
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in env_inquiry.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 MTL Dev
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,47 @@
1
+ # EnvInquiry
2
+
3
+ Use dot notation to access ENV vars. A handy companion to dotenv-* gems
4
+
5
+ EnvInquiry::Env.https_enabled? instead of ENV['HTTPS_ENABLED'] == 'true'
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'env_inquiry'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install env_inquiry
20
+
21
+ In Rails (optional)
22
+
23
+ ```
24
+ # auto-load in config/initializers/whatever.rb
25
+ require 'env_inquiry'
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ```
31
+ EnvInquiry::Env.https_enabled?
32
+ # feel free to shorten in your app with something like:
33
+ Env = EnvInquiry::Env
34
+ Env.https_enabled?
35
+ ```
36
+
37
+ ## Run Tests
38
+
39
+ $ bundle exec rspec spec
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( http://github.com/servicient/env_inquiry/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -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 'env_inquiry/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "env_inquiry"
8
+ spec.version = EnvInquiry::VERSION
9
+ spec.authors = ["MTL Dev", "Luke Wendling"]
10
+ spec.email = ["dev@mytennislessons.com"]
11
+ spec.summary = %q{Use dot notation to access ENV vars}
12
+ spec.description = %q{Use dot notation to access ENV vars. A handy companion to dotenv-* gems}
13
+ spec.homepage = "http://github.com/servicient/env_inquiry"
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.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 2.14"
24
+ end
@@ -0,0 +1,3 @@
1
+ module EnvInquiry
2
+ VERSION = "0.5.0"
3
+ end
@@ -0,0 +1,56 @@
1
+ require "env_inquiry/version"
2
+
3
+ module EnvInquiry
4
+
5
+ class Env
6
+ class << self
7
+ def env
8
+ ENV
9
+ end
10
+
11
+ # return nil for any class methods not defined
12
+ # same as calling ENV['<missing_key>'] would
13
+ def method_missing(name)
14
+ return nil
15
+ end
16
+
17
+ def inquire
18
+ env.each_pair do |k,v|
19
+ name = k.downcase
20
+
21
+ # wrap env keys as singleton methods on class.
22
+ # returns bools for 'true', 'false'
23
+ define_singleton_method(name.to_sym) do
24
+ case v.to_s.downcase
25
+ when 'true'
26
+ true
27
+ when 'false'
28
+ false
29
+ else
30
+ v
31
+ end
32
+ end
33
+
34
+ # define inspection method (method?)
35
+ # true if value is 'true'
36
+ # false if value is 'false'
37
+ # true if a 'present' value
38
+ define_singleton_method("#{name}?".to_sym) do
39
+ case v.to_s.downcase
40
+ when 'true'
41
+ true
42
+ when 'false'
43
+ false
44
+ else
45
+ v.to_s.strip != ''
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ # inquire of the ENV
53
+ self.inquire
54
+ end
55
+
56
+ end
@@ -0,0 +1,36 @@
1
+ require "env_inquiry"
2
+
3
+ describe EnvInquiry::Env do
4
+
5
+ let(:env_vars) do
6
+ {'KEY1' => 'abc', 'KEY2' => 'false', 'KEY3' => 'true', 'KEY4' => nil}
7
+ end
8
+
9
+ before(:each) do
10
+ EnvInquiry::Env.stub(env: env_vars)
11
+ EnvInquiry::Env.inquire
12
+ end
13
+
14
+ it 'wraps env var key in dot notation' do
15
+ expect(EnvInquiry::Env.key1).to eq 'abc'
16
+ end
17
+
18
+ it 'returns true for valid env var' do
19
+ expect(EnvInquiry::Env.key1?).to be true
20
+ end
21
+
22
+ it 'returns nil for invalid key' do
23
+ expect(EnvInquiry::Env.invalid_key).to be_nil
24
+ end
25
+
26
+ it 'returns nil for nil env var' do
27
+ expect(EnvInquiry::Env.key4).to be_nil
28
+ end
29
+
30
+ it 'converts string value to boolean' do
31
+ expect(EnvInquiry::Env.key2).to be false
32
+ expect(EnvInquiry::Env.key2?).to be false
33
+ expect(EnvInquiry::Env.key3).to be true
34
+ expect(EnvInquiry::Env.key3?).to be true
35
+ end
36
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: env_inquiry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - MTL Dev
8
+ - Luke Wendling
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-06-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.5'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.5'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '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: '2.14'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '2.14'
56
+ description: Use dot notation to access ENV vars. A handy companion to dotenv-* gems
57
+ email:
58
+ - dev@mytennislessons.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - env_inquiry.gemspec
69
+ - lib/env_inquiry.rb
70
+ - lib/env_inquiry/version.rb
71
+ - spec/env_inquiry_spec.rb
72
+ homepage: http://github.com/servicient/env_inquiry
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.2.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Use dot notation to access ENV vars
96
+ test_files:
97
+ - spec/env_inquiry_spec.rb