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.
@@ -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
@@ -1,3 +1,3 @@
1
1
  module EasyConfig
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/easy_config.rb CHANGED
@@ -36,6 +36,14 @@ module EasyConfig
36
36
  @loaded = false
37
37
  setup_config
38
38
  end
39
+
40
+ def self.environment
41
+ EasyConfig::Env.current
42
+ end
43
+
44
+ def self.environment=(env)
45
+ EasyConfig::Env.set(env)
46
+ end
39
47
  end
40
48
 
41
49
  require 'easy_config/config_file'
@@ -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
@@ -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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Felipe Oliveira