easy_config 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/easy_config/env.rb +13 -4
- data/lib/easy_config/version.rb +1 -1
- data/lib/easy_config.rb +8 -0
- data/spec/easy_config/env_spec.rb +9 -0
- data/spec/easy_config_spec.rb +11 -0
- metadata +3 -3
data/lib/easy_config/env.rb
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
module EasyConfig::Env
|
2
2
|
def self.current
|
3
|
+
@env ||= get_default
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.has_environment?(hash)
|
7
|
+
hash.keys.include?(self.current)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.set(env)
|
11
|
+
@env = env
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def self.get_default
|
3
16
|
if defined?(Rails)
|
4
17
|
Rails.env
|
5
18
|
elsif !ENV['RACK_ENV'].nil?
|
@@ -8,8 +21,4 @@ module EasyConfig::Env
|
|
8
21
|
"development"
|
9
22
|
end
|
10
23
|
end
|
11
|
-
|
12
|
-
def self.has_environment?(hash)
|
13
|
-
hash.keys.include?(self.current)
|
14
|
-
end
|
15
24
|
end
|
data/lib/easy_config/version.rb
CHANGED
data/lib/easy_config.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe EasyConfig::Env do
|
4
|
+
before { EasyConfig::Env.instance_variable_set('@env', nil) }
|
5
|
+
|
4
6
|
context :current do
|
7
|
+
|
5
8
|
context "Rails.env" do
|
6
9
|
before { module ::Rails; def self.env; "production"; end; end }
|
7
10
|
after { Object.send(:remove_const, :Rails) }
|
@@ -20,6 +23,12 @@ describe EasyConfig::Env do
|
|
20
23
|
subject { EasyConfig::Env.current }
|
21
24
|
it { should eq "development" }
|
22
25
|
end
|
26
|
+
|
27
|
+
context "custom environment" do
|
28
|
+
before { EasyConfig::Env.set('test') }
|
29
|
+
subject { EasyConfig::Env.current }
|
30
|
+
it { should eq 'test' }
|
31
|
+
end
|
23
32
|
end
|
24
33
|
|
25
34
|
context :has_environment? do
|
data/spec/easy_config_spec.rb
CHANGED
@@ -27,4 +27,15 @@ describe EasyConfig do
|
|
27
27
|
lambda { EasyConfig.no_exist }.should raise_error(EasyConfig::ConfigurationNotFound)
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
31
|
+
context "default environment" do
|
32
|
+
subject { EasyConfig.environment }
|
33
|
+
it { should eq "development" }
|
34
|
+
end
|
35
|
+
|
36
|
+
context "set custom environment" do
|
37
|
+
before { EasyConfig.environment = "test" }
|
38
|
+
subject { EasyConfig.environment }
|
39
|
+
it { should eq "test" }
|
40
|
+
end
|
30
41
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Felipe Oliveira
|