configurate 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba2e5111a8d1a9882b5230e9ec15e673f2cb9e37
4
- data.tar.gz: 28355f0874ff30a9607947a41da514fb1afdcb03
3
+ metadata.gz: 5c9982f04f1f636cbc5b6b9c5e45fdf1bdd94cdb
4
+ data.tar.gz: 62d95c25d55ab621123bb07d9a55fbac43c71e4e
5
5
  SHA512:
6
- metadata.gz: 5a0bbf13823232c663225f52978c9a73d132d36e7ff16338b9d3181ec6d0c8faba3001839e0f50f7b1fb700c4516bc64606da7d4e209906524889fc0a672ab09
7
- data.tar.gz: 25f1d06312902b428bf488894b76930df32b392b25964e10271e26bf09df2841a83471c6a9fde0cbb7aae99019195d6e4438c166c9a21356b97c459db4f474b3
6
+ metadata.gz: d697a43c3f69158c8d1fcfe0b232601830826d5a5c720e6628046dfbe21b110d9f42f04dbf1c1cd02ec3b59f7bf1f000c9241883e3393039e889e518bc5aaee1
7
+ data.tar.gz: d1ef8990fbb620024dca6093bb075211c8c7fe123e1105447f436eba924a8700aa3f006a7d81cfe4e2d654d976fccd5551f9f325d46b683fcb511772bdb9b21c
@@ -1,11 +1,11 @@
1
1
  -----BEGIN PGP SIGNATURE-----
2
2
  Version: GnuPG v2.0.19 (GNU/Linux)
3
3
 
4
- iQEcBAABAgAGBQJRa/mCAAoJEPNH4OtHrHDWMN4IAKejANfU2ta7YG9RixX5PHmu
5
- /AjTlpUCg/7InjX/xFmxUQo5MCuHxy9RImb12dA5k60MmLrIdNnFmUnBemyiwgo6
6
- 9ArIc1qYX0C5GWFVOMWgRmfviPpW1cTGLSdd98sTlHMQcfT1IThS/ObXZZFZY1WS
7
- BVxXEOpGDUf251HzCOWcaLz8VFumzht+gdWg6A2RtAToQnrDRXLwm/aRTr4dFYYm
8
- sWi94JtRLOggNG8IqCkvv9AXn27ptkR+LOgnyXG9viUQx8XqPAdsss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GBQJRcoukAAoJEPNH4OtHrHDWPUsH/ih9CZWu1ei8sAz8NqqrmwPU
5
+ BpgECWYpzisCe0LBu5tgLJCRe4WLEg7V3LT/fAVFJoPB8m4vtnNAmtZWOAAkEyZk
6
+ xgSeyF7Rjs9zKA29Ez1EDk9CBn5Iy+jDcKiBvKtsH4VWnPOiBgYTPM11/VQPES5J
7
+ VWSjIBwrDrLgx2LAJjPhsO9pSnHdf36ZMF4X6sGPDr6bqmqU4HfbXOdtaOjqzlWK
8
+ LCHJ2nZFlgDjmMgXVFvFMmVY4jHzcsjVmco1Zd1ziZTkigdZEkaBCB+zGXw2UMDl
9
+ 5a1ydYuzQAwvTD4SFh+6Gk048yyu+pFYKTfy2gawD1n8XQ3LBEJfhSoIOfD8f7s=
10
+ =ISOk
11
11
  -----END PGP SIGNATURE-----
@@ -1,3 +1,4 @@
1
+ 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.from_string(setting) if setting.is_a? String
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
- namespace = SettingPath.from_string(namespace)
23
- actual_settings = lookup_in_hash(namespace, @settings)
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 < Array
5
+ class SettingPath
6
+ include Enumerable
7
+ extend Forwardable
4
8
 
5
- # Create a path from the string format (+foo.bar+).
6
- # @param path [String]
7
- # @return [SettingPath]
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
- last.to_s.end_with?("?") || is_setter?
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
- super component.to_s
39
+ @path << component.to_s
24
40
  end
25
41
 
26
42
  def to_s
27
- join(".").chomp("?").chomp("=")
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.from_string "some.setting"
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(:from_string).with(setting).and_return(path)
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
- describe "::from_string" do
5
- it "creates a path" do
6
- described_class.from_string("foo.bar").should == described_class.new(["foo", "bar"])
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 { described_class.new([:foo=]).is_setter? }
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 { described_class.new([:foo]).is_setter? }
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 { described_class.new([:foo?]).is_question_or_setter? }
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 { described_class.new([:foo=]).is_question_or_setter? }
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 { described_class.new([:foo]).is_question_or_setter? }
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.5
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-15 00:00:00.000000000 Z
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
- iQEcBAABAgAGBQJRa/mCAAoJEPNH4OtHrHDWko0H/3ehr8t5DF3gsssk+8hd4p2T
5
- wVPdWmzDovXT2zqM56MTCPtpKPQsG7/DaRvhxWIu/XfAmGpGuUTuNjLOURvslNun
6
- aii2q7ZIJPiRkQPh38DQ+56k1xU3b8jtkgumHqQBFCnJr9wmXAF6XXM9NebeAktc
7
- mfYNsJPye8oVUe8XsmVaDVNgVAY95FvG82E85ATIhL0muWTMLKhEzzuCVq59ZNVO
8
- LOq7Ryh9Zb/xKo+ybb1vQujxQ4Db+offzKrpMmcQguVW9XKfitV8xd6wwaw6d/dr
9
- jahH4UjIrsImu2eootgTT89gxjCkD1tXyH+UIm7PgoW551VsPk6N5YWhTXpg4s8=
10
- =Tp+n
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-----