ee_cummings 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ad7554ad3ef9a071e81eec0845fd7f24c756235b
4
+ data.tar.gz: 359cd27beaf7ea5a67d4c89d8b30042ea8952c04
5
+ SHA512:
6
+ metadata.gz: 4ee6d6dfbfa94b3a3904ff060f90aefc92675bef4cffd3a4986b828e21e10aa30915b371aed88b44a16eaba311156231e7649ecc562b9d55cf0cf6ea0fdedb40
7
+ data.tar.gz: 3362b312d62e067301a0a839b7e14f37f4dd9ece7a7dbf9fe8465ce01b959fffc75c6e28248a7ba4ec1b26b3270aa27231d43a8c90bd68a9c4e16abb41e34fe9
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+ .ruby-version
20
+ .ruby-gemset
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ee_cummings.gemspec
4
+ gemspec
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ee_cummings (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.0.9)
10
+ diff-lcs (1.2.4)
11
+ method_source (0.8.1)
12
+ pry (0.9.12.2)
13
+ coderay (~> 1.0.5)
14
+ method_source (~> 0.8)
15
+ slop (~> 3.4)
16
+ rake (10.1.0)
17
+ rspec (2.14.1)
18
+ rspec-core (~> 2.14.0)
19
+ rspec-expectations (~> 2.14.0)
20
+ rspec-mocks (~> 2.14.0)
21
+ rspec-core (2.14.2)
22
+ rspec-expectations (2.14.0)
23
+ diff-lcs (>= 1.1.3, < 2.0)
24
+ rspec-mocks (2.14.1)
25
+ slop (3.4.5)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 1.3)
32
+ ee_cummings!
33
+ pry
34
+ rake
35
+ rspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Aubrey Rhodes
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.
@@ -0,0 +1,51 @@
1
+ E. E. Cummings
2
+ ==========
3
+
4
+ A tool to validate your environment variables
5
+
6
+ :rotating_light: *This is a work in progress and not ready for use* :rotating_light:
7
+
8
+ ## Description
9
+
10
+ E. E. Cummings manages your ENV variables and gives you clear warnings when they are misconfigured.
11
+
12
+ ## Installation
13
+
14
+ ```
15
+ gem install ee_cummings
16
+ ```
17
+ or add the following to a Gemfile
18
+ ```
19
+ gem 'ee_commings'
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ require 'ee_cummings'
26
+
27
+ # list your environment variables
28
+ EECummings.configure do |c|
29
+
30
+ # register an environment variable to require
31
+ c.variable do |var|
32
+
33
+ # the environment variable name
34
+ var.name = 'API_KEY'
35
+
36
+ # a regular expression that the value of the
37
+ # variable must match
38
+ var.regex = /[a-zA-Z0-9]+/
39
+ end
40
+
41
+ # register another varialbe
42
+ c.variable do |var|
43
+ var.name = 'API_SECRET'
44
+ # regex is defaulted to /.*/
45
+ end
46
+ end
47
+
48
+ # to retrieve the values of the environment variables
49
+ EECummings.api_secret
50
+ EECummings.api_key
51
+ ```
@@ -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
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ee_cummings/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ee_cummings"
8
+ spec.version = EECummings::VERSION
9
+ spec.authors = ["Aubrey Rhodes"]
10
+ spec.email = ["aubrey.c.rhodes@gmail.com"]
11
+ spec.description = %q{E. E. Cummings manages your ENV variables and gives you clear warnings when they are misconfigured.}
12
+ spec.summary = %q{A tool to validate your environment variables}
13
+ spec.homepage = "https://github.com/aubreyrhodes/ee_cummings"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+ end
@@ -0,0 +1,14 @@
1
+ require "ee_cummings/version"
2
+ require "ee_cummings/configuration"
3
+ require "ee_cummings/values"
4
+ require "ee_cummings/variable_registry"
5
+ require "ee_cummings/variable_definition"
6
+ require "ee_cummings/variable_warehouse"
7
+ require "ee_cummings/variable_source"
8
+ require "ee_cummings/variable_validator"
9
+ require "ee_cummings/misconfigured_variable"
10
+
11
+ module EECummings
12
+ extend Configuration
13
+ extend Values
14
+ end
@@ -0,0 +1,40 @@
1
+ module EECummings
2
+ module Configuration
3
+ def configure
4
+ variable_list = variable_registry
5
+ yield variable_list
6
+ variable_warehouse.load_variables_from_registry(variable_list)
7
+ if variable_warehouse.errors.length > 0
8
+ raise_errors(variable_warehouse.errors)
9
+ end
10
+ self.warehouse = variable_warehouse
11
+ end
12
+
13
+ def variable_registry=(registry)
14
+ @variable_registry = registry
15
+ end
16
+
17
+ def variable_warehouse=(warehouse)
18
+ @variable_warehouse = warehouse
19
+ end
20
+
21
+ def cleanup
22
+ @variable_registry = nil
23
+ @variable_warehouse = nil
24
+ end
25
+
26
+ private
27
+
28
+ def variable_registry
29
+ @variable_registry ||= EECummings::VariableRegistry.new
30
+ end
31
+
32
+ def variable_warehouse
33
+ @variable_warehouse ||= EECummings::VariableWarehouse.new
34
+ end
35
+
36
+ def raise_errors(errors)
37
+ raise MisconfiguredVariable.new "The following variables are missing or misconfigured: #{ errors.join(',') }"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,4 @@
1
+ module EECummings
2
+ class MisconfiguredVariable < StandardError
3
+ end
4
+ end
@@ -0,0 +1,12 @@
1
+ module EECummings
2
+ module Values
3
+ def warehouse=(warehouse)
4
+ @@warehouse=warehouse
5
+ end
6
+
7
+ def method_missing(meth, *args, &block)
8
+ key = meth.upcase.to_s
9
+ @@warehouse.get_value(key) || super
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ module EECummings
2
+ class VariableDefinition < Struct.new(:name, :regex)
3
+ def initialize
4
+ self.regex = /.*/
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ module EECummings
2
+ class VariableRegistry
3
+ attr_reader :variables
4
+
5
+ def initialize(variable_definition_class = VariableDefinition)
6
+ @variable_definition_class = variable_definition_class
7
+ @variables = []
8
+ end
9
+
10
+ def variable
11
+ variable = new_variable_definition
12
+ yield variable
13
+ @variables << variable
14
+ end
15
+
16
+ private
17
+
18
+ def new_variable_definition
19
+ @variable_definition_class.new
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,7 @@
1
+ module EECummings
2
+ class VariableSource
3
+ def get_value(key)
4
+ ENV[key]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module EECummings
2
+ class VariableValidator
3
+ def is_valid?(definition, value)
4
+ value =~ definition.regex
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ module EECummings
2
+ class VariableWarehouse
3
+ attr_reader :variable_source, :errors, :validator
4
+
5
+ def initialize(variable_source = VariableSource.new, validator = VariableValidator.new)
6
+ @variable_source = variable_source
7
+ @validator = validator
8
+ @variables = {}
9
+ @errors = []
10
+ end
11
+
12
+ def load_variables_from_registry(registry)
13
+ registry.variables.each do |var|
14
+ value = variable_source.get_value(var.name)
15
+ if validator.is_valid?(var, value)
16
+ @variables[var.name] = value
17
+ else
18
+ @errors << var.name
19
+ end
20
+ end
21
+ end
22
+
23
+ def get_value(key)
24
+ @variables[key]
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module EECummings
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,46 @@
1
+ require 'ee_cummings'
2
+
3
+ describe 'Managing Environment Variables' do
4
+ context 'an environment variable is present' do
5
+ let(:variable_value){ 'test' }
6
+
7
+ before do
8
+ EECummings.cleanup
9
+ ENV['EE_CUMMINGS_TEST_VAR'] ||= variable_value
10
+ end
11
+
12
+ it 'allows a user to require an environment variable' do
13
+ EECummings.configure do |c|
14
+ c.variable do |var|
15
+ var.name = 'EE_CUMMINGS_TEST_VAR'
16
+ end
17
+ end
18
+
19
+ expect(EECummings.ee_cummings_test_var).to eq(variable_value)
20
+ end
21
+
22
+ it 'throws an exception if a configured variable is missing' do
23
+ expect do
24
+ EECummings.configure do |c|
25
+ c.variable do |var|
26
+ var.name = 'EE_CUMMINGS_TEST_VAR'
27
+ end
28
+ c.variable do |var|
29
+ var.name = 'MISSING_VARIABLE'
30
+ end
31
+ end
32
+ end.to raise_error(EECummings::MisconfiguredVariable)
33
+ end
34
+
35
+ it 'throws an exception if a configured variable does not match the expected regex' do
36
+ expect do
37
+ EECummings.configure do |c|
38
+ c.variable do |var|
39
+ var.name = 'EE_CUMMINGS_TEST_VAR'
40
+ var.regex = /bad_regex/
41
+ end
42
+ end
43
+ end.to raise_error(EECummings::MisconfiguredVariable)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,36 @@
1
+ require 'ee_cummings/configuration'
2
+ require 'ee_cummings/misconfigured_variable'
3
+
4
+ describe EECummings::Configuration do
5
+ let(:variable_registry){ double }
6
+ let(:variable_warehouse){ double(errors: []) }
7
+
8
+ subject{ Object.new.extend(EECummings::Configuration) }
9
+
10
+ before do
11
+ subject.variable_registry = variable_registry
12
+ subject.variable_warehouse = variable_warehouse
13
+
14
+ variable_warehouse.stub(:load_variables_from_registry)
15
+ subject.stub(:warehouse=)
16
+ end
17
+
18
+ it 'yeilds a variable registry' do
19
+ target = expect{ |b| subject.configure(&b)}.to yield_with_args(variable_registry)
20
+ end
21
+
22
+ it 'loads variables into the warehouse from the registry' do
23
+ variable_warehouse.should_receive(:load_variables_from_registry).with(variable_registry)
24
+ subject.configure{}
25
+ end
26
+
27
+ it 'sets the objects warehouse' do
28
+ subject.should_receive(:warehouse=).with(variable_warehouse)
29
+ subject.configure{}
30
+ end
31
+
32
+ it 'raises an error if there are misconfigured variables' do
33
+ variable_warehouse.stub(:errors).and_return(['bad_variable'])
34
+ expect{ subject.configure{} }.to raise_error(EECummings::MisconfiguredVariable)
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe EECummings do
4
+ it 'should have a version number' do
5
+ EECummings::VERSION.should_not be_nil
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'ee_cummings'
@@ -0,0 +1,18 @@
1
+ require 'ee_cummings/values'
2
+
3
+ describe EECummings::Values do
4
+ let(:warehouse){ double }
5
+
6
+ subject{ Object.new.extend(EECummings::Values) }
7
+
8
+ describe 'retrieveing values' do
9
+ before do
10
+ warehouse.stub(:get_value).with('TEST_KEY').and_return('test')
11
+ subject.warehouse = warehouse
12
+ end
13
+
14
+ it 'returns the value for the right key with a method call' do
15
+ expect(subject.test_key).to eq('test')
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ require 'ee_cummings/variable_definition'
2
+
3
+ describe EECummings::VariableDefinition do
4
+ end
@@ -0,0 +1,21 @@
1
+ require 'ee_cummings/variable_registry'
2
+
3
+ describe EECummings::VariableRegistry do
4
+
5
+ class MockVariableDefinition; end
6
+
7
+ subject{ EECummings::VariableRegistry.new(MockVariableDefinition) }
8
+
9
+ describe '#variable' do
10
+ it 'yields a variable definition' do
11
+ expect{ |b| subject.variable(&b) }.to yield_with_args(MockVariableDefinition)
12
+ end
13
+ end
14
+
15
+ describe '#variables' do
16
+ it 'keeps track of variables that were registered' do
17
+ 3.times do subject.variable{} end
18
+ expect(subject.variables.length).to eq(3)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ require 'ee_cummings/variable_source'
2
+
3
+ describe EECummings::VariableSource do
4
+ describe '#get_value' do
5
+ it 'returns the value of an environment variable' do
6
+ ENV['test_key'] = 'test'
7
+ expect(subject.get_value('test_key')).to eq('test')
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ require 'ee_cummings/variable_validator'
2
+
3
+ describe EECummings::VariableValidator do
4
+ let(:definition){ double(name: 'test_name', regex: /[a-z]+/) }
5
+
6
+ describe '#is_valid?' do
7
+ it 'returns true if the value is valid' do
8
+ expect(subject.is_valid?(definition, 'test')).to be_true
9
+ end
10
+
11
+ it 'returns false if the value does not match the variables regex' do
12
+ expect(subject.is_valid?(definition, '123')).to be_false
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,34 @@
1
+ require 'ee_cummings/variable_warehouse'
2
+
3
+ describe EECummings::VariableWarehouse do
4
+ let(:variable_source){ double }
5
+ let(:registry){ double(variables: [ double(name: 'test_name') ]) }
6
+ let(:validator){ double(is_valid?: true) }
7
+
8
+ subject{ EECummings::VariableWarehouse.new(variable_source, validator) }
9
+
10
+ describe '#load_variables_from_registry' do
11
+
12
+ before do
13
+ variable_source.should_receive(:get_value).with('test_name')
14
+ end
15
+
16
+ it 'loads values from the variable source' do
17
+ subject.load_variables_from_registry(registry)
18
+ end
19
+
20
+ it 'saves the error if the validator fails' do
21
+ validator.stub(:is_valid?).and_return(false)
22
+ subject.load_variables_from_registry(registry)
23
+ expect(subject.errors.length).to eq(1)
24
+ end
25
+ end
26
+
27
+ describe '#get_value' do
28
+ it 'returns loaded values by key' do
29
+ variable_source.should_receive(:get_value).with('test_name').and_return('test')
30
+ subject.load_variables_from_registry(registry)
31
+ expect(subject.get_value('test_name')).to eq('test')
32
+ end
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ee_cummings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aubrey Rhodes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-12 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '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: pry
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: E. E. Cummings manages your ENV variables and gives you clear warnings
70
+ when they are misconfigured.
71
+ email:
72
+ - aubrey.c.rhodes@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rspec
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - ee_cummings.gemspec
85
+ - lib/ee_cummings.rb
86
+ - lib/ee_cummings/configuration.rb
87
+ - lib/ee_cummings/misconfigured_variable.rb
88
+ - lib/ee_cummings/values.rb
89
+ - lib/ee_cummings/variable_definition.rb
90
+ - lib/ee_cummings/variable_registry.rb
91
+ - lib/ee_cummings/variable_source.rb
92
+ - lib/ee_cummings/variable_validator.rb
93
+ - lib/ee_cummings/variable_warehouse.rb
94
+ - lib/ee_cummings/version.rb
95
+ - spec/acceptance/environment_variables_spec.rb
96
+ - spec/configuration_spec.rb
97
+ - spec/ee_cummings_spec.rb
98
+ - spec/spec_helper.rb
99
+ - spec/values_spec.rb
100
+ - spec/variable_definition_spec.rb
101
+ - spec/variable_registry_spec.rb
102
+ - spec/variable_source_spec.rb
103
+ - spec/variable_validator_spec.rb
104
+ - spec/variable_warehouse_spec.rb
105
+ homepage: https://github.com/aubreyrhodes/ee_cummings
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.0.3
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: A tool to validate your environment variables
129
+ test_files:
130
+ - spec/acceptance/environment_variables_spec.rb
131
+ - spec/configuration_spec.rb
132
+ - spec/ee_cummings_spec.rb
133
+ - spec/spec_helper.rb
134
+ - spec/values_spec.rb
135
+ - spec/variable_definition_spec.rb
136
+ - spec/variable_registry_spec.rb
137
+ - spec/variable_source_spec.rb
138
+ - spec/variable_validator_spec.rb
139
+ - spec/variable_warehouse_spec.rb