envyable 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ecba5911fb07a63cb327cd4f890971e4e2c0d2c
4
- data.tar.gz: c4076179d76ea1caea32145929e1c5a8528e19cc
3
+ metadata.gz: dc529b788e4c02ba9ade498c8f90ea124ee1eaff
4
+ data.tar.gz: 3ef74376da66af3d73676190503126a113b8e00d
5
5
  SHA512:
6
- metadata.gz: 90711adaf82b431c42dc2b6fe92b16a78b3ecd7ba465481c587cefe1c9ff18130ad4e50240b93b51bb811b47e2a48b4c77fbdffa350567ece8f514aa43364a88
7
- data.tar.gz: bb83481e5b0cb8b23cf1fd79c81c14459f42f579626339d0095c5e2dffb9364af4c775d115a051611c596b43a0b4441cb9aa056bb18651501259d055dd864eaa
6
+ metadata.gz: 16eb882c1d6c847421ef7f282439aba644508fea7a9ec67a67db59f6f66157d5c4c19f37002c43a17d66325cdfa266cc693316c02b836d7d9e8ceb147b5c1797
7
+ data.tar.gz: 9ca14c2acbff5f783c087c3c259bcf017ad4acf9ddb312bffb65c4f9e9c24412cedf3a9e8bc2d7a2dbda228b20c641c389cfd155616b55e848510192987407c2
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  The simplest yaml to ENV config loader.
4
4
 
5
+ [![Build Status](https://travis-ci.org/philnash/envyable.png?branch=master)](https://travis-ci.org/philnash/envyable)
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
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
- def self.load(path, env='development')
7
- yml = File.expand_path(path)
8
- if File.exists? yml
9
- Array(YAML.load_file(yml)[env]).each do |key,value|
10
- ENV[key.to_s] = value.to_s
11
- end
12
- end
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
@@ -1,3 +1,3 @@
1
1
  module Envyable
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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
@@ -1,5 +1,7 @@
1
1
  development:
2
2
  CHUNKY: 'bacon'
3
+ NUMBER: 3
3
4
 
4
5
  staging:
5
6
  CHUNKY: 'foxes'
7
+ NUMBER: 5
data/spec/spec_helper.rb CHANGED
@@ -2,4 +2,3 @@ require 'rubygems'
2
2
  require 'minitest/autorun'
3
3
 
4
4
  require File.join(File.dirname(__FILE__), '..', 'lib', 'envyable')
5
-
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.1
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-01-06 00:00:00.000000000 Z
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