env_var 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cf94c00f2ffad7cd60e6b0bb8ddc64244e99aadb4428cf55dc745f08a98b6bee
4
+ data.tar.gz: d43462325182d35213fcd594af9905f6a349d952ac0fd67d10fc939b5c1f401a
5
+ SHA512:
6
+ metadata.gz: 4bc26fe36791b206c4e57e5c3f53be6f7f121265fd0703d33d7d14e8753345590385064ea6ce82c858defe08d291a0fc0513ee8337591d3dfaeb998f7a8612b1
7
+ data.tar.gz: 3f2e3f1a4e27da95c02e73e15fff8ead19c3d9e945037f8527e54951a73099a2084e3797d412e555eb06b298b224a031e361c21e42cd7e261b223f90fd96c575
data/.gitignore ADDED
@@ -0,0 +1,111 @@
1
+
2
+ # Created by https://www.gitignore.io/api/emacs,ruby
3
+ # Edit at https://www.gitignore.io/?templates=emacs,ruby
4
+
5
+ ### Emacs ###
6
+ # -*- mode: gitignore; -*-
7
+ *~
8
+ \#*\#
9
+ /.emacs.desktop
10
+ /.emacs.desktop.lock
11
+ *.elc
12
+ auto-save-list
13
+ tramp
14
+ .\#*
15
+
16
+ # Org-mode
17
+ .org-id-locations
18
+ *_archive
19
+
20
+ # flymake-mode
21
+ *_flymake.*
22
+
23
+ # eshell files
24
+ /eshell/history
25
+ /eshell/lastdir
26
+
27
+ # elpa packages
28
+ /elpa/
29
+
30
+ # reftex files
31
+ *.rel
32
+
33
+ # AUCTeX auto folder
34
+ /auto/
35
+
36
+ # cask packages
37
+ .cask/
38
+ dist/
39
+
40
+ # Flycheck
41
+ flycheck_*.el
42
+
43
+ # server auth directory
44
+ /server/
45
+
46
+ # projectiles files
47
+ .projectile
48
+
49
+ # directory configuration
50
+ .dir-locals.el
51
+
52
+ # network security
53
+ /network-security.data
54
+
55
+
56
+ ### Ruby ###
57
+ *.gem
58
+ *.rbc
59
+ /.config
60
+ /coverage/
61
+ /InstalledFiles
62
+ /pkg/
63
+ /spec/reports/
64
+ /spec/examples.txt
65
+ /test/tmp/
66
+ /test/version_tmp/
67
+ /tmp/
68
+
69
+ # Used by dotenv library to load environment variables.
70
+ # .env
71
+
72
+ # Ignore Byebug command history file.
73
+ .byebug_history
74
+
75
+ ## Specific to RubyMotion:
76
+ .dat*
77
+ .repl_history
78
+ build/
79
+ *.bridgesupport
80
+ build-iPhoneOS/
81
+ build-iPhoneSimulator/
82
+
83
+ ## Specific to RubyMotion (use of CocoaPods):
84
+ #
85
+ # We recommend against adding the Pods directory to your .gitignore. However
86
+ # you should judge for yourself, the pros and cons are mentioned at:
87
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
88
+ # vendor/Pods/
89
+
90
+ ## Documentation cache and generated files:
91
+ /.yardoc/
92
+ /_yardoc/
93
+ /doc/
94
+ /rdoc/
95
+
96
+ ## Environment normalization:
97
+ /.bundle/
98
+ /vendor/bundle
99
+ /lib/bundler/man/
100
+
101
+ # for a library or gem, you might want to ignore these files since the code is
102
+ # intended to run in multiple environments; otherwise, check them in:
103
+ Gemfile.lock
104
+ # .ruby-version
105
+ # .ruby-gemset
106
+
107
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
108
+ .rvmrc
109
+
110
+ /bin
111
+ # End of https://www.gitignore.io/api/emacs,ruby
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3
7
+ - 2.4
8
+ - 2.5
9
+ - 2.6
10
+
11
+ before_install: gem install bundler -v 1.16.4
12
+
13
+ notifications:
14
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in env_var.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 sshaw
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,131 @@
1
+ # EnvVar
2
+
3
+ [![Build Status](https://travis-ci.org/sshaw/env_var.svg?branch=master)](https://travis-ci.org/sshaw/env_var)
4
+
5
+ Check if an environment variable is set to an enabled or disabled value.
6
+ Fetch an environment variable as an Array of `String`s or `Symbol`s.
7
+
8
+ ## Usage
9
+
10
+ ### `enabled?`/`disabled?`
11
+
12
+ Set an environment variable:
13
+ ```
14
+ export VARIABLE_NAME=1 # enabled
15
+ export VARIABLE_NAME=true # enabled
16
+ export VARIABLE_NAME=0 # disabled
17
+ export VARIABLE_NAME=false # disabled
18
+ ```
19
+
20
+ And check if it's enabled or disabled:
21
+ ```rb
22
+ require "$ENV"
23
+
24
+ enable_foo if $ENV.enabled?("VARIABLE_NAME")
25
+ disable_foo if $ENV.disabled?("VARIABLE_NAME")
26
+ ```
27
+
28
+ Note that if the environment variable **is not set** `enabled?` and `disabled?` **can both be `false`**.
29
+ If something is not enabled that does not mean it was explicitly disabled.
30
+
31
+ Don't do this:
32
+ ```rb
33
+ if !$ENV.enabled?("VARIABLE_NAME")
34
+ if !$ENV.disabled?("VARIABLE_NAME")
35
+ ```
36
+
37
+ Do this:
38
+ ```rb
39
+ if $ENV.disabled?("VARIABLE_NAME")
40
+ if $ENV.enabled?("VARIABLE_NAME")
41
+ ```
42
+
43
+ ### `$ENV::W`
44
+
45
+ Return an environment variable's value as an `Array` of words (`String`s):
46
+
47
+
48
+ ```
49
+ export VARIABLE_NAME="a,b,c"
50
+ export ANOTHER_VARIABLE=
51
+ ```
52
+
53
+ Then in Ruby:
54
+
55
+ ```rb
56
+ $ENV::W["VARIABLE_NAME"] # ["a", "b", "c"]
57
+ $ENV::W["ANOTHER_VARIABLE"] # []
58
+
59
+ # Or
60
+ $ENV.W("VARIABLE_NAME") # ["a", "b", "c"]
61
+ $ENV.w("VARIABLE_NAME") # ["a", "b", "c"]
62
+ ```
63
+
64
+ Mnemonic `%w(a b c)`.
65
+
66
+ ### `$ENV::I`
67
+
68
+ Return an environment variable's value as an `Array` of `Symbol`s:
69
+
70
+ ```rb
71
+ $ENV::I["VARIABLE_NAME"] # [:a, :b, :c]
72
+
73
+ # Or
74
+ $ENV.I("VARIABLE_NAME") # [:a, :b, :c]
75
+ $ENV.i("VARIABLE_NAME") # [:a, :b, :c]
76
+ ```
77
+
78
+ Mnemonic `%w(a b c)`.
79
+
80
+ ### Otherwise, Use it Like You Would `ENV`
81
+
82
+ ```rb
83
+ p $ENV["VARIABLE_NAME"]
84
+ p $ENV.delete("VARIABLE_NAME")
85
+ $ENV.each { |name, value| ... }
86
+ ```
87
+
88
+ ## Without `$ENV`
89
+
90
+ ```rb
91
+ require "env_var"
92
+
93
+ enable_foo if EnvVar.enabled?("VARIABLE_NAME")
94
+ disable_foo if EnvVar.disabled?("VARIABLE_NAME")
95
+ p EnvVar["VARIABLE_NAME"]
96
+ p EnvVar.delete("VARIABLE_NAME")
97
+ EnvVar.each { |name, value| ... }
98
+ ```
99
+
100
+ ## Monkey Patch
101
+
102
+ ```rb
103
+ require "env_var/env"
104
+
105
+ enable_foo if ENV.enabled?("VARIABLE_NAME")
106
+ disable_bar if ENV.disabled?("VARIABLE_NAME")
107
+ p ENV::i["VARIABLE_NAME"]
108
+ p ENV::w["VARIABLE_NAME"]
109
+
110
+ # ENV::W, ENV::I do not work
111
+ ```
112
+
113
+ ## Why?
114
+
115
+ Got tired of writing this over and over in various applications:
116
+
117
+ ```rb
118
+ enable_foo if %w[true 1 on].include?(ENV["ENABLE_FOO"])
119
+ ```
120
+
121
+ ## See Also
122
+
123
+ - [Envied](https://github.com/eval/envied) - Ensures presence and type of your app's ENV-variables
124
+
125
+ ## Author
126
+
127
+ Skye Shaw (skye DOT shaw AT gmail )
128
+
129
+ ## License
130
+
131
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/env_var.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "env_var/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "env_var"
7
+ spec.version = EnvVar::VERSION
8
+ spec.authors = ["sshaw"]
9
+ spec.email = ["skye.shaw@gmail.com"]
10
+
11
+ spec.summary = %q{Check if an environment variable is set to an enabled or disabled value. Fetch an environment variable as an Array of Strings or Symbols.}
12
+ #spec.description = %q{Check if an environment variable is set to an enabled or disabled value. Fetch an environment variable as an Array of Strings or Symbols.}
13
+ spec.homepage = "https://github.com/sshaw/env_var"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
data/lib/$ENV.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "env_var"
2
+ raise LoadError, "error: variable $ENV has been defined elsewhere" if defined?($ENV) && $ENV != EnvVar
3
+ $ENV = EnvVar
data/lib/env_var.rb ADDED
@@ -0,0 +1,49 @@
1
+ module EnvVar
2
+ module W
3
+ def self.[](name)
4
+ EnvVar[name] ? EnvVar[name].split(",") : []
5
+ end
6
+ end
7
+
8
+ module I
9
+ def self.[](name)
10
+ v = W[name]
11
+ v.empty? ? v : v.map(&:to_sym)
12
+ end
13
+ end
14
+
15
+ class << self
16
+ def I(name)
17
+ I[name]
18
+ end
19
+
20
+ alias i I
21
+
22
+ def W(name)
23
+ W[name]
24
+ end
25
+
26
+ alias w W
27
+
28
+ def enabled?(name)
29
+ %w[1 true on].freeze.include?(self[name])
30
+ end
31
+
32
+ def disabled?(name)
33
+ %w[0 false off].freeze.include?(self[name])
34
+ end
35
+
36
+ def [](name)
37
+ ENV[name]
38
+ end
39
+
40
+ def method_missing(name, *args)
41
+ return ENV.public_send(name, *args) if ENV.respond_to?(name)
42
+ super
43
+ end
44
+
45
+ def respond_to_missing?(name, all)
46
+ ENV.respond_to?(name, all) || super
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,26 @@
1
+ require "env_var"
2
+
3
+ def ENV.enabled?(name)
4
+ EnvVar.enabled?(name)
5
+ end
6
+
7
+ def ENV.disabled?(name)
8
+ EnvVar.enabled?(name)
9
+ end
10
+
11
+ def ENV.w(*a)
12
+ # Fake ENV::w["FOO"]
13
+ a.size == 0 ? EnvVar::W : EnvVar.w(*a)
14
+ end
15
+
16
+ def ENV.W(*a)
17
+ w(*a)
18
+ end
19
+
20
+ def ENV.i(*a)
21
+ a.size == 0 ? EnvVar::I : EnvVar.i(*a)
22
+ end
23
+
24
+ def ENV.I(*a)
25
+ i(*a)
26
+ end
@@ -0,0 +1,3 @@
1
+ module EnvVar
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: env_var
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - sshaw
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-06-22 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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.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.0'
55
+ description:
56
+ email:
57
+ - skye.shaw@gmail.com
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
+ - env_var.gemspec
70
+ - lib/$ENV.rb
71
+ - lib/env_var.rb
72
+ - lib/env_var/env.rb
73
+ - lib/env_var/version.rb
74
+ homepage: https://github.com/sshaw/env_var
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.7.6
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Check if an environment variable is set to an enabled or disabled value.
98
+ Fetch an environment variable as an Array of Strings or Symbols.
99
+ test_files: []