figroll 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 14a63f584f645b93fac14fc5828541385cb6a7f9071051805037b9a483c3fbf0
4
+ data.tar.gz: 4544076f2daad2456dce6342b8d22fa9d0fdfffb0a0bc541f978bea6642a2ab6
5
+ SHA512:
6
+ metadata.gz: 7a0a9a5c95d9fa16fda6a42106e37209976b576e9593dee2b2c64c22740d7aaeea8b84e4ea0c71c511d556e9172360e481f1deb370be8efb2f4f68d064b0b5c1
7
+ data.tar.gz: b3b70d15d130702b413e0da9f4edde943a6b532d4cd86f33b2d1e29f23360a7f105611e1db4c76b9496a47ad8bb31a579cc926e58db2f5aa6232c6d45b24cf14
@@ -0,0 +1,8 @@
1
+ /Gemfile.lock
2
+ pkg
3
+ .bundle
4
+ *.gem
5
+ spec-*/fixtures/gitrepo
6
+ /coverage
7
+ *~
8
+ *.swp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.2
8
+ - 2.3.4
9
+
10
+ sudo: false
11
+
12
+ dist: precise
13
+
14
+ env:
15
+ - FIGROLL_ENV=test
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Engine Yard, Inc.
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.
@@ -0,0 +1,31 @@
1
+ # figroll #
2
+
3
+ Figroll is a somewhat simple gem to ease your way into the use of environment variables for configuration. That said, it is not currently documented, and you should not use it just yet.
4
+
5
+ ## Installation ##
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'figroll'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install figroll
20
+
21
+ ## Usage ##
22
+
23
+ Wow. Just look at all this empty space. You should check back here soon, but not right now. Later than now, definitely. As in there isn't any documentation at the present moment.
24
+
25
+ ## History ##
26
+
27
+ * 0.0.1 - A prerelease for internal tire kicking
28
+
29
+ ## License ##
30
+
31
+ This gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new do |t|
5
+ t.rspec_opts = %w[--color]
6
+ t.pattern = 'spec/**/*_spec.rb'
7
+ end
8
+
9
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib/', __FILE__)
3
+ $:.unshift lib unless $:.include?(lib)
4
+ require 'figroll/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "figroll"
8
+ gem.version = Figroll::VERSION
9
+
10
+ gem.author = "EY Cloud Team"
11
+ gem.email = "cloud@engineyard.com"
12
+ gem.summary = "Rails 2 configuration via ENV"
13
+ gem.description = "Rails 2 app configuration using ENV and a single YAML file"
14
+ gem.homepage = "https://github.com/engineyard/figroll"
15
+ gem.license = "MIT"
16
+
17
+ gem.add_development_dependency "bundler", "~> 1.7"
18
+ gem.add_development_dependency "rake", "~> 10.4"
19
+ gem.add_development_dependency 'rspec', '~> 2.14'
20
+ gem.add_development_dependency 'simplecov'
21
+ gem.add_development_dependency 'json', '<2'
22
+
23
+ gem.files = `git ls-files`.split($\)
24
+ gem.files.reject! {|file| ['Dockerfile', 'docker-compose.yml'].include?(file)}
25
+ gem.test_files = gem.files.grep(/^(spec|mock)/)
26
+
27
+ end
@@ -0,0 +1,62 @@
1
+ require 'figroll/config'
2
+ require 'figroll/storage'
3
+
4
+ module Figroll
5
+ def self.load_file(config_file)
6
+ setup
7
+
8
+ # Load the config file
9
+ config.load_file(config_file)
10
+
11
+ # Import the environment configuration from the config
12
+ storage.import(config.data)
13
+
14
+ # Import the actual ENV hash
15
+ storage.import(ENV)
16
+
17
+ # verify all required variables are set
18
+ validate_configuration
19
+ end
20
+
21
+ def self.fetch(key)
22
+ storage.fetch(key)
23
+ end
24
+
25
+ def self.storage
26
+ @storage
27
+ end
28
+
29
+ def self.config
30
+ @config
31
+ end
32
+
33
+
34
+ def self.validate_configuration
35
+ return nil if required.length == 0
36
+ return nil if (keys - required).length == keys.length - required.length
37
+
38
+ missing = required.reject {|key| keys.include?(key)}
39
+ raise "Required variables not set: #{missing}"
40
+ end
41
+
42
+ def self.required
43
+ config.required
44
+ end
45
+
46
+ def self.keys
47
+ storage.keys
48
+ end
49
+
50
+ def self.environment
51
+ config.environment
52
+ end
53
+
54
+ def self.normalize(key)
55
+ key.to_s.upcase.gsub(/\s+/, '_')
56
+ end
57
+
58
+ def self.setup
59
+ @config = Config.new
60
+ @storage = Storage.new
61
+ end
62
+ end
@@ -0,0 +1,34 @@
1
+ require 'yaml'
2
+
3
+ module Figroll
4
+ class Config
5
+ attr_reader :required, :environment, :data
6
+
7
+ def initialize
8
+ reset
9
+ end
10
+
11
+ def load_file(config_file)
12
+ return unless File.exists?(config_file)
13
+
14
+ file_data = YAML.load_file(config_file) || {}
15
+
16
+ # set up required keys
17
+ file_data['required'] ||= []
18
+ file_data['required'].each do |key|
19
+ required.push(Figroll.normalize(key))
20
+ end
21
+
22
+ # load up the environment-specific data
23
+ file_data['environments'] ||= {}
24
+ @data = file_data['environments'][environment] || {}
25
+ end
26
+
27
+ private
28
+ def reset
29
+ @environment = ENV['FIGROLL_ENV']
30
+ @required = []
31
+ @data = {}
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,30 @@
1
+ module Figroll
2
+ class Storage
3
+ attr_reader :vars
4
+
5
+ def initialize
6
+ reset
7
+ end
8
+
9
+ def fetch(key)
10
+ @vars.fetch(Figroll.normalize(key))
11
+ end
12
+
13
+ def import(incoming)
14
+ incoming.keys.each do |key|
15
+ vars[Figroll.normalize(key)] = incoming[key]
16
+ end
17
+
18
+ nil
19
+ end
20
+
21
+ def keys
22
+ vars.keys
23
+ end
24
+
25
+ private
26
+ def reset
27
+ @vars = {}
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module Figroll
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,6 @@
1
+ #required:
2
+ #- SAUSAGES
3
+
4
+ #environments:
5
+ #staging:
6
+ #SAUSAGES: gold
@@ -0,0 +1,3 @@
1
+ environments:
2
+ test:
3
+ SAUSAGES: gold
@@ -0,0 +1,2 @@
1
+ required:
2
+ - SAUSAGES
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Figroll::Config do
4
+ let(:config) {described_class.new}
5
+
6
+ describe '#load_file' do
7
+ let(:filename) {'figroll.yml'}
8
+ let(:config_file) {
9
+ File.join(MOCK_PATH, filename)
10
+ }
11
+
12
+ let(:load_file) {config.load_file(config_file)}
13
+
14
+ context 'when the file does not exist' do
15
+ let(:filename) {'nosuch.yml'}
16
+
17
+ it 'returns nil' do
18
+ expect(load_file).to eql(nil)
19
+ end
20
+ end
21
+
22
+ context 'when the file exists' do
23
+ let(:filename) {'figroll.yml'}
24
+
25
+ context 'and it contains required variables' do
26
+ let(:filename) {'withreqs.yml'}
27
+
28
+ it 'sets up the required variable names' do
29
+ load_file
30
+
31
+ expect(config.required).not_to be_empty
32
+ end
33
+ end
34
+
35
+ context 'and it contains an applicable environment' do
36
+ let(:filename) {'withoutreqs.yml'}
37
+
38
+ it 'sets up the data' do
39
+ load_file
40
+ expect(config.data).not_to be_empty
41
+ end
42
+ end
43
+ end
44
+
45
+ end
46
+
47
+
48
+
49
+
50
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Figroll::Storage do
4
+ let(:storage) {described_class.new}
5
+
6
+ describe '#fetch' do
7
+ let(:data) {
8
+ {
9
+ 'one' => 'two',
10
+ 'two' => 'three',
11
+ 'i like good' => 'ruby',
12
+ 'and' => 'I like good memes'
13
+ }
14
+ }
15
+
16
+ let(:key) {'two'}
17
+ let(:fetch) {storage.fetch(key)}
18
+
19
+ before(:each) do
20
+ storage.send(:reset)
21
+ storage.import(data)
22
+ end
23
+
24
+ context 'when I reference a known variable' do
25
+ let(:expected) {'ruby'}
26
+
27
+ context 'in standard env var format' do
28
+ let(:key) {'I_LIKE_GOOD'}
29
+
30
+ it 'is the expected value' do
31
+ expect(fetch).to eql(expected)
32
+ end
33
+ end
34
+
35
+ context 'in standard symbol format' do
36
+ let(:key) {:i_like_good}
37
+
38
+ it 'is the expected value' do
39
+ expect(fetch).to eql(expected)
40
+ end
41
+ end
42
+
43
+ context 'in a conversational manner' do
44
+ let(:key) {'I like good'}
45
+
46
+ it 'is the expected value' do
47
+ expect(fetch).to eql(expected)
48
+ end
49
+ end
50
+ end
51
+
52
+ context 'when I reference an unknown variable' do
53
+ let(:key) {:unknown}
54
+
55
+ it 'raises an error' do
56
+ expect {fetch}.to raise_error
57
+ end
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,107 @@
1
+ require 'spec_helper'
2
+
3
+ describe Figroll do
4
+ let(:storage) {described_class::Storage.new}
5
+ let(:config) {described_class::Config.new}
6
+
7
+ before(:each) do
8
+ allow(described_class).to receive(:storage).and_return(storage)
9
+ allow(described_class).to receive(:config).and_return(config)
10
+ allow(described_class).to receive(:reset).and_return(true)
11
+
12
+ allow(storage).to receive(:import).and_call_original
13
+ end
14
+
15
+ describe '.load_file' do
16
+ let(:filename) {'figroll.yml'}
17
+ let(:config_file) {
18
+ File.join(MOCK_PATH, filename)
19
+ }
20
+
21
+ let(:load_file) {described_class.load_file(config_file)}
22
+
23
+ before(:each) do
24
+ storage.send(:reset)
25
+ config.send(:reset)
26
+ end
27
+
28
+ it 'forwards the call to a config object' do
29
+ expect(described_class.config).to eql(config)
30
+ expect(config).
31
+ to receive(:load_file).
32
+ with(config_file)
33
+
34
+ load_file
35
+ end
36
+
37
+ context 'when there is an applicable configuration environment' do
38
+ let(:filename) {'withoutreqs.yml'}
39
+
40
+ it 'imports the configuration environment' do
41
+ expect(storage).
42
+ to receive(:import).
43
+ with({'SAUSAGES' => 'gold'})
44
+
45
+ load_file
46
+ end
47
+ end
48
+
49
+ it 'imports the execution environment' do
50
+ expect(storage).
51
+ to receive(:import).
52
+ with(ENV)
53
+
54
+ load_file
55
+ end
56
+
57
+ context 'when there are required variables' do
58
+ let(:filename) {'withreqs.yml'}
59
+
60
+ context 'but there is a missing required variable' do
61
+ before(:each) do
62
+ ENV.delete('SAUSAGES')
63
+ end
64
+
65
+ it 'raises an error' do
66
+ expect {load_file}.to raise_error
67
+ end
68
+ end
69
+
70
+ context 'and they are all present' do
71
+ before(:each) do
72
+ ENV['SAUSAGES'] = 'gold'
73
+ end
74
+
75
+ after(:each) do
76
+ ENV.delete('SAUSAGES')
77
+ end
78
+
79
+ it 'returns nil' do
80
+ expect(load_file).to eql(nil)
81
+ end
82
+ end
83
+ end
84
+
85
+ context 'when there are not required variables' do
86
+ let(:filename) {'withoutreqs.yml'}
87
+
88
+ it 'returns nil' do
89
+ expect(load_file).to eql(nil)
90
+ end
91
+ end
92
+ end
93
+
94
+ describe '.fetch' do
95
+ let(:key) {:whatever}
96
+ let(:value) {'yassss'}
97
+
98
+ let(:fetch) {described_class.fetch(key)}
99
+
100
+ it 'forwards the call to a storage object' do
101
+ expect(storage).to receive(:fetch).with(key).and_return(value)
102
+
103
+ expect(fetch).to eql(value)
104
+ end
105
+ end
106
+
107
+ end
@@ -0,0 +1,13 @@
1
+ unless RUBY_VERSION =~ /^1\.8\./
2
+ require 'simplecov'
3
+ SimpleCov.coverage_dir 'coverage'
4
+ SimpleCov.start do
5
+ add_filter '/spec/'
6
+ add_filter '/mock/'
7
+ end
8
+ end
9
+
10
+ ENV['FIGROLL_ENV'] = 'test'
11
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
12
+ MOCK_PATH = File.expand_path('../../mock', __FILE__)
13
+ require 'figroll'
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: figroll
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - EY Cloud Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-16 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
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
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "<"
74
+ - !ruby/object:Gem::Version
75
+ version: '2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "<"
81
+ - !ruby/object:Gem::Version
82
+ version: '2'
83
+ description: Rails 2 app configuration using ENV and a single YAML file
84
+ email: cloud@engineyard.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - ".rspec"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - figroll.gemspec
97
+ - lib/figroll.rb
98
+ - lib/figroll/config.rb
99
+ - lib/figroll/storage.rb
100
+ - lib/figroll/version.rb
101
+ - mock/figroll.yml
102
+ - mock/withoutreqs.yml
103
+ - mock/withreqs.yml
104
+ - spec/figroll/config_spec.rb
105
+ - spec/figroll/storage_spec.rb
106
+ - spec/figroll_spec.rb
107
+ - spec/spec_helper.rb
108
+ homepage: https://github.com/engineyard/figroll
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.7.9
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Rails 2 configuration via ENV
132
+ test_files:
133
+ - mock/figroll.yml
134
+ - mock/withoutreqs.yml
135
+ - mock/withreqs.yml
136
+ - spec/figroll/config_spec.rb
137
+ - spec/figroll/storage_spec.rb
138
+ - spec/figroll_spec.rb
139
+ - spec/spec_helper.rb