envyable 0.0.1 → 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 +4 -4
- data/.travis.yml +6 -0
- data/README.md +2 -0
- data/lib/envyable.rb +19 -7
- data/lib/envyable/loader.rb +49 -0
- data/lib/envyable/version.rb +1 -1
- data/spec/envyable/loader_spec.rb +61 -0
- data/spec/fixtures/env.yml +2 -0
- data/spec/spec_helper.rb +0 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc529b788e4c02ba9ade498c8f90ea124ee1eaff
|
4
|
+
data.tar.gz: 3ef74376da66af3d73676190503126a113b8e00d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16eb882c1d6c847421ef7f282439aba644508fea7a9ec67a67db59f6f66157d5c4c19f37002c43a17d66325cdfa266cc693316c02b836d7d9e8ceb147b5c1797
|
7
|
+
data.tar.gz: 9ca14c2acbff5f783c087c3c259bcf017ad4acf9ddb312bffb65c4f9e9c24412cedf3a9e8bc2d7a2dbda228b20c641c389cfd155616b55e848510192987407c2
|
data/.travis.yml
ADDED
data/README.md
CHANGED
data/lib/envyable.rb
CHANGED
@@ -1,14 +1,26 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require 'envyable/loader'
|
2
3
|
require 'envyable/version'
|
3
4
|
require 'envyable/railtie' if defined?(Rails)
|
4
5
|
|
6
|
+
# Public: A simple yaml to ENV loader.
|
5
7
|
module Envyable
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
# Public: load the yaml file from path and set the variables in the given
|
9
|
+
# environment to the ENV.
|
10
|
+
#
|
11
|
+
# path - a Pathname or String that describes where the yaml file
|
12
|
+
# resides.
|
13
|
+
# environment - a String describing the environment from which to load the
|
14
|
+
# variables (default: development).
|
15
|
+
#
|
16
|
+
# Examples
|
17
|
+
#
|
18
|
+
# Envyable.load('config/env.yml')
|
19
|
+
#
|
20
|
+
# Envyable.load('config/application.yml', 'production')
|
21
|
+
#
|
22
|
+
# Returns nothing.
|
23
|
+
def self.load(path, environment='development')
|
24
|
+
Loader.new(path).load(environment)
|
13
25
|
end
|
14
26
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Envyable
|
2
|
+
# Internal: Loads yaml files into ENV (or a supplied hash).
|
3
|
+
class Loader
|
4
|
+
# Internal: Returns the String or Pathname path of the loader
|
5
|
+
attr_reader :path
|
6
|
+
|
7
|
+
# Internal: Returns the Hash loadable of the loader
|
8
|
+
attr_reader :loadable
|
9
|
+
|
10
|
+
# Internal: initalize a Loader
|
11
|
+
#
|
12
|
+
# path - a Pathname or String that describes where the yaml file
|
13
|
+
# resides.
|
14
|
+
# loadable - a Hash or hashlike structure that the yaml file variables
|
15
|
+
# should be loaded into (default: ENV).
|
16
|
+
def initialize(path, loadable=ENV)
|
17
|
+
@path = path
|
18
|
+
@loadable = loadable
|
19
|
+
end
|
20
|
+
|
21
|
+
# Internal: perform the loading from the given environment
|
22
|
+
#
|
23
|
+
# environment - a String describing the environment from which to load the
|
24
|
+
# variables (default: development).
|
25
|
+
#
|
26
|
+
# Examples
|
27
|
+
#
|
28
|
+
# load('production')
|
29
|
+
#
|
30
|
+
# Returns nothing.
|
31
|
+
def load(environment='development')
|
32
|
+
if @yml ||= load_yml
|
33
|
+
@yml[environment].each { |key, value| set_value(key, value) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def load_yml
|
40
|
+
yml_path = File.expand_path(@path)
|
41
|
+
return nil unless File.exists?(yml_path)
|
42
|
+
YAML.load_file(yml_path)
|
43
|
+
end
|
44
|
+
|
45
|
+
def set_value(key, value)
|
46
|
+
@loadable[key.to_s] = value.to_s
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/envyable/version.rb
CHANGED
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Envyable::Loader do
|
4
|
+
it 'should initialize with a path' do
|
5
|
+
loader = Envyable::Loader.new('.')
|
6
|
+
loader.must_be_kind_of Envyable::Loader
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'needs a path to initialize' do
|
10
|
+
lambda { Envyable::Loader.new }.must_raise ArgumentError
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'can be loaded with a path, environment and loadable hash' do
|
14
|
+
hash = {}
|
15
|
+
loader = Envyable::Loader.new('.', hash)
|
16
|
+
loader.loadable.must_equal hash
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'initialized with just a path' do
|
20
|
+
before { @loader = Envyable::Loader.new('spec/fixtures/env.yml') }
|
21
|
+
|
22
|
+
it 'should have access to the path' do
|
23
|
+
@loader.path.must_equal 'spec/fixtures/env.yml'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should default to loading to the ENV' do
|
27
|
+
@loader.loadable.must_equal ENV
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'initialized with a path and a loadable hash' do
|
32
|
+
before do
|
33
|
+
@loadable = {}
|
34
|
+
@loader = Envyable::Loader.new('spec/fixtures/env.yml', @loadable)
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'loading the default development env' do
|
38
|
+
before { @loader.load }
|
39
|
+
|
40
|
+
it 'should load variables from the yaml file into the loadable hash' do
|
41
|
+
@loadable['CHUNKY'].must_equal 'bacon'
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should load all items as strings' do
|
45
|
+
@loadable['NUMBER'].must_equal '3'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'loading the staging env' do
|
50
|
+
before { @loader.load('staging') }
|
51
|
+
|
52
|
+
it 'should load variables from the yaml file into the loadable hash' do
|
53
|
+
@loadable['CHUNKY'].must_equal 'foxes'
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should load all items as strings' do
|
57
|
+
@loadable['NUMBER'].must_equal '5'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/spec/fixtures/env.yml
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: envyable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phil Nash
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,14 +60,17 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- .gitignore
|
63
|
+
- .travis.yml
|
63
64
|
- Gemfile
|
64
65
|
- LICENSE.txt
|
65
66
|
- README.md
|
66
67
|
- Rakefile
|
67
68
|
- envyable.gemspec
|
68
69
|
- lib/envyable.rb
|
70
|
+
- lib/envyable/loader.rb
|
69
71
|
- lib/envyable/railtie.rb
|
70
72
|
- lib/envyable/version.rb
|
73
|
+
- spec/envyable/loader_spec.rb
|
71
74
|
- spec/envyable_spec.rb
|
72
75
|
- spec/fixtures/env.yml
|
73
76
|
- spec/spec_helper.rb
|
@@ -96,6 +99,7 @@ signing_key:
|
|
96
99
|
specification_version: 4
|
97
100
|
summary: The simplest yaml to ENV config loader
|
98
101
|
test_files:
|
102
|
+
- spec/envyable/loader_spec.rb
|
99
103
|
- spec/envyable_spec.rb
|
100
104
|
- spec/fixtures/env.yml
|
101
105
|
- spec/spec_helper.rb
|