config_core 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/config_core.gemspec +25 -0
- data/lib/config_core/parameter.rb +33 -0
- data/lib/config_core/scope.rb +46 -0
- data/lib/config_core/scopes_collection.rb +36 -0
- data/lib/config_core/version.rb +3 -0
- data/lib/config_core.rb +20 -0
- data/spec/config_core/parameter_spec.rb +30 -0
- data/spec/config_core/scope_spec.rb +48 -0
- data/spec/config_core/scopes_collection_spec.rb +54 -0
- data/spec/spec_helper.rb +12 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3b5cd635aa34e0630c433d3806168917f4d00e12
|
4
|
+
data.tar.gz: d7dcc97440fde85bdf42a7669045470936f88f43
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f524e0a0189b3b9f79f72a68a6b5b2435d496a4f0b605f5eb941a4a2ed0719bd562bf97c0e9a97001938bc9183a0fea3d41bdc3a8b7f6a3932bb3bbe83b781af
|
7
|
+
data.tar.gz: 7fa8fb0fc2b0ba7f2e3378cf33a10ea6acc81cf0deaff54288ee54f370051089247101b5254a1ac8c435e3d5478f1f3d14fc00402ef4b2f835ca617e8757ad73
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 egoholic
|
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,31 @@
|
|
1
|
+
[](https://codeclimate.com/github/egoholic/config_core)
|
2
|
+
|
3
|
+
# ConfigCore
|
4
|
+
|
5
|
+
Simple configuration solution. Don't use FCKN_CONSTANTS - use ConfigCore.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'config_core'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install config_core
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/config_core.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'config_core/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "config_core"
|
8
|
+
spec.version = ConfigCore::VERSION
|
9
|
+
spec.authors = ["Vladimir Melnick"]
|
10
|
+
spec.email = ["egotraumatic@gmail.com"]
|
11
|
+
spec.description = %q{ConfigCore provides super simple configuration solution.}
|
12
|
+
spec.summary = %q{ConfigCore provides super simple configuration solution.}
|
13
|
+
spec.homepage = "http://rubydev.ru"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Всегда удивлялся зачем здесь git.
|
17
|
+
spec.files = `git ls-files`.split($/)
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec"
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ConfigCore
|
2
|
+
class Parameter
|
3
|
+
attr_reader :name, :value, :default_value
|
4
|
+
|
5
|
+
def initialize(name, value)
|
6
|
+
@name = name
|
7
|
+
@default_value = value
|
8
|
+
|
9
|
+
begin
|
10
|
+
@value = value.dup
|
11
|
+
rescue TypeError
|
12
|
+
@value = value
|
13
|
+
end
|
14
|
+
|
15
|
+
@editable = true
|
16
|
+
end
|
17
|
+
|
18
|
+
def disable_editing!
|
19
|
+
@editable = false
|
20
|
+
@value.freeze
|
21
|
+
end
|
22
|
+
|
23
|
+
def editable?
|
24
|
+
@editable
|
25
|
+
end
|
26
|
+
|
27
|
+
def value=(value)
|
28
|
+
raise TryingToModifyUneditableParameterError unless editable?
|
29
|
+
|
30
|
+
@value = value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module ConfigCore
|
2
|
+
class Scope
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize(name)
|
6
|
+
@name = name
|
7
|
+
@parameters = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def empty?
|
11
|
+
@parameters.empty?
|
12
|
+
end
|
13
|
+
|
14
|
+
def has_parameter?(name)
|
15
|
+
@parameters.has_key?(name)
|
16
|
+
end
|
17
|
+
|
18
|
+
def define_parameter(name, value, editable: true)
|
19
|
+
raise ParameterAlreadyExistsError if has_parameter?(name)
|
20
|
+
|
21
|
+
parameter = Parameter.new(name, value)
|
22
|
+
parameter.disable_editing! unless editable
|
23
|
+
|
24
|
+
@parameters[name] = parameter
|
25
|
+
|
26
|
+
define_parameter_reader(name)
|
27
|
+
define_parameter_value_reader(name)
|
28
|
+
define_parameter_value_writer(name)
|
29
|
+
|
30
|
+
return parameter
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def define_parameter_reader(name)
|
35
|
+
define_singleton_method(:"#{name}_parameter") { @parameters[name] }
|
36
|
+
end
|
37
|
+
|
38
|
+
def define_parameter_value_reader(name)
|
39
|
+
define_singleton_method(name) { @parameters[name].value }
|
40
|
+
end
|
41
|
+
|
42
|
+
def define_parameter_value_writer(name)
|
43
|
+
define_singleton_method(:"#{name}=") { |value| @parameters[name].value = value }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ConfigCore
|
2
|
+
class ScopesCollection
|
3
|
+
def initialize
|
4
|
+
@scopes = {}
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_h
|
8
|
+
@scopes
|
9
|
+
end
|
10
|
+
|
11
|
+
def [](name)
|
12
|
+
@scopes[name]
|
13
|
+
end
|
14
|
+
|
15
|
+
def has_scope?(name)
|
16
|
+
@scopes.has_key?(name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def define(name)
|
20
|
+
raise ScopeAlreadyExistsError if has_scope?(name)
|
21
|
+
|
22
|
+
scope = Scope.new(name)
|
23
|
+
yield(scope) if block_given?
|
24
|
+
@scopes[name] = scope
|
25
|
+
|
26
|
+
define_scope_reader(name)
|
27
|
+
|
28
|
+
return scope
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def define_scope_reader(name)
|
33
|
+
define_singleton_method(name) { @scopes[name] }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/config_core.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'config_core/version'
|
2
|
+
require 'config_core/scopes_collection'
|
3
|
+
require 'config_core/scope'
|
4
|
+
require 'config_core/parameter'
|
5
|
+
|
6
|
+
module ConfigCore
|
7
|
+
class ScopeAlreadyExistsError < StandardError; end
|
8
|
+
class ParameterAlreadyExistsError < StandardError; end
|
9
|
+
class TryingToModifyUneditableParameterError < StandardError; end
|
10
|
+
|
11
|
+
def self.extended(klass)
|
12
|
+
klass.instance_variable_set(:@config_scopes_collection, ScopesCollection.new)
|
13
|
+
end
|
14
|
+
|
15
|
+
def scopes
|
16
|
+
@config_scopes_collection
|
17
|
+
end
|
18
|
+
|
19
|
+
alias config scopes
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ConfigCore::Parameter do
|
4
|
+
let(:value) { 'value' }
|
5
|
+
let(:new_value) { 'new value' }
|
6
|
+
let(:parameter) { ConfigCore::Parameter.new(:name, value) }
|
7
|
+
|
8
|
+
subject { parameter}
|
9
|
+
|
10
|
+
its(:name) { should be :name }
|
11
|
+
its(:value) { should eq value }
|
12
|
+
its(:default_value) { should eq value }
|
13
|
+
its(:default_value) { should_not be subject.value }
|
14
|
+
|
15
|
+
it { expect { parameter.value = new_value }.to_not change { parameter.default_value }.from(value) }
|
16
|
+
|
17
|
+
context 'when editable' do
|
18
|
+
its(:editable?) { should be_true }
|
19
|
+
|
20
|
+
it { expect { parameter.value = new_value }.to change { parameter.value }.from(value).to(new_value) }
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when uneditable' do
|
24
|
+
before { parameter.disable_editing! }
|
25
|
+
|
26
|
+
its(:editable?) { should be_false }
|
27
|
+
|
28
|
+
it { expect { parameter.value = new_value }.to raise_error(ConfigCore::TryingToModifyUneditableParameterError) }
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ConfigCore::Scope do
|
4
|
+
let(:scope) { ConfigCore::Scope.new(:core) }
|
5
|
+
let(:value) { 'value' }
|
6
|
+
let(:new_value) { 'new_value' }
|
7
|
+
|
8
|
+
subject { scope }
|
9
|
+
|
10
|
+
its(:name) { should be :core }
|
11
|
+
|
12
|
+
describe '#empty?' do
|
13
|
+
it { expect { scope.define_parameter(:items_per_page, 10) }.to change { scope.empty? }.from(true).to(false) }
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#has_parameter?' do
|
17
|
+
it { expect { scope.define_parameter(:items_per_page, 10) }.to change { scope.has_parameter?(:items_per_page) }.from(false).to(true) }
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#define_parameter' do
|
21
|
+
it { expect { scope.define_parameter(:param, value) }.to change { scope.has_parameter?(:param) }.to(true) }
|
22
|
+
|
23
|
+
context 'when parameter already exists' do
|
24
|
+
before { scope.define_parameter(:param, value) }
|
25
|
+
|
26
|
+
it { expect { scope.define_parameter(:param, value) }.to raise_error(ConfigCore::ParameterAlreadyExistsError) }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'parameter/parameter value accessors' do
|
30
|
+
context 'when editable parameter' do
|
31
|
+
before { scope.define_parameter(:param, value) }
|
32
|
+
|
33
|
+
its(:param_parameter) { should be_a ConfigCore::Parameter }
|
34
|
+
its(:param) { should == value }
|
35
|
+
it { expect { scope.param = new_value }.to change { scope.param }.to(new_value) }
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when uneditable parameter' do
|
39
|
+
before { scope.define_parameter(:param, value, editable: false) }
|
40
|
+
|
41
|
+
its(:param_parameter) { should be_a ConfigCore::Parameter }
|
42
|
+
its(:param) { should == value }
|
43
|
+
it { expect { scope.param = new_value }.to raise_error(ConfigCore::TryingToModifyUneditableParameterError) }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ConfigCore::ScopesCollection do
|
4
|
+
let!(:scopes_collection) { ConfigCore::ScopesCollection.new }
|
5
|
+
|
6
|
+
subject { scopes_collection }
|
7
|
+
|
8
|
+
describe '#to_h' do
|
9
|
+
context 'when empty' do
|
10
|
+
its(:to_h) { should == {} }
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'when scopes defined' do
|
14
|
+
before { scopes_collection.define(:core) }
|
15
|
+
|
16
|
+
it { scopes_collection.to_h.should have(1).scope }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#[]' do
|
21
|
+
context 'when empty' do
|
22
|
+
it { scopes_collection[:core].should be_nil }
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'when scopes defined' do
|
26
|
+
before { scopes_collection.define(:core) }
|
27
|
+
|
28
|
+
it { scopes_collection[:core].should be_a ConfigCore::Scope }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#has_scope?' do
|
33
|
+
it { expect { scopes_collection.define(:core).to change { scopes_collection.has_scope?(:core) }.from(false).to(true) } }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#define' do
|
37
|
+
context 'when scope already exists' do
|
38
|
+
before { scopes_collection.define(:core) }
|
39
|
+
|
40
|
+
it { expect { scopes_collection.define(:core) }.to raise_error(ConfigCore::ScopeAlreadyExistsError) }
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when scope not exists' do
|
44
|
+
it { expect { scopes_collection.define(:core) }.to change { scopes_collection.has_scope?(:core) }.from(false).to(true)}
|
45
|
+
|
46
|
+
describe 'scope reader' do
|
47
|
+
before { scopes_collection.define(:core) }
|
48
|
+
|
49
|
+
it { scopes_collection.should respond_to(:core) }
|
50
|
+
its(:core) { should be_a ConfigCore::Scope }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: config_core
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vladimir Melnick
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: ConfigCore provides super simple configuration solution.
|
56
|
+
email:
|
57
|
+
- egotraumatic@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- config_core.gemspec
|
68
|
+
- lib/config_core.rb
|
69
|
+
- lib/config_core/parameter.rb
|
70
|
+
- lib/config_core/scope.rb
|
71
|
+
- lib/config_core/scopes_collection.rb
|
72
|
+
- lib/config_core/version.rb
|
73
|
+
- spec/config_core/parameter_spec.rb
|
74
|
+
- spec/config_core/scope_spec.rb
|
75
|
+
- spec/config_core/scopes_collection_spec.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
homepage: http://rubydev.ru
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.0.3
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: ConfigCore provides super simple configuration solution.
|
101
|
+
test_files:
|
102
|
+
- spec/config_core/parameter_spec.rb
|
103
|
+
- spec/config_core/scope_spec.rb
|
104
|
+
- spec/config_core/scopes_collection_spec.rb
|
105
|
+
- spec/spec_helper.rb
|