armoire 1.2.1 → 1.3.0
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/README.md +3 -1
- data/lib/armoire/version.rb +1 -1
- data/lib/armoire.rb +9 -4
- data/spec/lib/armoire_spec.rb +29 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a263f7ddf3ce8f483ec067a5ecb465fddd6717bb
|
4
|
+
data.tar.gz: 95a65f417aebde97343c57f1ca1fe655877a061d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/lib/armoire/version.rb
CHANGED
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
|
data/spec/lib/armoire_spec.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2014-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|