armoire 1.2.1 → 1.3.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: 16046f7dc3cfc111e688f040ceedc6d4ce5fe27d
4
- data.tar.gz: 829927c14622774dabeaea3cf570e95e5f51d32e
3
+ metadata.gz: a263f7ddf3ce8f483ec067a5ecb465fddd6717bb
4
+ data.tar.gz: 95a65f417aebde97343c57f1ca1fe655877a061d
5
5
  SHA512:
6
- metadata.gz: aed809c5f2fe6d9bf1a5a9ae9d505118d7cf7b9bf6ce67225529f9fa557b545c49938c917f17d6af19a57e3ed3a1a009c93b7aedae1619122ab6691d93bf875e
7
- data.tar.gz: 74b8b0200c547f30fb1896671a45386f46322d33779e4cc3a1f602e8eb8c8f7cf1d946bec2f27dfadd05fe25686d467f25de95e8df35f976c136e6815d9ceb13
6
+ metadata.gz: f66b78e05f8f27501337d14ea691c7a945dcd912b143e275c58fe840ce5848f1b7f4e7423d8830b7ad991cd4b6eb7bb2d96fe32cccaf105d5cef16e647fedd30
7
+ data.tar.gz: 0a1b4276b5286aed8e14a4dce4bd2869e7f8ff89ed5459d1bc7dba416a2b9af3db2a0d3222323b1a5bb2409dfed593b8c5da3b50e452c99ef8ed61e7e284ecb5
data/README.md CHANGED
@@ -42,7 +42,9 @@ Simply call `Armoire["foo"]` to get `"bar"` or `Armoire["nested_options"]["neste
42
42
 
43
43
  You may also call keys with any object that responds to `#to_s` and armoire will work correctly, e.g. `Armoire[:foo]`.
44
44
 
45
- The configuration environment will initially be taken from `ENV['RAILS_ENV']`, then `ENV['RACK_ENV']` and if neither exist then it will fall back to `development`
45
+ The configuration environment will initially be taken from `ENV['RAILS_ENV']`, then `ENV['RACK_ENV']` and if neither exist then it will fall back to `development`. Environment can also be set explicitly, but must be set prior to calling `load!`
46
+
47
+ Armoire.environment = 'not_rack'
46
48
 
47
49
  ### Usage in Rails
48
50
 
@@ -1,3 +1,3 @@
1
1
  class Armoire
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
data/lib/armoire.rb CHANGED
@@ -15,10 +15,7 @@ class Armoire
15
15
  include Singleton
16
16
 
17
17
  attr_accessor :settings
18
-
19
- def environment
20
- ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
21
- end
18
+ attr_writer :environment
22
19
 
23
20
  def self.[](key)
24
21
  instance.settings[key]
@@ -28,6 +25,14 @@ class Armoire
28
25
  instance.settings = Setting.new(instance.load_settings(path_to_config_file))
29
26
  end
30
27
 
28
+ def self.environment=(environment)
29
+ instance.environment = environment
30
+ end
31
+
32
+ def environment
33
+ @environment ||= ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
34
+ end
35
+
31
36
  def load_settings(path_to_config_file)
32
37
  YAML.load(ERB.new(File.read(path_to_config_file)).result)[environment]
33
38
  rescue Errno::ENOENT => e
@@ -4,6 +4,10 @@ describe Armoire do
4
4
  describe '#.environment' do
5
5
  subject { described_class.instance.environment }
6
6
 
7
+ before do
8
+ described_class.environment = nil
9
+ end
10
+
7
11
  context "ENV['RAILS_ENV'] is set" do
8
12
  before do
9
13
  @prev_rails_env = ENV['RAILS_ENV']
@@ -37,6 +41,27 @@ describe Armoire do
37
41
  end
38
42
  end
39
43
 
44
+ context "environment is explicitly set" do
45
+ before do
46
+ @prev_rails_env = ENV['RAILS_ENV']
47
+ @prev_rack_env = ENV['RACK_ENV']
48
+ ENV['RAILS_ENV'] = nil
49
+ ENV['RACK_ENV'] = nil
50
+ described_class.environment = 'no_rack'
51
+ end
52
+
53
+ it "returns the explicitly set environment" do
54
+ expect(subject).to eql("no_rack")
55
+ end
56
+
57
+ after do
58
+ ENV['RAILS_ENV'] = @prev_rails_env
59
+ ENV['RACK_ENV'] = @prev_rack_env
60
+ described_class.environment = nil
61
+ end
62
+ end
63
+
64
+
40
65
  context "nothing is set" do
41
66
  before do
42
67
  @prev_rails_env = ENV['RAILS_ENV']
@@ -54,6 +79,10 @@ describe Armoire do
54
79
  ENV['RACK_ENV'] = @prev_rack_env
55
80
  end
56
81
  end
82
+
83
+ after do
84
+ described_class.environment = nil
85
+ end
57
86
  end
58
87
 
59
88
  describe '#[]' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: armoire
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-21 00:00:00.000000000 Z
11
+ date: 2014-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler