elasticonf 1.1.3 → 1.1.4

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: fa70ead7bcaae31e24429db8b9054eb62aaef07a
4
- data.tar.gz: 5a0e3c812f8b3e9454d05ce74ac06a2fff6cc408
3
+ metadata.gz: c7d9d65ebdccdbdabb548b8b36628247765a3ce3
4
+ data.tar.gz: ee94d162f67b29f3caca0df5296d6381a5cf9df9
5
5
  SHA512:
6
- metadata.gz: b36e15f8901a3aaee7a635550ea462e29d08d64d14634a2f4907ff89764796a0865275f9918c896adea09bddb693c706a2150a7336f251f0f5dd0dd6047df384
7
- data.tar.gz: 1aadce5ac6ce226e40c2de0dfb176275d6e9e2873534fa6b1f5c40f5cb2d5f4f2a9fb78279e990e6daccb9af7e37b9bb7f73d02d8f468174dc8b4225c0fef361
6
+ metadata.gz: 4aed8f70ff65d966b3658b61ed55e7bc320f55743f7b8127b342db722b6a3158eac3925b5f762909fe3be6780322502784b070372eefe73ed3e06c3a51052168
7
+ data.tar.gz: 24a0acd93cfbdba4edbbd14df9c2d3ae310e92892d8d72deeda9a567deddbb5b579c33cd5404b73b232504f06821d2e32887211ac146e449bff102e2f90eb4ec
data/.gitignore CHANGED
@@ -3,4 +3,4 @@
3
3
  doc
4
4
  pkg
5
5
  vendor/bundle
6
- coverage/
6
+ coverage/
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
1
  --color
2
- --format progress
2
+ --format progress
data/.travis.yml CHANGED
@@ -1,22 +1,26 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - ruby-head
5
- - jruby-head
6
- - rbx-head
7
- - 2.1.2
8
- - 2.1.1
9
- - 2.1.0
10
- - 2.0.0
11
- - 1.9.3
12
4
  - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.10
8
+ - 2.2.9
9
+ - 2.3.6
10
+ - 2.4.3
11
+ - 2.5.0
13
12
 
14
13
  matrix:
15
14
  allow_failures:
16
- - rvm: ruby-head
17
- - rvm: jruby-head
18
- - rvm: rbx-head
15
+ - rvm: 1.9.2
16
+ - rvm: 1.9.3
17
+ - rvm: 2.0.0
18
+ - rvm: 2.1.10
19
+ - rvm: 2.2.9
19
20
 
20
21
  branches:
21
22
  only:
22
- - master
23
+ - master
24
+
25
+ before_install:
26
+ - gem install bundler
data/.yardopts CHANGED
@@ -1,2 +1,2 @@
1
1
  --main README.md
2
- --no-private
2
+ --no-private
data/Gemfile CHANGED
@@ -4,4 +4,4 @@ gemspec
4
4
 
5
5
  group :test do
6
6
  gem 'coveralls', require: false
7
- end
7
+ end
data/Gemfile.lock CHANGED
@@ -1,28 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- elasticonf (1.1.3)
5
- hashie (>= 2.0)
4
+ elasticonf (1.1.4)
5
+ hashie (~> 3.0)
6
+ semantic (> 0)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- coveralls (0.7.1)
11
- multi_json (~> 1.3)
12
- rest-client
13
- simplecov (>= 0.7)
14
- term-ansicolor
15
- thor
16
- diff-lcs (1.2.5)
11
+ coveralls (0.8.21)
12
+ json (>= 1.8, < 3)
13
+ simplecov (~> 0.14.1)
14
+ term-ansicolor (~> 1.3)
15
+ thor (~> 0.19.4)
16
+ tins (~> 1.6)
17
+ diff-lcs (1.3)
17
18
  docile (1.1.5)
18
- hashie (3.3.1)
19
- mime-types (2.3)
20
- multi_json (1.10.1)
21
- netrc (0.7.7)
22
- rake (10.3.2)
23
- rest-client (1.7.2)
24
- mime-types (>= 1.16, < 3.0)
25
- netrc (~> 0.7)
19
+ hashie (3.5.7)
20
+ json (2.1.0)
21
+ rake (10.5.0)
26
22
  rspec (2.14.1)
27
23
  rspec-core (~> 2.14.0)
28
24
  rspec-expectations (~> 2.14.0)
@@ -31,16 +27,17 @@ GEM
31
27
  rspec-expectations (2.14.5)
32
28
  diff-lcs (>= 1.1.3, < 2.0)
33
29
  rspec-mocks (2.14.6)
34
- simplecov (0.9.0)
30
+ semantic (1.6.0)
31
+ simplecov (0.14.1)
35
32
  docile (~> 1.1.0)
36
- multi_json
37
- simplecov-html (~> 0.8.0)
38
- simplecov-html (0.8.0)
39
- term-ansicolor (1.3.0)
33
+ json (>= 1.8, < 3)
34
+ simplecov-html (~> 0.10.0)
35
+ simplecov-html (0.10.2)
36
+ term-ansicolor (1.6.0)
40
37
  tins (~> 1.0)
41
- thor (0.19.1)
42
- tins (1.3.2)
43
- yard (0.8.7.4)
38
+ thor (0.19.4)
39
+ tins (1.16.3)
40
+ yard (0.9.12)
44
41
 
45
42
  PLATFORMS
46
43
  ruby
@@ -48,6 +45,9 @@ PLATFORMS
48
45
  DEPENDENCIES
49
46
  coveralls
50
47
  elasticonf!
51
- rake (~> 10.3)
48
+ rake (~> 10.0)
52
49
  rspec (~> 2.14.0)
53
50
  yard (~> 0.8)
51
+
52
+ BUNDLED WITH
53
+ 1.16.0
data/LICENSE CHANGED
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,25 +1,103 @@
1
+ <img align="left" src="/logo.png?raw=true"></img>
2
+
1
3
  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
4
  ==========
3
5
 
6
+ <br />
7
+
4
8
  Powerfull and flexible application config solution worked in any ruby program. No clases definition, no dependencies. It just works!
5
9
 
10
+ ## Prerequisites
11
+
12
+ You need to have Ruby 2.0 or higher installed on your system.
13
+
6
14
  ## Installation
7
15
 
8
16
  First add the following lines to your application `Gemfile`:
9
17
 
10
- ``` ruby
11
- gem 'elasticonf', '~> 1.1.0'
18
+ ```ruby
19
+ gem 'elasticonf', '~> 1.1.4'
12
20
  ```
13
21
 
14
22
  Then run `bundle install` to update your's gems bundle.
15
23
 
16
- ## Configuration
24
+ ## Setup and usage
25
+
26
+ For basic setup you must pass a block to `Elasticonf.configure` method and call `Elasticonf.load!`.
27
+
28
+ To load settings from the file `some/path/settings.yml` and define `Settings` constant, you need to run the following code:
29
+
30
+ ```ruby
31
+ require 'elasticonf'
32
+
33
+ Elasticonf.configure do |config|
34
+ config.config_root = 'some/path'
35
+ end
36
+
37
+ Elasticonf.load!
38
+ puts Settings.some_key # will print some value
39
+ ```
40
+
41
+ To load settings from the file `some/path/config.yml` and define `Config` constant, you need:
42
+
43
+ ```ruby
44
+ require 'elasticonf'
45
+
46
+ Elasticonf.configure do |config|
47
+ config.config_root = 'some/path'
48
+ config.config_file = 'config'
49
+ config.constant_name = 'Config'
50
+ end
51
+
52
+ Elasticonf.load!
53
+ puts Config.some_key # will print some value
54
+ ```
55
+
56
+ There is also support for multi environment. To do this change the value of the `config.env` (the default is `'development'`).
17
57
 
18
- Will be available soon.
58
+ Elasticonf supports the following priorities of files (the priority decreases from top to bottom). For the default configuration:
59
+
60
+ 0. `#{Elasticonf.config_root}/settings.local.yml`
61
+ 0. `#{Elasticonf.config_root}/settings/development.yml`
62
+ 0. `#{Elasticonf.config_root}/settings.yml`
63
+
64
+ Sometimes there can be a situation when the constant defined Elasticonf already exists. In this case, exception will raise and method execution will stop. To change this behavior you need to set `config.raise_if_already_initialized_constant` to `false`. Take a look:
65
+
66
+ ```ruby
67
+ require 'elasticonf'
68
+
69
+ Settings = "I'm predefined constant!"
70
+
71
+ Elasticonf.configure do |config|
72
+ config.config_root = 'some/path'
73
+ end
74
+
75
+ Elasticonf.load! # will raise RuntimeError "Cannot set constant Settings because it is already initialized"
76
+ ```
77
+
78
+ However, this code is okay:
79
+
80
+ ```ruby
81
+ require 'elasticonf'
82
+
83
+ Settings = "I'm predefined constant!"
84
+
85
+ Elasticonf.configure do |config|
86
+ config.config_root = 'some/path'
87
+ config.raise_if_already_initialized_constant = false
88
+ end
89
+
90
+ Elasticonf.load! # will not raise any error
91
+ puts Settings.some_key # will print some value
92
+ ```
19
93
 
20
94
  ## Documentation
21
95
 
22
- Will be available soon.
96
+ Run this commands in terminal:
97
+
98
+ 0. `cd path/to/elasticonf/repo`
99
+ 0. `bin/yard server`
100
+ 0. Go to [http://localhost:8808](http://localhost:8808) (by default) in your favorite browser
23
101
 
24
102
  ## Testing
25
103
 
@@ -37,4 +115,4 @@ Elasticonf uses RubyGems Rational Versioning Policy.
37
115
 
38
116
  ## Copyright
39
117
 
40
- See LICENSE file.
118
+ See LICENSE file.
data/Rakefile CHANGED
@@ -8,4 +8,4 @@ RSpec::Core::RakeTask.new do |spec|
8
8
  spec.pattern = 'spec/**/*_spec.rb'
9
9
  end
10
10
 
11
- task default: :spec
11
+ task default: :spec
data/elasticonf.gemspec CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
 
8
8
  s.version = Elasticonf::VERSION
9
9
  s.platform = Gem::Platform::RUBY
10
-
10
+
11
11
  s.authors = ['Sergey Rezvanov']
12
12
  s.email = ['sergey@rezvanov.info']
13
13
  s.homepage = 'https://github.com/rezwyi/elasticonf'
@@ -19,9 +19,10 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.required_ruby_version = '>= 1.9'
21
21
 
22
- s.add_dependency 'hashie', '>= 2.0'
22
+ s.add_dependency 'hashie', '~> 3.0'
23
+ s.add_dependency 'semantic', '> 0'
23
24
 
24
- s.add_development_dependency 'rake', '~> 10.3'
25
+ s.add_development_dependency 'rake', '~> 10.0'
25
26
  s.add_development_dependency 'rspec', '~> 2.14.0'
26
27
  s.add_development_dependency 'yard', '~> 0.8'
27
28
  end
data/lib/elasticonf.rb CHANGED
@@ -29,7 +29,7 @@ module Elasticonf
29
29
  end
30
30
 
31
31
  loader = Loader[YAML.load_file(config_file)]
32
-
32
+
33
33
  env_config_file = config.config_root.join(config.config_file, "#{config.env}.yml")
34
34
  if File.exists?(env_config_file)
35
35
  loader = loader.deep_merge(Loader[YAML.load_file(env_config_file)])
@@ -39,13 +39,13 @@ module Elasticonf
39
39
  if File.exists?(local_config_file)
40
40
  loader = loader.deep_merge(Loader[YAML.load_file(local_config_file)])
41
41
  end
42
-
42
+
43
43
  if Kernel.const_defined?(config.const_name)
44
44
  config.raise_if_already_initialized_constant ?
45
45
  raise("Cannot set constant #{config.const_name} because it is already initialized") :
46
46
  Kernel.send(:remove_const, config.const_name)
47
47
  end
48
-
48
+
49
49
  Kernel.const_set config.const_name, loader
50
50
  end
51
51
 
@@ -60,4 +60,4 @@ module Elasticonf
60
60
  configure { |config| yield(config) }
61
61
  load!
62
62
  end
63
- end
63
+ end
@@ -11,7 +11,7 @@ module Elasticonf
11
11
  instance_variable_set "@#{v}", nil
12
12
  end
13
13
  end
14
-
14
+
15
15
  def env
16
16
  @env ||= 'development'
17
17
  end
@@ -67,4 +67,4 @@ module Elasticonf
67
67
  @raise_if_already_initialized_constant = value
68
68
  end
69
69
  end
70
- end
70
+ end
@@ -1,17 +1,25 @@
1
+ require 'semantic'
2
+
1
3
  module Elasticonf
2
4
  class Loader < Hashie::Mash
3
5
  def get(key)
4
6
  unless [String, Symbol].include?(key.class)
5
7
  raise ArgumentError, "String or Symbol expected #{key.class} given"
6
8
  end
7
-
8
- hash, items = self, key.split('.')
9
-
10
- while (item = items.shift)
11
- (hash = hash[item.to_sym]) || break
12
- end
13
9
 
14
- hash
10
+ ruby_version = Semantic::Version.new(RUBY_VERSION)
11
+
12
+ if ruby_version.major == 2 && ruby_version.minor >= 3
13
+ dig *key.split('.')
14
+ else
15
+ result, items = self.dup, key.split('.')
16
+
17
+ while (item = items.shift)
18
+ (result = result[item.to_sym]) || break
19
+ end
20
+
21
+ result
22
+ end
15
23
  end
16
24
  end
17
- end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module Elasticonf
2
- VERSION = '1.1.3'
3
- end
2
+ VERSION = '1.1.4'
3
+ end
data/logo.png ADDED
Binary file
@@ -1,3 +1,3 @@
1
1
  some_config:
2
2
  int_key: 1
3
- str_key: '1'
3
+ str_key: '1'
@@ -1,3 +1,3 @@
1
1
  some_config:
2
2
  int_key: 3
3
- str_key: '3'
3
+ str_key: '3'
@@ -1,3 +1,3 @@
1
1
  some_config:
2
2
  int_key: 2
3
- str_key: '2'
3
+ str_key: '2'
@@ -1,3 +1,3 @@
1
1
  some_config:
2
2
  int_key: 1
3
- str_key: '1'
3
+ str_key: '1'
@@ -8,10 +8,10 @@ describe Elasticonf::Config do
8
8
  subject.config_file = 'application'
9
9
  subject.const_name = 'AppSettings'
10
10
  subject.raise_if_already_initialized_constant = false
11
-
11
+
12
12
  subject.reset_config!
13
13
  end
14
-
14
+
15
15
  its(:env) { should eql('development') }
16
16
  its(:config_file) { should eql('settings') }
17
17
  its(:const_name) { should eql('Settings') }
@@ -144,7 +144,7 @@ describe Elasticonf::Config do
144
144
  subject.raise_if_already_initialized_constant = :some_symbol
145
145
  }.to raise_error
146
146
  end
147
-
147
+
148
148
  it 'should raise an error' do
149
149
  expect {
150
150
  subject.raise_if_already_initialized_constant = -> {}
@@ -164,4 +164,4 @@ describe Elasticonf::Config do
164
164
  end
165
165
  end
166
166
  end
167
- end
167
+ end
@@ -5,7 +5,7 @@ describe Elasticonf::Loader do
5
5
  file = Elasticonf.root.join('spec', 'fixtures', 'config.yml')
6
6
  described_class[YAML.load_file(file)]
7
7
  end
8
-
8
+
9
9
  it 'should be inherited from Hashie::Mash' do
10
10
  subject.should be_kind_of(Hashie::Mash)
11
11
  end
@@ -14,7 +14,7 @@ describe Elasticonf::Loader do
14
14
  it 'should return nil' do
15
15
  expect(subject.get('some.unexisting.key')).to be_nil
16
16
  end
17
-
17
+
18
18
  it 'should return some value' do
19
19
  expect(subject.get('some_config.int_key')).to eql(1)
20
20
  end
@@ -27,7 +27,7 @@ describe Elasticonf::Loader do
27
27
  it 'should raise an error' do
28
28
  expect { subject.get }.to raise_error
29
29
  end
30
-
30
+
31
31
  it 'should raise an error' do
32
32
  expect { subject.get({}) }.to raise_error
33
33
  end
@@ -41,4 +41,4 @@ describe Elasticonf::Loader do
41
41
  end
42
42
  end
43
43
  end
44
- end
44
+ end
@@ -73,7 +73,7 @@ describe Elasticonf do
73
73
 
74
74
  context 'when some env given (as argument)' do
75
75
  let(:env) { :test }
76
-
76
+
77
77
  it 'should not raise an error' do
78
78
  expect { subject.load!(env) }.not_to raise_error
79
79
  end
@@ -109,7 +109,7 @@ describe Elasticonf do
109
109
 
110
110
  context 'when already initialized constant' do
111
111
  before { Kernel.const_set(const_name, {}) }
112
-
112
+
113
113
  it 'should raise an error' do
114
114
  expect { subject.load! }.to raise_error
115
115
  end
@@ -123,7 +123,7 @@ describe Elasticonf do
123
123
  context 'when .local file present' do
124
124
  let(:config_file) { subject.config.config_root.join('application.yml') }
125
125
  let(:local_config_file) { subject.config.config_root.join('application.local.yml') }
126
-
126
+
127
127
  before do
128
128
  YAML::load_file(config_file).tap do |config|
129
129
  config['some_config']['str_key'] = 'local'
@@ -142,7 +142,7 @@ describe Elasticonf do
142
142
  subject.load!
143
143
  expect(AppSettings.some_config.int_key).to eql(1)
144
144
  end
145
-
145
+
146
146
  it 'should override values from config file' do
147
147
  subject.load!
148
148
  expect(AppSettings.some_config.str_key).to eql('local')
@@ -189,14 +189,14 @@ describe Elasticonf do
189
189
  describe '#reload!' do
190
190
  let(:config_file) { subject.config.config_root.join('application.yml') }
191
191
  let(:bak_file) { subject.config.config_root.join('application.bak') }
192
-
192
+
193
193
  before do
194
194
  subject.configure do |config|
195
195
  config.config_root = subject.root.join('spec', 'fixtures')
196
196
  config.config_file = 'application'
197
197
  config.const_name = 'AppSettings'
198
198
  end
199
-
199
+
200
200
  subject.load!
201
201
 
202
202
  # Assume that our configuration has been changed since we have already
@@ -217,14 +217,14 @@ describe Elasticonf do
217
217
 
218
218
  describe '#configure_and_load!' do
219
219
  before { Elasticonf.stub(:load!).and_return(true) }
220
-
220
+
221
221
  let(:config_block) do
222
222
  Proc.new do |config|
223
223
  config.config_root = subject.root.join('spec', 'fixtures')
224
224
  config.raise_if_already_initialized_constant = false
225
225
  end
226
226
  end
227
-
227
+
228
228
  it 'should call configure' do
229
229
  subject.should_receive :configure
230
230
  subject.configure_and_load! &config_block
@@ -235,4 +235,4 @@ describe Elasticonf do
235
235
  subject.configure_and_load! &config_block
236
236
  end
237
237
  end
238
- end
238
+ end
data/spec/spec_helper.rb CHANGED
@@ -12,4 +12,4 @@ RSpec.configure do |config|
12
12
 
13
13
  # After each test spec rollback configuration to its default state
14
14
  config.after(:each) { Elasticonf.config.reset_config! }
15
- end
15
+ end
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elasticonf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
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-09-15 00:00:00.000000000 Z
11
+ date: 2018-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: semantic
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
18
32
  - !ruby/object:Gem::Version
19
- version: '2.0'
33
+ version: '0'
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - ">="
38
+ - - ">"
25
39
  - !ruby/object:Gem::Version
26
- version: '2.0'
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '10.3'
47
+ version: '10.0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '10.3'
54
+ version: '10.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +108,7 @@ files:
94
108
  - lib/elasticonf/config.rb
95
109
  - lib/elasticonf/loader.rb
96
110
  - lib/elasticonf/version.rb
111
+ - logo.png
97
112
  - spec/fixtures/application.yml
98
113
  - spec/fixtures/application/production.yml
99
114
  - spec/fixtures/application/test.yml
@@ -122,9 +137,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
137
  version: '0'
123
138
  requirements: []
124
139
  rubyforge_project:
125
- rubygems_version: 2.2.2
140
+ rubygems_version: 2.6.14
126
141
  signing_key:
127
142
  specification_version: 4
128
143
  summary: Powerfull and flexible application config solution worked in any ruby program
129
144
  test_files: []
130
- has_rdoc: