envyable 0.1.0 → 0.2.0

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: 661545b979cadecd245a677ec876ca2c401a9d8d
4
- data.tar.gz: a8601f4fd7d40d933b59ebf55ea193bac1cb4bdc
3
+ metadata.gz: 6b57186fbe7d6265ce530ab6a33f95fca5c05a03
4
+ data.tar.gz: 887228621e2fea513d72db59f7f84ceaf59a69c6
5
5
  SHA512:
6
- metadata.gz: 1df7cfea13ad7efde5c24e34b658af6dfd446782bea413d1b4baa7e7da2b7465510bc3f3bbd9691884707110d1b72d781ed2b934c3eb9b12a823d781bd213f2d
7
- data.tar.gz: 6463eda2156c6abb6b6c85652310ac57b68d7b7feda230c25e1df8549593e4270f377cb0c7087ad153474e63970bc9bf4ece971d798d0bc575299cd98936fb8e
6
+ metadata.gz: 6bd05e5ce62e73555001d214a199135da6732e1ce3b457ca6f58ac7e9dc8c7cdfe0842b9473ae7f5c10af18284f95f6dc739839aec0c71bc4cdf3c5b10b63735
7
+ data.tar.gz: 1d52aa03bafa7e316fd94c403181339f98f442764120a567cc7e4a1caccb328472563129b8db12f68e5ec3c40259514e389a66f5012f8204730d3f05a1283e83
@@ -1,10 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
- - 1.9.3
6
3
  - 2.0.0
7
4
  - 2.1.0
8
- - jruby-18mode
5
+ - 2.2.0
9
6
  - jruby-19mode
10
7
  - rbx
@@ -0,0 +1,20 @@
1
+ # ChangeLog
2
+
3
+ ## 0.2.0 / 2015-03-16
4
+
5
+ * [FEATURE] Allows user to add default values and then override on an environment by environment basis
6
+ * [ENHANCEMENT] Uses `Pathname#join` to form file name in Railtie
7
+
8
+ ## 0.1.0 / 2015-01-22
9
+
10
+ * [BUGFIX] Stops the loader from choking on a file if the environment requested is not present
11
+
12
+ ## 0.0.2 / 2014-02-02
13
+
14
+ * [ENHANCEMENT] Tidies up Loader class
15
+ * [ENHANCEMENT] Adds more tests
16
+ * [ENHANCEMENT] Adds TravisCI
17
+
18
+ ## 0.0.1 / 2014-01-06
19
+
20
+ * Initial version
data/README.md CHANGED
@@ -20,26 +20,27 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- ### Rails
23
+ ### YAML file
24
24
 
25
- Once installed in a Rails app, add a `config/env.yml` file with your config
26
- separated into environments, like so:
25
+ Create a yaml file that holds your settings. You can put default settings into the root of the yaml file and then override those on an environment by environment basis. For example, the following yaml file will load the id "development-id" into all environments it is loaded in except for the test environment, where the id would be "test-id".
27
26
 
28
27
  ```
29
- development:
30
- API_CLIENT_ID: development-id
28
+ API_CLIENT_ID: development-id
31
29
  test:
32
30
  API_CLIENT_ID: test-id
33
31
  ```
34
32
 
35
- The gem will load the correct environment on initialization of the application.
33
+ ### Rails
36
34
 
37
- Do not check in the `config/env.yml` file as it may contain application secrets
38
- that you do not want shared.
35
+ Once installed in a Rails app, add your yaml file at `config/env.yml`. The gem will load the correct environment on initialization of the application.
39
36
 
40
37
  ### Other applications
41
38
 
42
- You can simply call `Envyable.load(path, environment)` and the yaml file will be loaded into ENV.
39
+ You can create your yaml file anywhere (though why not `config/env.yml`?). Then call `Envyable.load('path/to/yml', environment)` and the yaml file will be loaded into `ENV`.
40
+
41
+ ### Version control
42
+
43
+ It is not recommended that you check the yaml file in to version control. Personally, I like to check in a `env.yml.example` file that shows the required keys, but does not include any credentials.
43
44
 
44
45
  ## Contributing
45
46
 
@@ -30,8 +30,10 @@ module Envyable
30
30
  # Returns nothing.
31
31
  def load(environment='development')
32
32
  if @yml ||= load_yml
33
- return unless @yml[environment]
34
- @yml[environment].each { |key, value| set_value(key, value) }
33
+ @yml.each { |key, value| set_value(key, value) }
34
+ if @yml[environment]
35
+ @yml[environment].each { |key, value| set_value(key, value) }
36
+ end
35
37
  end
36
38
  end
37
39
 
@@ -44,7 +46,7 @@ module Envyable
44
46
  end
45
47
 
46
48
  def set_value(key, value)
47
- @loadable[key.to_s] = value.to_s
49
+ @loadable[key.to_s] = value.to_s unless value.is_a?(Hash)
48
50
  end
49
51
  end
50
52
  end
@@ -1,7 +1,7 @@
1
1
  module Envyable
2
2
  class Railtie < Rails::Railtie
3
3
  initializer "envyable.load", :before => :load_environment_config do
4
- Envyable.load Rails.root + 'config/env.yml', Rails.env
4
+ Envyable.load Rails.root.join('config', 'env.yml'), Rails.env
5
5
  end
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module Envyable
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -58,4 +58,36 @@ describe Envyable::Loader do
58
58
  end
59
59
  end
60
60
  end
61
+
62
+ describe 'initialized with a path to an env with default values and a loadable hash' do
63
+ before do
64
+ @loadable = {}
65
+ @loader = Envyable::Loader.new('spec/fixtures/default_env.yml', @loadable)
66
+ end
67
+
68
+ describe 'loading the default development environment' do
69
+ before { @loader.load }
70
+
71
+ it 'should load default values into the loadable' do
72
+ @loadable['CHUNKY'].must_equal 'bacon'
73
+ @loadable['NUMBER'].must_equal '3'
74
+ end
75
+
76
+ it 'should not load a key for environment specific values' do
77
+ @loadable['staging'].must_be_nil
78
+ end
79
+ end
80
+
81
+ describe 'loading the staging environment' do
82
+ before { @loader.load('staging') }
83
+
84
+ it 'should overwrite the default values' do
85
+ @loadable['CHUNKY'].must_equal 'foxes'
86
+ end
87
+
88
+ it 'should still load the other default values' do
89
+ @loadable['NUMBER'].must_equal '3'
90
+ end
91
+ end
92
+ end
61
93
  end
@@ -0,0 +1,5 @@
1
+ CHUNKY: 'bacon'
2
+ NUMBER: 3
3
+
4
+ staging:
5
+ CHUNKY: 'foxes'
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Nash
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-22 00:00:00.000000000 Z
11
+ date: 2015-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,6 +61,7 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
63
  - ".travis.yml"
64
+ - CHANGELOG.md
64
65
  - Gemfile
65
66
  - LICENSE.txt
66
67
  - README.md
@@ -72,6 +73,7 @@ files:
72
73
  - lib/envyable/version.rb
73
74
  - spec/envyable/loader_spec.rb
74
75
  - spec/envyable_spec.rb
76
+ - spec/fixtures/default_env.yml
75
77
  - spec/fixtures/env.yml
76
78
  - spec/spec_helper.rb
77
79
  homepage: https://github.com/philnash/envyable
@@ -94,12 +96,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
96
  version: '0'
95
97
  requirements: []
96
98
  rubyforge_project:
97
- rubygems_version: 2.2.2
99
+ rubygems_version: 2.4.5
98
100
  signing_key:
99
101
  specification_version: 4
100
102
  summary: The simplest yaml to ENV config loader
101
103
  test_files:
102
104
  - spec/envyable/loader_spec.rb
103
105
  - spec/envyable_spec.rb
106
+ - spec/fixtures/default_env.yml
104
107
  - spec/fixtures/env.yml
105
108
  - spec/spec_helper.rb