configurate 0.0.5 → 0.0.6
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 +4 -4
- checksums.yaml.gz.asc +7 -7
- data.tar.gz.asc +7 -7
- data/lib/configurate.rb +10 -7
- data/lib/configurate/lookup_chain.rb +1 -1
- data/lib/configurate/provider/yaml.rb +2 -2
- data/lib/configurate/setting_path.rb +48 -10
- data/spec/configurate/lookup_chain_spec.rb +3 -2
- data/spec/configurate/setting_path_spec.rb +43 -8
- metadata +2 -2
- metadata.gz.asc +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c9982f04f1f636cbc5b6b9c5e45fdf1bdd94cdb
|
4
|
+
data.tar.gz: 62d95c25d55ab621123bb07d9a55fbac43c71e4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d697a43c3f69158c8d1fcfe0b232601830826d5a5c720e6628046dfbe21b110d9f42f04dbf1c1cd02ec3b59f7bf1f000c9241883e3393039e889e518bc5aaee1
|
7
|
+
data.tar.gz: d1ef8990fbb620024dca6093bb075211c8c7fe123e1105447f436eba924a8700aa3f006a7d81cfe4e2d654d976fccd5551f9f325d46b683fcb511772bdb9b21c
|
checksums.yaml.gz.asc
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
-----BEGIN PGP SIGNATURE-----
|
2
2
|
Version: GnuPG v2.0.19 (GNU/Linux)
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
=
|
4
|
+
iQEcBAABAgAGBQJRcoukAAoJEPNH4OtHrHDWxfsH/RyFwwVlzI/nMKCgHReF4ljO
|
5
|
+
MfIPgiyuDlOXAPCBpMNQy+Wi4cGepmiKogteDRG6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+
require 'forwardable'
|
1
2
|
|
2
3
|
require 'configurate/setting_path'
|
3
4
|
require 'configurate/lookup_chain'
|
@@ -39,6 +40,13 @@ module Configurate
|
|
39
40
|
attr_reader :lookup_chain
|
40
41
|
|
41
42
|
undef_method :method # Remove possible conflicts with common setting names
|
43
|
+
|
44
|
+
extend Forwardable
|
45
|
+
|
46
|
+
def initialize
|
47
|
+
@lookup_chain = LookupChain.new
|
48
|
+
$stderr.puts "Warning you called Configurate::Settings.new with a block, you really meant to call #create" if block_given?
|
49
|
+
end
|
42
50
|
|
43
51
|
# @!method lookup(setting)
|
44
52
|
# (see {LookupChain#lookup})
|
@@ -49,18 +57,13 @@ module Configurate
|
|
49
57
|
# @!method [](setting)
|
50
58
|
# (see {LookupChain#[]})
|
51
59
|
|
60
|
+
def_delegators :@lookup_chain, :lookup, :add_provider, :[]
|
61
|
+
|
52
62
|
# See description and {#lookup}, {#[]} and {#add_provider}
|
53
63
|
def method_missing(method, *args, &block)
|
54
|
-
return @lookup_chain.public_send(method, *args, &block) if [:lookup, :add_provider, :[]].include?(method)
|
55
|
-
|
56
64
|
Proxy.new(@lookup_chain).public_send(method, *args, &block)
|
57
65
|
end
|
58
66
|
|
59
|
-
def initialize
|
60
|
-
@lookup_chain = LookupChain.new
|
61
|
-
$stderr.puts "Warning you called Configurate::Settings.new with a block, you really meant to call #create" if block_given?
|
62
|
-
end
|
63
|
-
|
64
67
|
# Create a new configuration object
|
65
68
|
# @yield the given block will be evaluated in the context of the new object
|
66
69
|
def self.create(&block)
|
@@ -31,7 +31,7 @@ module Configurate
|
|
31
31
|
# @return [Array,Hash,String,Boolean,nil] whatever the responding
|
32
32
|
# provider provides is casted to a {String}, except for some special values
|
33
33
|
def lookup(setting, *args)
|
34
|
-
setting = SettingPath.
|
34
|
+
setting = SettingPath.new setting if setting.is_a? String
|
35
35
|
@provider.each do |provider|
|
36
36
|
begin
|
37
37
|
return special_value_or_string(provider.lookup(setting.dup, *args))
|
@@ -19,8 +19,8 @@ module Configurate; module Provider
|
|
19
19
|
|
20
20
|
namespace = opts.delete(:namespace)
|
21
21
|
unless namespace.nil?
|
22
|
-
|
23
|
-
actual_settings = lookup_in_hash(
|
22
|
+
namespace_path = SettingPath.new namespace
|
23
|
+
actual_settings = lookup_in_hash(namespace_path, @settings)
|
24
24
|
if !actual_settings.nil?
|
25
25
|
@settings = actual_settings
|
26
26
|
elsif required
|
@@ -1,17 +1,26 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
1
3
|
module Configurate
|
2
4
|
# Class encapsulating the concept of a path to a setting
|
3
|
-
class SettingPath
|
5
|
+
class SettingPath
|
6
|
+
include Enumerable
|
7
|
+
extend Forwardable
|
4
8
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def self.from_string(path)
|
9
|
-
SettingPath.new(path.split("."))
|
9
|
+
def initialize path=[]
|
10
|
+
path = path.split(".") if path.is_a? String
|
11
|
+
@path = path
|
10
12
|
end
|
11
13
|
|
14
|
+
def_delegators :@path, :empty?, :last, :join, :length, :size, :hsh
|
15
|
+
|
12
16
|
# Whether the current path looks like a question or setter method
|
13
17
|
def is_question_or_setter?
|
14
|
-
|
18
|
+
is_question? || is_setter?
|
19
|
+
end
|
20
|
+
|
21
|
+
# Whether the current path looks like a question method
|
22
|
+
def is_question?
|
23
|
+
last.to_s.end_with?("?")
|
15
24
|
end
|
16
25
|
|
17
26
|
# Whether the current path looks like a setter method
|
@@ -19,16 +28,45 @@ module Configurate
|
|
19
28
|
last.to_s.end_with?("=")
|
20
29
|
end
|
21
30
|
|
31
|
+
def each
|
32
|
+
return to_enum(:each) unless block_given?
|
33
|
+
@path.each do |component|
|
34
|
+
yield clean_special_characters(component)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
22
38
|
def <<(component)
|
23
|
-
|
39
|
+
@path << component.to_s
|
24
40
|
end
|
25
41
|
|
26
42
|
def to_s
|
27
|
-
join(".")
|
43
|
+
clean_special_characters join(".")
|
44
|
+
end
|
45
|
+
|
46
|
+
def shift
|
47
|
+
clean_special_characters @path.shift
|
48
|
+
end
|
49
|
+
|
50
|
+
def pop
|
51
|
+
clean_special_characters @path.pop
|
52
|
+
end
|
53
|
+
|
54
|
+
def dup
|
55
|
+
SettingPath.new(@path.dup)
|
56
|
+
end
|
57
|
+
|
58
|
+
def ==(other)
|
59
|
+
to_s == other.to_s
|
28
60
|
end
|
29
61
|
|
30
62
|
def inspect
|
31
|
-
"<SettingPath path=#{to_s}>"
|
63
|
+
"<SettingPath:#{object_id.to_s(16)} path=#{to_s}:#{@path.object_id.to_s(16)} setter=#{is_setter?} question=#{is_question?}>"
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def clean_special_characters(value)
|
69
|
+
value.to_s.chomp("?").chomp("=")
|
32
70
|
end
|
33
71
|
end
|
34
72
|
end
|
@@ -35,7 +35,8 @@ describe Configurate::LookupChain do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it "it tries all providers" do
|
38
|
-
setting = Configurate::SettingPath.
|
38
|
+
setting = Configurate::SettingPath.new "some.setting"
|
39
|
+
setting.stub(:dup).and_return(setting)
|
39
40
|
@provider.each do |provider|
|
40
41
|
provider.should_receive(:lookup).with(setting).and_raise(Configurate::SettingNotFoundError)
|
41
42
|
end
|
@@ -49,7 +50,7 @@ describe Configurate::LookupChain do
|
|
49
50
|
path.stub(:stub).and_return(path)
|
50
51
|
provider.should_receive(:lookup).with(path).and_raise(Configurate::SettingNotFoundError)
|
51
52
|
setting = "bar"
|
52
|
-
Configurate::SettingPath.should_receive(:
|
53
|
+
Configurate::SettingPath.should_receive(:new).with(setting).and_return(path)
|
53
54
|
subject.lookup(setting)
|
54
55
|
end
|
55
56
|
|
@@ -1,20 +1,39 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Configurate::SettingPath do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
let(:normal_path) { described_class.new([:foo]) }
|
5
|
+
let(:question_path) { described_class.new([:foo?]) }
|
6
|
+
let(:setter_path) { described_class.new([:foo=]) }
|
7
|
+
let(:long_path) { described_class.new(["foo", "bar?"]) }
|
8
|
+
|
9
|
+
describe "#initialize" do
|
10
|
+
context "with a string" do
|
11
|
+
it "creates a path" do
|
12
|
+
described_class.new(long_path.to_s).should == long_path
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#is_question?" do
|
18
|
+
context "with a question signature as setting" do
|
19
|
+
subject { question_path.is_question? }
|
20
|
+
it { should be_true }
|
21
|
+
end
|
22
|
+
|
23
|
+
context "with a normal path as setting" do
|
24
|
+
subject { normal_path.is_question? }
|
25
|
+
it { should be_false }
|
7
26
|
end
|
8
27
|
end
|
9
28
|
|
10
29
|
describe "#is_setter?" do
|
11
30
|
context "with a setter signature as setting" do
|
12
|
-
subject {
|
31
|
+
subject { setter_path.is_setter? }
|
13
32
|
it { should be_true }
|
14
33
|
end
|
15
34
|
|
16
35
|
context "with a normal path as setting" do
|
17
|
-
subject {
|
36
|
+
subject { normal_path.is_setter? }
|
18
37
|
it { should be_false }
|
19
38
|
end
|
20
39
|
end
|
@@ -22,21 +41,37 @@ describe Configurate::SettingPath do
|
|
22
41
|
|
23
42
|
describe "#is_question_or_setter?" do
|
24
43
|
context "with a question signature as setting" do
|
25
|
-
subject {
|
44
|
+
subject { question_path.is_question_or_setter? }
|
26
45
|
it { should be_true }
|
27
46
|
end
|
28
47
|
|
29
48
|
context "with a setter signature as setting" do
|
30
|
-
subject {
|
49
|
+
subject { setter_path.is_question_or_setter? }
|
31
50
|
it { should be_true }
|
32
51
|
end
|
33
52
|
|
34
53
|
context "with a normal path as setting" do
|
35
|
-
subject {
|
54
|
+
subject { normal_path.is_question_or_setter? }
|
36
55
|
it { should be_false }
|
37
56
|
end
|
38
57
|
end
|
39
58
|
|
59
|
+
describe "#shift" do
|
60
|
+
subject { question_path.shift }
|
61
|
+
it { should_not include "?" }
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#pop" do
|
65
|
+
subject { question_path.pop }
|
66
|
+
it { should_not include "?" }
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#each" do
|
70
|
+
it "should strip special characters" do
|
71
|
+
long_path.all? { |c| c.include? "?" }.should be_false
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
40
75
|
describe "#<<" do
|
41
76
|
it 'converts the argument to a string' do
|
42
77
|
arg = mock
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configurate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonne Haß
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
metadata.gz.asc
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
-----BEGIN PGP SIGNATURE-----
|
2
2
|
Version: GnuPG v2.0.19 (GNU/Linux)
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
=
|
4
|
+
iQEcBAABAgAGBQJRcoujAAoJEPNH4OtHrHDWkxQIAK7oOLtLgFhGjS5pOq7KoEw7
|
5
|
+
Z8CRfyb73ivBALGQHxjFPWo1Ez4+ha2hqwQSGhzJ8y8bedqhQRgD7BM8kLJUVvTM
|
6
|
+
6MTDOv6oKlcP/4O4uQlf+Brzst4hptoVqTCI5k4wIFOyzu5nBUFe55ScbSzbmRqp
|
7
|
+
eREGatvSqNH3KK8BEexCQxYlzLXuW3XV2WIHGW94i3RntKuB8n9NP7z+KPc/n6T2
|
8
|
+
F+r9wO9raAtvFzc5/ycMQS3X6GN867YU+lh7yweldY/mWDjGlduw6agiCWDyap8o
|
9
|
+
4XVA3iqx2j630bVn4RBF/u/WyHDrs/vxnWcM9pSitRY71NxXhasoEUSm0mK1jCc=
|
10
|
+
=kuZ/
|
11
11
|
-----END PGP SIGNATURE-----
|