env_manager 0.0.11

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: a74dc7206a484e79c4c92af61ae311f0ea1fcb4b
4
+ data.tar.gz: dba897d62fd4b2d5ca78ae9018b49cccb36c2fb1
5
+ SHA512:
6
+ metadata.gz: 98d7cfa38ef19623652b06d38d31c3839f98bd7f19faa00ef7a42a18836ce0ea17051c77f16b3ff184463c9070f330e0244b6f6527785259582617f7646783a9
7
+ data.tar.gz: d4ebeccffbe97dc8131bf8737e827739eed611f37d0358a1a0f40f31766f3c9d616de546e52f925ea59a20c4e9bc0dd155a8f04b65f341dd1f427c3bcf34188d
data/.env ADDED
@@ -0,0 +1,3 @@
1
+ RACK_ENV=development
2
+ PORT=7000
3
+ DATABASE_URL=postgres://robert@127.0.0.1:5432/get_the_rundown
@@ -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_manager.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Robert Evans
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,29 @@
1
+ # EnvManager
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'env_manager'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install env_manager
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/env_manager/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.verbose = true
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/**/**/*_test.rb']
8
+ end
9
+
10
+ task :default => 'test'
@@ -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_manager/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "env_manager"
8
+ spec.version = EnvManager.version
9
+ spec.authors = ["Robert Evans"]
10
+ spec.email = ["robert@codewranglers.org"]
11
+ spec.summary = %q{Manage your environment}
12
+ spec.description = %q{Manage your environment}
13
+ spec.homepage = ""
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"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "minitest"
24
+ end
@@ -0,0 +1,15 @@
1
+ require "env_manager/version"
2
+
3
+ require 'env_manager/loader'
4
+ require 'env_manager/builder'
5
+
6
+ module EnvManager
7
+ # Reads the env file for the given environment
8
+ # and returns an object representation of the
9
+ # environment variables defined within that file.
10
+ #
11
+ def self.load(path)
12
+ env_file = Loader.new(path)
13
+ Builder.new(env_file.read)
14
+ end
15
+ end
@@ -0,0 +1,43 @@
1
+
2
+ module EnvManager
3
+ class Builder
4
+
5
+ def initialize(file_contents)
6
+ build(file_contents)
7
+ end
8
+
9
+ def build(file_contents)
10
+ hash = dynamic_assignment(file_contents)
11
+ hash.each do |key, value|
12
+ instance_variable_set("@#{key}", value)
13
+ self.class.send(:attr_accessor, key)
14
+ end
15
+ end
16
+
17
+ %w|development staging test production|.each do |env|
18
+ define_method :"#{env}?" do
19
+ env == ::ENV['RACK_ENV']
20
+ end
21
+ end
22
+
23
+ def env
24
+ ::ENV['RACK_ENV']
25
+ end
26
+
27
+ private
28
+
29
+ # Builds a hash of the .env file
30
+ # Assigns values to the ENV global
31
+ def dynamic_assignment(content)
32
+ return if content.nil? || content == ''
33
+ content.split("\n").inject({}) do |hash, line|
34
+ key, value = line.split('=')
35
+ ::ENV[key] = value.strip
36
+
37
+ hash[key.downcase.to_sym] = value.strip
38
+ hash
39
+ end
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,23 @@
1
+
2
+ module EnvManager
3
+ class Loader
4
+
5
+ # ==== Arguments
6
+ #
7
+ # * Basepath - Pathname Object
8
+ #
9
+ def initialize(basepath)
10
+ @basepath = basepath
11
+ end
12
+
13
+
14
+ # ==== Returns
15
+ #
16
+ # Returns the content of the env file read
17
+ #
18
+ def read
19
+ @basepath.join(".env").read
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ module EnvManager
2
+ MAJOR = 0
3
+ MINOR = 0
4
+ PATCH = 11
5
+
6
+ def self.version
7
+ [
8
+ MAJOR, MINOR, PATCH
9
+ ].join('.')
10
+ end
11
+ end
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ class EnvManager::LoaderTest < Minitest::Test
4
+ include TestHelper
5
+
6
+ def test_loader
7
+ env = EnvManager::Loader.new(App.root)
8
+
9
+ refute_empty env.read
10
+ end
11
+
12
+ def test_load
13
+ env = EnvManager.load(App.root)
14
+
15
+ refute_nil env.database_url
16
+ refute_nil ::ENV["DATABASE_URL"]
17
+
18
+ assert_equal "development", env.rack_env
19
+ assert_equal "development", ::ENV["RACK_ENV"]
20
+ end
21
+
22
+ def test_app_load
23
+ assert_equal 'development', App.config.rack_env
24
+ assert_equal 'postgres://robert@127.0.0.1:5432/get_the_rundown', App.config.database_url
25
+ end
26
+
27
+ def test_app_booleans
28
+ assert App.config.development?
29
+ refute App.config.test?
30
+ refute App.config.staging?
31
+ refute App.config.production?
32
+ end
33
+
34
+ def test_env
35
+ assert_equal 'development', App.config.env
36
+ end
37
+
38
+ end
@@ -0,0 +1,19 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require 'pathname'
4
+
5
+ require_relative '../lib/env_manager'
6
+
7
+ module TestHelper
8
+ module App
9
+ extend self
10
+
11
+ def root
12
+ @root ||= ::Pathname.new(__dir__).join("..")
13
+ end
14
+
15
+ def config
16
+ @config ||= ::EnvManager.load(root)
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: env_manager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.11
5
+ platform: ruby
6
+ authors:
7
+ - Robert Evans
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-13 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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: minitest
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
+ description: Manage your environment
56
+ email:
57
+ - robert@codewranglers.org
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".env"
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - env_manager.gemspec
69
+ - lib/env_manager.rb
70
+ - lib/env_manager/builder.rb
71
+ - lib/env_manager/loader.rb
72
+ - lib/env_manager/version.rb
73
+ - test/loader_test.rb
74
+ - test/test_helper.rb
75
+ homepage: ''
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.0
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Manage your environment
99
+ test_files:
100
+ - test/loader_test.rb
101
+ - test/test_helper.rb