confrider 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +24 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +13 -0
- data/confrider.gemspec +19 -0
- data/lib/confrider/core.rb +29 -0
- data/lib/confrider/version.rb +3 -0
- data/lib/confrider.rb +8 -0
- data/spec/lib/confrider/core_spec.rb +39 -0
- data/spec/lib/confrider/version_spec.rb +6 -0
- data/spec/lib/confrider_spec.rb +7 -0
- data/spec/spec_helper.rb +7 -0
- metadata +86 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
confrider (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.3)
|
10
|
+
rspec (2.10.0)
|
11
|
+
rspec-core (~> 2.10.0)
|
12
|
+
rspec-expectations (~> 2.10.0)
|
13
|
+
rspec-mocks (~> 2.10.0)
|
14
|
+
rspec-core (2.10.1)
|
15
|
+
rspec-expectations (2.10.0)
|
16
|
+
diff-lcs (~> 1.1.3)
|
17
|
+
rspec-mocks (2.10.1)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
confrider!
|
24
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Artiom Di
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Confrider
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'confrider'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install confrider
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'rubygems' if RUBY_VERSION < '1.9'
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
|
7
|
+
desc 'Default run rake spec'
|
8
|
+
task :default => :spec
|
9
|
+
|
10
|
+
desc 'Run all tests'
|
11
|
+
task :spec do
|
12
|
+
system('bundle exec rspec spec')
|
13
|
+
end
|
data/confrider.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/confrider/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['Artiom Di']
|
6
|
+
gem.email = ['kron82@gmail.com']
|
7
|
+
gem.summary = %q{manage config options like i18n}
|
8
|
+
gem.description = %q{}
|
9
|
+
gem.homepage = 'https://github.com/kron4eg/confrider'
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = 'confrider'
|
15
|
+
gem.require_paths = ['lib']
|
16
|
+
gem.version = Confrider::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency 'rspec'
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class Confrider::Core
|
2
|
+
def initialize(hash)
|
3
|
+
@vault = {}
|
4
|
+
save_hash(nil, hash)
|
5
|
+
end
|
6
|
+
|
7
|
+
def [](key, default_value = nil)
|
8
|
+
@vault.fetch(key, default_value)
|
9
|
+
end
|
10
|
+
|
11
|
+
def save(key, value)
|
12
|
+
@vault[key] = value
|
13
|
+
end
|
14
|
+
|
15
|
+
def save_hash(key, hash)
|
16
|
+
@vault[key] = hash if key
|
17
|
+
hash.each do |inner_key, value|
|
18
|
+
normalized_key = normalize_keys(key, inner_key)
|
19
|
+
case value
|
20
|
+
when Hash then save_hash(normalized_key, value)
|
21
|
+
else save(normalized_key, value)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def normalize_keys(*keys)
|
27
|
+
keys.join('.').gsub(/^\./, '')
|
28
|
+
end
|
29
|
+
end
|
data/lib/confrider.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Confrider::Core do
|
4
|
+
let(:cfg) { Confrider::Core.new :foo => 'bar' }
|
5
|
+
|
6
|
+
context '#initialize' do
|
7
|
+
it 'should init @vault' do
|
8
|
+
cfg.instance_variable_get('@vault').should be
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context '#save_hash' do
|
13
|
+
let(:cfg) { Confrider::Core.new 'foo' => {'bar' => {'baz' => 'value'}} }
|
14
|
+
|
15
|
+
it 'should flatten hash keys' do
|
16
|
+
cfg['foo.bar.baz'].should == 'value'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context '#[]' do
|
21
|
+
it 'should return value' do
|
22
|
+
cfg['foo'].should == 'bar'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should return default value if nothing found' do
|
26
|
+
cfg['foo2', 'default value'].should == 'default value'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context '#normalize_keys' do
|
31
|
+
it 'should join keys with "."' do
|
32
|
+
cfg.normalize_keys('q', 'a', 'z').should == 'q.a.z'
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should remove leading "."' do
|
36
|
+
cfg.normalize_keys(nil, 'q').should == 'q'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: confrider
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Artiom Di
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: ''
|
31
|
+
email:
|
32
|
+
- kron82@gmail.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- .rspec
|
39
|
+
- Gemfile
|
40
|
+
- Gemfile.lock
|
41
|
+
- LICENSE
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- confrider.gemspec
|
45
|
+
- lib/confrider.rb
|
46
|
+
- lib/confrider/core.rb
|
47
|
+
- lib/confrider/version.rb
|
48
|
+
- spec/lib/confrider/core_spec.rb
|
49
|
+
- spec/lib/confrider/version_spec.rb
|
50
|
+
- spec/lib/confrider_spec.rb
|
51
|
+
- spec/spec_helper.rb
|
52
|
+
homepage: https://github.com/kron4eg/confrider
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
hash: -2599701976609297857
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
hash: -2599701976609297857
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.8.23
|
79
|
+
signing_key:
|
80
|
+
specification_version: 3
|
81
|
+
summary: manage config options like i18n
|
82
|
+
test_files:
|
83
|
+
- spec/lib/confrider/core_spec.rb
|
84
|
+
- spec/lib/confrider/version_spec.rb
|
85
|
+
- spec/lib/confrider_spec.rb
|
86
|
+
- spec/spec_helper.rb
|