strenv 0.0.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: 9ea50a7c635563c02fa4d773f5ae03d0a2094051
4
+ data.tar.gz: 6d3d41c921f2c1884dfbae1ee9ecb9f93a056729
5
+ SHA512:
6
+ metadata.gz: 4f138db3790030270a6800e904b797b1e3055a10229e23735d2c4f12ed1925be8267288dc7f201c055b1ec0c70a7c1eedf0a0f10fc9fa9d273ed69b1175602bd
7
+ data.tar.gz: 4695da4923c2042d18a8a8ea8f6e505d07a929ed127557dff2880317bcfefe41b282d1b7232193e697d8db2b66676fa41ad5867d9c19ac0ee7f5350b3da49c73
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.9"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler", "~> 1.0"
12
+ gem "jeweler", "~> 2.0.1"
13
+ gem "simplecov", ">= 0"
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Julik Tarkhanov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,25 @@
1
+ = strenv
2
+
3
+ Creates a STRICT_ENV object in your global namespace. You can ask this object for environment variables just like
4
+ you would do with ENV.
5
+
6
+ However, when you pass a missing key (which happens all too often), there is going to be a meaningful exception:
7
+
8
+ STRICT_ENV['NUM_SERVERS']
9
+ # => STRICT_ENV::MissingVariable: No environment variable called "NUM_SERVERS" - you have to define it
10
+
11
+ == Contributing to strenv
12
+
13
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
14
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
15
+ * Fork the project.
16
+ * Start a feature/bugfix branch.
17
+ * Commit and push until you are happy with your contribution.
18
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
19
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
20
+
21
+ == Copyright
22
+
23
+ Copyright (c) 2014 Julik Tarkhanov. See LICENSE.txt for
24
+ further details.
25
+
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ require_relative 'lib/strenv'
3
+
4
+ require 'rubygems'
5
+ require 'bundler'
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+ require 'rake'
14
+
15
+ require 'jeweler'
16
+ Jeweler::Tasks.new do |gem|
17
+ gem.version = STRICT_ENV::VERSION
18
+ gem.name = "strenv"
19
+ gem.homepage = "http://github.com/julik/strenv"
20
+ gem.license = "MIT"
21
+ gem.summary = %Q{Strict ENV proxy for required environment variables}
22
+ gem.description = %Q{Creates a STRICT_ENV constant that you can query for environment variables and get meaningful exceptions}
23
+ gem.email = "me@julik.nl"
24
+ gem.authors = ["Julik Tarkhanov"]
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core'
30
+ require 'rspec/core/rake_task'
31
+ RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ spec.pattern = FileList['spec/**/*_spec.rb']
33
+ end
34
+
35
+ desc "Code coverage detail"
36
+ task :simplecov do
37
+ ENV['COVERAGE'] = "true"
38
+ Rake::Task['spec'].execute
39
+ end
40
+
41
+ task :default => :spec
42
+
43
+ require 'rdoc/task'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "strenv #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/lib/strenv.rb ADDED
@@ -0,0 +1,29 @@
1
+ # This is both a constant and a module, since in Ruby those two
2
+ # often go together. We avoid an extra item in the namespace
3
+ # and an extra assignment.
4
+ module STRICT_ENV
5
+ VERSION = '0.0.1'
6
+ MalformedKey = Class.new(RuntimeError)
7
+ MissingVariable = Class.new(RuntimeError)
8
+
9
+ # Fetch a value from ENV coded by "key" and raise a meaningful error if it's not set.
10
+ def [](key)
11
+ key_as_str = key.to_s
12
+ raise MalformedKey, "The given environment variable name was empty or nil" if key_as_str.empty?
13
+ unless ENV.has_key?(key_as_str)
14
+ raise MissingVariable, "No environment variable called #{key_as_str.inspect} - you have to define it"
15
+ end
16
+ ENV[key]
17
+ end
18
+
19
+ # Run a block protecting the contents of the environment variables
20
+ def with_protected_env(&blk)
21
+ preserved = ENV.to_h.dup
22
+ yield
23
+ ensure
24
+ ENV.replace(preserved)
25
+ end
26
+
27
+ extend self
28
+ end
29
+
@@ -0,0 +1,29 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_adapter 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
18
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
19
+
20
+ require 'rspec'
21
+ require 'strenv'
22
+
23
+ # Requires supporting files with custom matchers and macros, etc,
24
+ # in ./support/ and its subdirectories.
25
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
26
+
27
+ RSpec.configure do |config|
28
+
29
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "STRICT_ENV" do
4
+ it 'creates the STRICT_ENV environment variable' do
5
+ is_defined = defined?(STRICT_ENV)
6
+ expect(is_defined).to eq('constant')
7
+ end
8
+
9
+ context 'STRICT_ENV#[]' do
10
+ it 'proxies calls to [] to ENV' do
11
+ ENV.keys.each do | key |
12
+ expect(STRICT_ENV[key]).to eq(ENV[key])
13
+ end
14
+ end
15
+
16
+ it 'raises a meaningful error when a nil key is requested' do
17
+ expect {
18
+ STRICT_ENV[nil]
19
+ }.to raise_error(STRICT_ENV::MalformedKey, "The given environment variable name was empty or nil")
20
+ end
21
+
22
+ it 'raises a meaningful error when an empty key is requested' do
23
+ expect {
24
+ STRICT_ENV['']
25
+ }.to raise_error(STRICT_ENV::MalformedKey, "The given environment variable name was empty or nil")
26
+ end
27
+
28
+ it 'raises a meaningful error key that does not exist in ENV is requested' do
29
+ totally_random_key = "RANDOM_ENV_KEY_" + SecureRandom.hex(4).upcase
30
+ expect(ENV).not_to have_key(totally_random_key)
31
+ expect {
32
+ STRICT_ENV[totally_random_key]
33
+ }.to raise_error(
34
+ STRICT_ENV::MissingVariable,
35
+ "No environment variable called \"#{totally_random_key}\" - you have to define it"
36
+ )
37
+ end
38
+ end
39
+ end
40
+
data/strenv.gemspec ADDED
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "strenv"
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Julik Tarkhanov"]
12
+ s.date = "2014-07-14"
13
+ s.description = "Creates a STRICT_ENV constant that you can query for environment variables and get meaningful exceptions"
14
+ s.email = "me@julik.nl"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "lib/strenv.rb",
27
+ "spec/spec_helper.rb",
28
+ "spec/strenv_spec.rb",
29
+ "strenv.gemspec"
30
+ ]
31
+ s.homepage = "http://github.com/julik/strenv"
32
+ s.licenses = ["MIT"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = "2.0.3"
35
+ s.summary = "Strict ENV proxy for required environment variables"
36
+
37
+ if s.respond_to? :specification_version then
38
+ s.specification_version = 4
39
+
40
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
41
+ s.add_development_dependency(%q<rspec>, ["~> 2.9"])
42
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
43
+ s.add_development_dependency(%q<bundler>, ["~> 1.0"])
44
+ s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
45
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
46
+ else
47
+ s.add_dependency(%q<rspec>, ["~> 2.9"])
48
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
49
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
50
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
51
+ s.add_dependency(%q<simplecov>, [">= 0"])
52
+ end
53
+ else
54
+ s.add_dependency(%q<rspec>, ["~> 2.9"])
55
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
58
+ s.add_dependency(%q<simplecov>, [">= 0"])
59
+ end
60
+ end
61
+
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: strenv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Julik Tarkhanov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '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: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 2.0.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Creates a STRICT_ENV constant that you can query for environment variables
84
+ and get meaningful exceptions
85
+ email: me@julik.nl
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files:
89
+ - LICENSE.txt
90
+ - README.rdoc
91
+ files:
92
+ - .document
93
+ - .rspec
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.rdoc
97
+ - Rakefile
98
+ - lib/strenv.rb
99
+ - spec/spec_helper.rb
100
+ - spec/strenv_spec.rb
101
+ - strenv.gemspec
102
+ homepage: http://github.com/julik/strenv
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.0.3
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Strict ENV proxy for required environment variables
126
+ test_files: []