elasticonf 1.0.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53660c491b6cb9f052da798d870ed9fba66873bd
4
- data.tar.gz: e23890b87312c7a42d744b9a5971a47f38f2a17b
3
+ metadata.gz: cd115068bd4e3aa9f3335c5728f744684d88231e
4
+ data.tar.gz: ef56ca9fa15a060e729d983b7ca3fe93f5460287
5
5
  SHA512:
6
- metadata.gz: 72d9b370cfbb6e2b8b676bf7d2725aa3e7acaebd869ad21faa50f77aef35205169123303625d0e2bcd91dfc2701e4e3f72cbd22960b8bab1edea0fa30cf776b9
7
- data.tar.gz: 65cb6a62d043b0e480938ef2216f11da2530683d6b16e39c7e4bfc6f29586498053dfa3334bfe0666737fc6a00cba00a6aa2f41e412654cf04d59fd749b7ba31
6
+ metadata.gz: 83d0d17bd2506b22ffe0f5fdf13d19e9d2bc6cb43646e2cdaf2d858af473699a2758f80a9bf5e548588943eaf35ee6ae41fc4c87930091ba51859188365826bc
7
+ data.tar.gz: b7130ff9b5b389af6cd54570e2dd895b549ab209ef18e3633cad593daf796df22b482eb0bb4f68454e877fbb5a8e94270e5fe0fbfc21e53f627acc2cd45e9914
data/.gitignore CHANGED
@@ -2,4 +2,5 @@
2
2
  .yardoc
3
3
  doc
4
4
  pkg
5
- vendor/bundle
5
+ vendor/bundle
6
+ coverage/
data/.travis.yml CHANGED
@@ -2,17 +2,20 @@ language: ruby
2
2
 
3
3
  rvm:
4
4
  - ruby-head
5
+ - jruby-head
6
+ - rbx-head
5
7
  - 2.1.1
6
8
  - 2.1.0
7
9
  - 2.0.0
8
10
  - 1.9.3
9
11
  - 1.9.2
10
- - jruby-19mode
11
- - jruby-head
12
- - rbx-2.1
13
- - rbx-2.2
14
12
 
15
13
  matrix:
16
14
  allow_failures:
17
15
  - rvm: ruby-head
18
- - rvm: jruby-head
16
+ - rvm: jruby-head
17
+ - rvm: rbx-head
18
+
19
+ branches:
20
+ only:
21
+ - master
data/Gemfile CHANGED
@@ -1,2 +1,7 @@
1
1
  source 'https://rubygems.org'
2
- gemspec
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem 'coveralls', require: false
7
+ end
data/Gemfile.lock CHANGED
@@ -1,15 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- elasticonf (1.0.0)
5
- hashie (~> 2.1.0)
4
+ elasticonf (1.1.0)
5
+ hashie (~> 3.1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ coveralls (0.7.0)
11
+ multi_json (~> 1.3)
12
+ rest-client
13
+ simplecov (>= 0.7)
14
+ term-ansicolor
15
+ thor
10
16
  diff-lcs (1.2.5)
11
- hashie (2.1.1)
12
- rake (10.3.1)
17
+ docile (1.1.5)
18
+ hashie (3.1.0)
19
+ mime-types (2.3)
20
+ multi_json (1.10.1)
21
+ rake (10.3.2)
22
+ rest-client (1.6.7)
23
+ mime-types (>= 1.16)
13
24
  rspec (2.14.1)
14
25
  rspec-core (~> 2.14.0)
15
26
  rspec-expectations (~> 2.14.0)
@@ -18,13 +29,23 @@ GEM
18
29
  rspec-expectations (2.14.5)
19
30
  diff-lcs (>= 1.1.3, < 2.0)
20
31
  rspec-mocks (2.14.6)
32
+ simplecov (0.8.2)
33
+ docile (~> 1.1.0)
34
+ multi_json
35
+ simplecov-html (~> 0.8.0)
36
+ simplecov-html (0.8.0)
37
+ term-ansicolor (1.3.0)
38
+ tins (~> 1.0)
39
+ thor (0.19.1)
40
+ tins (1.3.0)
21
41
  yard (0.8.7.4)
22
42
 
23
43
  PLATFORMS
24
44
  ruby
25
45
 
26
46
  DEPENDENCIES
47
+ coveralls
27
48
  elasticonf!
28
- rake (~> 10.3.0)
29
- rspec (~> 2.14.0)
30
- yard (~> 0.8.0)
49
+ rake (~> 10.3)
50
+ rspec (~> 2.14)
51
+ yard (~> 0.8)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ElastiConf [![Build Status](https://travis-ci.org/rezwyi/elasticonf.svg?branch=master)](https://travis-ci.org/rezwyi/elasticonf) [![Dependency Status](https://gemnasium.com/rezwyi/elasticonf.svg)](https://gemnasium.com/rezwyi/elasticonf)
1
+ ElastiConf [![Build Status](https://travis-ci.org/rezwyi/elasticonf.svg?branch=master)](https://travis-ci.org/rezwyi/elasticonf) [![Dependency Status](https://gemnasium.com/rezwyi/elasticonf.svg)](https://gemnasium.com/rezwyi/elasticonf) [![Coverage Status](https://img.shields.io/coveralls/rezwyi/elasticonf.svg)](https://coveralls.io/r/rezwyi/elasticonf)
2
2
  ==========
3
3
 
4
4
  Powerfull and flexible application config solution worked in any ruby program. No clases definition, no dependencies. It just works!
@@ -8,7 +8,7 @@ Powerfull and flexible application config solution worked in any ruby program. N
8
8
  First add the following lines to your application `Gemfile`:
9
9
 
10
10
  ``` ruby
11
- gem 'elasticonf', '~> 1.0.0.beta'
11
+ gem 'elasticonf', '~> 1.1.0'
12
12
  ```
13
13
 
14
14
  Then run `bundle install` to update your's gems bundle.
@@ -28,7 +28,8 @@ Run this commands in terminal:
28
28
  0. `cd some/path`
29
29
  0. `git clone git@github.com:rezwyi/elasticonf.git`
30
30
  0. `cd elasticonf/`
31
- 0. `bin/rspec`
31
+ 0. `bundle install`
32
+ 0. `bin/rake`
32
33
 
33
34
  ## Versioning
34
35
 
data/elasticonf.gemspec CHANGED
@@ -19,9 +19,9 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.required_ruby_version = '>= 1.9'
21
21
 
22
- s.add_dependency 'hashie', '~> 2.1.0'
22
+ s.add_dependency 'hashie', '~> 3.1'
23
23
 
24
- s.add_development_dependency 'rake', '~> 10.3.0'
25
- s.add_development_dependency 'rspec', '~> 2.14.0'
26
- s.add_development_dependency 'yard', '~> 0.8.0'
27
- end
24
+ s.add_development_dependency 'rake', '~> 10.3'
25
+ s.add_development_dependency 'rspec', '~> 2.14'
26
+ s.add_development_dependency 'yard', '~> 0.8'
27
+ end
@@ -1,11 +1,8 @@
1
1
  module ElastiConf
2
- module Config
3
- def configure
4
- yield self
5
- end
6
-
2
+ class Config
7
3
  def reset_config!
8
4
  %w(
5
+ env
9
6
  config_root
10
7
  config_file
11
8
  const_name
@@ -14,16 +11,27 @@ module ElastiConf
14
11
  instance_variable_set "@#{v}", nil
15
12
  end
16
13
  end
14
+
15
+ def env
16
+ @env ||= 'development'
17
+ end
18
+
19
+ def env=(value)
20
+ unless [String, Symbol].include?(value.class)
21
+ raise ArgumentError, "String or Symbol expected #{value.class} given"
22
+ end
23
+ @env = value.to_s
24
+ end
17
25
 
18
26
  def config_root
19
- @config_root ||= raise(ArgumentError, 'You must first specify config root')
27
+ @config_root ||= raise(ArgumentError, 'You must specify config_root option first')
20
28
  end
21
29
 
22
30
  def config_root=(value)
23
31
  unless [String, Symbol, Pathname].include?(value.class)
24
- raise ArgumentError, "String or Pathname expected #{value.class} given"
32
+ raise ArgumentError, "String or Symbol or Pathname expected #{value.class} given"
25
33
  end
26
- @config_root = value.is_a?(String) ? Pathname.new(value.to_s) : value
34
+ @config_root = value.is_a?(Pathname) ? value : Pathname.new(value.to_s)
27
35
  end
28
36
 
29
37
  def config_file
@@ -34,7 +42,7 @@ module ElastiConf
34
42
  unless [String, Symbol].include?(value.class)
35
43
  raise ArgumentError, "String or Symbol expected #{value.class} given"
36
44
  end
37
- @config_file = value
45
+ @config_file = value.to_s
38
46
  end
39
47
 
40
48
  def const_name
@@ -1,4 +1,17 @@
1
1
  module ElastiConf
2
2
  class Loader < Hashie::Mash
3
+ def get(key)
4
+ unless [String, Symbol].include?(key.class)
5
+ raise ArgumentError, "String or Symbol expected #{key.class} given"
6
+ end
7
+
8
+ hash, items = self, key.split('.')
9
+
10
+ while (item = items.shift)
11
+ (hash = hash[item.to_sym]) || break
12
+ end
13
+
14
+ hash
15
+ end
3
16
  end
4
17
  end
@@ -1,3 +1,3 @@
1
1
  module ElastiConf
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
data/lib/elasticonf.rb CHANGED
@@ -6,35 +6,51 @@ require 'elasticonf/config'
6
6
  require 'elasticonf/loader'
7
7
 
8
8
  module ElastiConf
9
- extend Config
10
-
11
9
  module_function
12
10
 
13
11
  def root
14
12
  @root ||= Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), '..')))
15
13
  end
16
14
 
15
+ def config
16
+ @config ||= Config.new
17
+ end
18
+
19
+ def configure
20
+ yield config
21
+ end
22
+
17
23
  def load!(env = nil)
18
- const_name = ElastiConf.const_name
19
- config_file = ElastiConf.config_root.join(ElastiConf.config_file + '.yml')
20
-
21
- env_config_file = env ?
22
- ElastiConf.config_root.join(ElastiConf.config_file, "#{env}.yml") :
23
- nil
24
-
25
- raise("Config file #{config_file} not found. Cannot continue") unless File.exists?(config_file)
24
+ config_file = config.config_root.join(config.config_file + '.yml')
25
+ config.env = env if env
26
+
27
+ unless File.exists?(config_file)
28
+ raise "Config file #{config_file} not found. Cannot continue"
29
+ end
30
+
31
+ loader = Loader[YAML.load_file(config_file)]
26
32
 
27
- config = Loader[YAML.load_file(config_file)]
28
- if env_config_file && File.exists?(env_config_file)
29
- config = config.deep_merge(Loader[YAML.load_file(env_config_file)])
33
+ env_config_file = config.config_root.join(config.config_file, "#{config.env}.yml")
34
+ if File.exists?(env_config_file)
35
+ loader = loader.deep_merge(Loader[YAML.load_file(env_config_file)])
36
+ end
37
+
38
+ local_config_file = config.config_root.join(config.config_file + '.local.yml')
39
+ if File.exists?(local_config_file)
40
+ loader = loader.deep_merge(Loader[YAML.load_file(local_config_file)])
30
41
  end
31
42
 
32
- if Kernel.const_defined?(const_name)
33
- raise_if_already_initialized_constant ?
34
- raise("Cannot set constant #{const_name} because it is already initialized") :
35
- Kernel.send(:remove_const, const_name)
43
+ if Kernel.const_defined?(config.const_name)
44
+ config.raise_if_already_initialized_constant ?
45
+ raise("Cannot set constant #{config.const_name} because it is already initialized") :
46
+ Kernel.send(:remove_const, config.const_name)
36
47
  end
37
48
 
38
- Kernel.const_set const_name, config
49
+ Kernel.const_set config.const_name, loader
50
+ end
51
+
52
+ def configure_and_load!
53
+ configure { |config| yield(config) }
54
+ load!
39
55
  end
40
56
  end
@@ -1,7 +1,167 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ElastiConf::Config do
4
- it 'should be a module' do
5
- subject.should be_a(Module)
4
+ describe '#reset_config!' do
5
+ before do
6
+ subject.env = :test
7
+ subject.config_root = '/configuration'
8
+ subject.config_file = 'application'
9
+ subject.const_name = 'AppSettings'
10
+ subject.raise_if_already_initialized_constant = false
11
+
12
+ subject.reset_config!
13
+ end
14
+
15
+ its(:env) { should eql('development') }
16
+ its(:config_file) { should eql('config') }
17
+ its(:const_name) { should eql('Settings') }
18
+ its(:raise_if_already_initialized_constant) { should be_true }
19
+
20
+ it 'should raise an error' do
21
+ expect { subject.config_root }.to raise_error
22
+ end
23
+ end
24
+
25
+ describe '#env' do
26
+ its(:env) { should eql('development') }
27
+
28
+ it 'should return some value' do
29
+ expect { subject.env = :test }.to change(subject, :env).to('test')
30
+ end
31
+
32
+ context 'when wrong argument given' do
33
+ it 'should raise an error' do
34
+ expect { subject.env = -> {} }.to raise_error
35
+ end
36
+
37
+ it 'should raise an error' do
38
+ expect { subject.env = {} }.to raise_error
39
+ end
40
+
41
+ it 'should raise an error' do
42
+ expect { subject.env = [] }.to raise_error
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '#config_root' do
48
+ it 'should raise an error' do
49
+ expect { subject.config_root }.to raise_error
50
+ end
51
+
52
+ it 'should return some value' do
53
+ subject.config_root = '/config'
54
+ expect(subject.config_root).to eql(Pathname.new('/config'))
55
+ end
56
+
57
+ context 'when wrong argument given' do
58
+ it 'should raise an error' do
59
+ expect { subject.config_root = -> {} }.to raise_error
60
+ end
61
+
62
+ it 'should raise an error' do
63
+ expect { subject.config_root = {} }.to raise_error
64
+ end
65
+
66
+ it 'should raise an error' do
67
+ expect { subject.config_root = [] }.to raise_error
68
+ end
69
+ end
70
+ end
71
+
72
+ describe '#config_file' do
73
+ its(:config_file) { should eql('config') }
74
+
75
+ it 'should return some value' do
76
+ expect {
77
+ subject.config_file = 'application'
78
+ }.to change(subject, :config_file).to('application')
79
+ end
80
+
81
+ context 'when wrong argument given' do
82
+ it 'should raise an error' do
83
+ expect { subject.config_file = -> {} }.to raise_error
84
+ end
85
+
86
+ it 'should raise an error' do
87
+ expect { subject.config_file = {} }.to raise_error
88
+ end
89
+
90
+ it 'should raise an error' do
91
+ expect { subject.config_file = [] }.to raise_error
92
+ end
93
+ end
94
+ end
95
+
96
+ describe '#const_name' do
97
+ its(:const_name) { should eql('Settings') }
98
+
99
+ it 'should return some value' do
100
+ expect {
101
+ subject.const_name = 'AppSettings'
102
+ }.to change(subject, :const_name).to('AppSettings')
103
+ end
104
+
105
+ it 'should return some value' do
106
+ expect {
107
+ subject.const_name = :'AppSettings'
108
+ }.to change(subject, :const_name).to('AppSettings')
109
+ end
110
+
111
+ context 'when wrong argument given' do
112
+ it 'should raise an error' do
113
+ expect { subject.const_name = -> {} }.to raise_error
114
+ end
115
+
116
+ it 'should raise an error' do
117
+ expect { subject.const_name = {} }.to raise_error
118
+ end
119
+
120
+ it 'should raise an error' do
121
+ expect { subject.const_name = [] }.to raise_error
122
+ end
123
+ end
124
+ end
125
+
126
+ describe '#raise_if_already_initialized_constant' do
127
+ its(:raise_if_already_initialized_constant) { should be_true }
128
+
129
+ it 'should change to false' do
130
+ expect {
131
+ subject.raise_if_already_initialized_constant = false
132
+ }.to change(subject, :raise_if_already_initialized_constant).to(false)
133
+ end
134
+
135
+ context 'when wrong argument given' do
136
+ it 'should raise an error' do
137
+ expect {
138
+ subject.raise_if_already_initialized_constant = 'some_string'
139
+ }.to raise_error
140
+ end
141
+
142
+ it 'should raise an error' do
143
+ expect {
144
+ subject.raise_if_already_initialized_constant = :some_symbol
145
+ }.to raise_error
146
+ end
147
+
148
+ it 'should raise an error' do
149
+ expect {
150
+ subject.raise_if_already_initialized_constant = -> {}
151
+ }.to raise_error
152
+ end
153
+
154
+ it 'should raise an error' do
155
+ expect {
156
+ subject.raise_if_already_initialized_constant = {}
157
+ }.to raise_error
158
+ end
159
+
160
+ it 'should raise an error' do
161
+ expect {
162
+ subject.raise_if_already_initialized_constant = []
163
+ }.to raise_error
164
+ end
165
+ end
6
166
  end
7
167
  end
@@ -1,7 +1,44 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ElastiConf::Loader do
4
+ subject do
5
+ file = ElastiConf.root.join('spec', 'fixtures', 'config.yml')
6
+ described_class[YAML.load_file(file)]
7
+ end
8
+
4
9
  it 'should be inherited from Hashie::Mash' do
5
10
  subject.should be_kind_of(Hashie::Mash)
6
11
  end
12
+
13
+ describe '#get' do
14
+ it 'should return nil' do
15
+ expect(subject.get('some.unexisting.key')).to be_nil
16
+ end
17
+
18
+ it 'should return some value' do
19
+ expect(subject.get('some_config.int_key')).to eql(1)
20
+ end
21
+
22
+ it 'should return some value' do
23
+ expect(subject.get('some_config.str_key')).to eql('1')
24
+ end
25
+
26
+ context 'when wrong argument given' do
27
+ it 'should raise an error' do
28
+ expect { subject.get }.to raise_error
29
+ end
30
+
31
+ it 'should raise an error' do
32
+ expect { subject.get({}) }.to raise_error
33
+ end
34
+
35
+ it 'should raise an error' do
36
+ expect { subject.get([]) }.to raise_error
37
+ end
38
+
39
+ it 'should raise an error' do
40
+ expect { subject.get(false) }.to raise_error
41
+ end
42
+ end
43
+ end
7
44
  end
@@ -3,6 +3,18 @@ require 'spec_helper'
3
3
  describe ElastiConf do
4
4
  it { should be_a(Module) }
5
5
 
6
+ describe '#root' do
7
+ its(:root) do
8
+ should eql(Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))))
9
+ end
10
+ end
11
+
12
+ describe '#config' do
13
+ it 'should instantiate ElastiConf::Config' do
14
+ expect(subject.config.class).to eql(ElastiConf::Config)
15
+ end
16
+ end
17
+
6
18
  describe '#configure' do
7
19
  before do
8
20
  subject.configure do |config|
@@ -13,155 +25,27 @@ describe ElastiConf do
13
25
  end
14
26
  end
15
27
 
16
- its(:config_root) { should eql(Pathname('/config')) }
17
- its(:config_file) { should eql('application') }
18
- its(:const_name) { should eql('AppSettings') }
19
- its(:raise_if_already_initialized_constant) { should be_false }
20
- end
21
-
22
- describe '#reset_config!' do
23
- before { subject.reset_config! }
24
-
25
- its(:config_file) { should eql('config') }
26
- its(:const_name) { should eql('Settings') }
27
- its(:raise_if_already_initialized_constant) { should be_true }
28
-
29
- it 'should raise an error' do
30
- expect { subject.config_root }.to raise_error
28
+ it 'should return config_root' do
29
+ expect(subject.config.config_root).to eql(Pathname('/config'))
31
30
  end
32
- end
33
31
 
34
- describe '#config_root' do
35
- it 'should raise an error' do
36
- expect { subject.config_root }.to raise_error
32
+ it 'should return config_file' do
33
+ expect(subject.config.config_file).to eql('application')
37
34
  end
38
35
 
39
- it 'should return some value' do
40
- subject.config_root = '/config'
41
- subject.config_root.should eql(Pathname.new('/config'))
36
+ it 'should return const_name' do
37
+ expect(subject.config.const_name).to eql('AppSettings')
42
38
  end
43
39
 
44
- context 'when wrong argument given' do
45
- it 'should raise an error' do
46
- expect { subject.config_root = -> {} }.to raise_error
47
- end
48
-
49
- it 'should raise an error' do
50
- expect { subject.config_root = {} }.to raise_error
51
- end
52
-
53
- it 'should raise an error' do
54
- expect { subject.config_root = [] }.to raise_error
55
- end
56
- end
57
- end
58
-
59
- describe '#config_file' do
60
- its(:config_file) { should eql('config') }
61
-
62
- it 'should return some value' do
63
- expect {
64
- subject.config_file = 'application'
65
- }.to change(subject, :config_file).to('application')
66
- end
67
-
68
- context 'when wrong argument given' do
69
- it 'should raise an error' do
70
- expect { subject.config_file = -> {} }.to raise_error
71
- end
72
-
73
- it 'should raise an error' do
74
- expect { subject.config_file = {} }.to raise_error
75
- end
76
-
77
- it 'should raise an error' do
78
- expect { subject.config_file = [] }.to raise_error
79
- end
80
- end
81
- end
82
-
83
- describe '#const_name' do
84
- its(:const_name) { should eql('Settings') }
85
-
86
- it 'should return some value' do
87
- expect {
88
- subject.const_name = 'AppSettings'
89
- }.to change(subject, :const_name).to('AppSettings')
90
- end
91
-
92
- it 'should return some value' do
93
- expect {
94
- subject.const_name = :'AppSettings'
95
- }.to change(subject, :const_name).to('AppSettings')
96
- end
97
-
98
- context 'when wrong argument given' do
99
- it 'should raise an error' do
100
- expect { subject.const_name = -> {} }.to raise_error
101
- end
102
-
103
- it 'should raise an error' do
104
- expect { subject.const_name = {} }.to raise_error
105
- end
106
-
107
- it 'should raise an error' do
108
- expect { subject.const_name = [] }.to raise_error
109
- end
110
- end
111
- end
112
-
113
- describe '#raise_if_already_initialized_constant' do
114
- its(:raise_if_already_initialized_constant) { should be_true }
115
-
116
- it 'should change to false' do
117
- expect {
118
- subject.raise_if_already_initialized_constant = false
119
- }.to change(subject, :raise_if_already_initialized_constant).to(false)
120
- end
121
-
122
- context 'when wrong argument given' do
123
- it 'should raise an error' do
124
- expect {
125
- subject.raise_if_already_initialized_constant = 'some_string'
126
- }.to raise_error
127
- end
128
-
129
- it 'should raise an error' do
130
- expect {
131
- subject.raise_if_already_initialized_constant = :some_symbol
132
- }.to raise_error
133
- end
134
-
135
- it 'should raise an error' do
136
- expect {
137
- subject.raise_if_already_initialized_constant = -> {}
138
- }.to raise_error
139
- end
140
-
141
- it 'should raise an error' do
142
- expect {
143
- subject.raise_if_already_initialized_constant = {}
144
- }.to raise_error
145
- end
146
-
147
- it 'should raise an error' do
148
- expect {
149
- subject.raise_if_already_initialized_constant = []
150
- }.to raise_error
151
- end
152
- end
153
- end
154
-
155
- describe '#root' do
156
- its(:root) do
157
- should eql(Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))))
40
+ it 'should return false' do
41
+ expect(subject.config.raise_if_already_initialized_constant).to eql(false)
158
42
  end
159
43
  end
160
44
 
161
45
  describe '#load!' do
162
46
  before do
163
47
  subject.configure do |config|
164
- config.config_root = ElastiConf.root.join('spec', 'fixtures')
48
+ config.config_root = subject.root.join('spec', 'fixtures')
165
49
  config.config_file = 'application'
166
50
  config.const_name = const_name
167
51
  end
@@ -187,7 +71,7 @@ describe ElastiConf do
187
71
  expect(AppSettings.some_config.str_key).to eql('1')
188
72
  end
189
73
 
190
- context 'when some env given' do
74
+ context 'when some env given (as argument)' do
191
75
  let(:env) { :test }
192
76
 
193
77
  it 'should not raise an error' do
@@ -205,6 +89,24 @@ describe ElastiConf do
205
89
  end
206
90
  end
207
91
 
92
+ context 'and some env given (through config.env)' do
93
+ before { subject.config.env = :test }
94
+
95
+ it 'should not raise an error' do
96
+ expect { subject.load! }.not_to raise_error
97
+ end
98
+
99
+ it 'should load missing values from config file' do
100
+ subject.load!
101
+ expect(AppSettings.some_config.int_key).to eql(2)
102
+ end
103
+
104
+ it 'should override values from config file' do
105
+ subject.load!
106
+ expect(AppSettings.some_config.str_key).to eql('2')
107
+ end
108
+ end
109
+
208
110
  context 'when already initialized constant' do
209
111
  before { Kernel.const_set(const_name, {}) }
210
112
 
@@ -213,9 +115,95 @@ describe ElastiConf do
213
115
  end
214
116
 
215
117
  it 'should not raise an error' do
216
- subject.raise_if_already_initialized_constant = false
118
+ subject.config.raise_if_already_initialized_constant = false
119
+ expect { subject.load! }.not_to raise_error
120
+ end
121
+ end
122
+
123
+ context 'when .local file present' do
124
+ let(:config_file) { subject.config.config_root.join('application.yml') }
125
+ let(:local_config_file) { subject.config.config_root.join('application.local.yml') }
126
+
127
+ before do
128
+ YAML::load_file(config_file).tap do |config|
129
+ config['some_config']['str_key'] = 'local'
130
+ config['some_config'].delete('int_key')
131
+ File.open(local_config_file, 'w') { |f| f.write config.to_yaml }
132
+ end
133
+ end
134
+
135
+ after { FileUtils.rm(local_config_file) }
136
+
137
+ it 'should not raise an error' do
217
138
  expect { subject.load! }.not_to raise_error
218
139
  end
140
+
141
+ it 'should load missing values from config file' do
142
+ subject.load!
143
+ expect(AppSettings.some_config.int_key).to eql(1)
144
+ end
145
+
146
+ it 'should override values from config file' do
147
+ subject.load!
148
+ expect(AppSettings.some_config.str_key).to eql('local')
149
+ end
150
+
151
+ context 'and some env given (as argument)' do
152
+ let(:env) { :test }
153
+
154
+ it 'should not raise an error' do
155
+ expect { subject.load!(env) }.not_to raise_error
156
+ end
157
+
158
+ it 'should load missing values from config file' do
159
+ subject.load! env
160
+ expect(AppSettings.some_config.int_key).to eql(2)
161
+ end
162
+
163
+ it 'should override values from config file' do
164
+ subject.load! env
165
+ expect(AppSettings.some_config.str_key).to eql('local')
166
+ end
167
+ end
168
+
169
+ context 'and some env given (through config.env)' do
170
+ before { subject.config.env = :test }
171
+
172
+ it 'should not raise an error' do
173
+ expect { subject.load! }.not_to raise_error
174
+ end
175
+
176
+ it 'should load missing values from config file' do
177
+ subject.load!
178
+ expect(AppSettings.some_config.int_key).to eql(2)
179
+ end
180
+
181
+ it 'should override values from config file' do
182
+ subject.load!
183
+ expect(AppSettings.some_config.str_key).to eql('local')
184
+ end
185
+ end
186
+ end
187
+ end
188
+
189
+ describe '#configure_and_load!' do
190
+ before { ElastiConf.stub(:load!).and_return(true) }
191
+
192
+ let(:config_block) do
193
+ Proc.new do |config|
194
+ config.config_root = subject.root.join('spec', 'fixtures')
195
+ config.raise_if_already_initialized_constant = false
196
+ end
197
+ end
198
+
199
+ it 'should call configure' do
200
+ subject.should_receive :configure
201
+ subject.configure_and_load! &config_block
202
+ end
203
+
204
+ it 'should call load' do
205
+ subject.should_receive :load!
206
+ subject.configure_and_load! &config_block
219
207
  end
220
208
  end
221
209
  end
data/spec/spec_helper.rb CHANGED
@@ -3,13 +3,15 @@ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
3
  require 'bundler'
4
4
  Bundler.require :default
5
5
 
6
+ require 'coveralls'
7
+ Coveralls.wear!
8
+
6
9
  require 'elasticonf'
7
10
 
8
11
  RSpec.configure do |config|
9
12
  config.treat_symbols_as_metadata_keys_with_true_values = true
10
13
  config.run_all_when_everything_filtered = true
11
- config.filter_run :focus
12
14
 
13
15
  # After each test spec rollback configuration to its default state
14
- config.after(:each) { ElastiConf.reset_config! }
16
+ config.after(:each) { ElastiConf.config.reset_config! }
15
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticonf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Rezvanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-26 00:00:00.000000000 Z
11
+ date: 2014-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -16,56 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.0
19
+ version: '3.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.0
26
+ version: '3.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: 10.3.0
33
+ version: '10.3'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: 10.3.0
40
+ version: '10.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 2.14.0
47
+ version: '2.14'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 2.14.0
54
+ version: '2.14'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: yard
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ~>
60
60
  - !ruby/object:Gem::Version
61
- version: 0.8.0
61
+ version: '0.8'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
- version: 0.8.0
68
+ version: '0.8'
69
69
  description: Powerfull and flexible application config solution worked in any ruby
70
70
  program
71
71
  email: