configatron 2.12.0 → 2.13.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -223,8 +223,8 @@ Enjoy!
223
223
  * Mark Bates
224
224
  * Kurtis Rainbolt-Greene
225
225
  * Rob Sanheim
226
- * Cody Maggard
227
226
  * Greg Brockman
227
+ * Cody Maggard
228
228
  * Jean-Denis Vauguet
229
229
  * Torsten Schönebaum
230
230
  * Mat Brown
data/lib/configatron.rb CHANGED
@@ -1,12 +1,17 @@
1
+ # You can require 'configure/core' directly to avoid loading
2
+ # configatron's monkey patches (and you can then set
3
+ # `Configatron.disable_monkey_patchs = true` to enforce this). If you
4
+ # do so, no `configatron` top-level method will be defined for
5
+ # you. You can access the configatron object by Configatron.instance.
6
+
1
7
  base = File.join(File.dirname(__FILE__), 'configatron')
2
- require 'yamler'
3
- require 'fileutils'
4
- require File.join(base, 'configatron')
5
- require File.join(base, 'store')
6
- require File.join(base, 'errors')
8
+ require File.join(base, 'core')
9
+
10
+ if Configatron.disable_monkey_patching
11
+ raise "Cannot require 'configatron' directly, since monkey patching has been disabled. Run `Configatron.disable_monkey_patching = false` to re-enable it, or always require 'configatron/core' to load Configatron."
12
+ end
13
+
7
14
  require File.join(base, 'core_ext', 'kernel')
8
15
  require File.join(base, 'core_ext', 'object')
9
16
  require File.join(base, 'core_ext', 'string')
10
17
  require File.join(base, 'core_ext', 'class')
11
- require File.join(base, 'rails')
12
- require File.join(base, 'proc')
@@ -1,14 +1,23 @@
1
+ require 'fileutils'
1
2
  require 'singleton'
2
3
  require 'logger'
4
+ require 'yamler'
5
+
6
+ base = File.dirname(__FILE__)
7
+
8
+ require File.join(base, 'store')
9
+ require File.join(base, 'errors')
10
+ require File.join(base, 'rails')
11
+ require File.join(base, 'proc')
3
12
 
4
13
  class Configatron
5
14
  include Singleton
6
15
 
7
16
  alias_method :send!, :send
8
-
17
+
9
18
  class << self
10
19
 
11
- attr_accessor :strict
20
+ attr_accessor :strict, :disable_monkey_patching
12
21
 
13
22
  def log
14
23
  unless @logger
@@ -29,7 +38,7 @@ class Configatron
29
38
  @_namespace = [:default]
30
39
  reset!
31
40
  end
32
-
41
+
33
42
  # Forwards the method call onto the 'namespaced' Configatron::Store
34
43
  def method_missing(sym, *args, &block)
35
44
  @_store[@_namespace.last].send(sym, *args, &block)
@@ -1,5 +1,5 @@
1
1
  class Object # :nodoc:
2
-
2
+
3
3
  def send_with_chain(methods, *args) # :nodoc:
4
4
  obj = self
5
5
  [methods].flatten.each {|m| obj = obj.send(m, *args)}
@@ -148,7 +148,8 @@ class Configatron
148
148
  raise Configatron::LockedNamespace.new(@_name) if @_locked && !@_store.has_key?(name)
149
149
  @_store[name] = parse_options(*args)
150
150
  elsif sym.to_s.match(/(.+)\?/)
151
- return !_store_lookup($1.to_sym).blank?
151
+ object = _store_lookup($1.to_sym)
152
+ return !_object_blank?(object)
152
153
  elsif block_given?
153
154
  yield self.send(sym)
154
155
  elsif @_store.has_key?(sym)
@@ -353,6 +354,10 @@ class Configatron
353
354
  end
354
355
  end
355
356
 
357
+ def _object_blank?(object) # ported ActiveSupport method
358
+ object.respond_to?(:empty?) ? object.empty? : !object
359
+ end
360
+
356
361
  begin
357
362
  undef :test # :nodoc:
358
363
  rescue Exception => e
@@ -1,3 +1,3 @@
1
1
  class Configatron
2
- VERSION = "2.12.0"
2
+ VERSION = "2.13.0"
3
3
  end
@@ -22,24 +22,25 @@ module N
22
22
  end
23
23
 
24
24
  describe Class do
25
-
26
- describe 'to_configatron' do
27
-
28
- it 'should return a Configatron::Store object based on the name of the class' do
29
- Foo.to_configatron.should be_kind_of(Configatron::Store)
30
- Foo.to_configatron.bar.should == :bar
31
- A::B::C.to_configatron.d.should == 'D'
32
- end
33
-
34
- it 'should take an array to prepend to the object' do
35
- Foo.to_configatron(:cachetastic).bar.should == 'cachetastic-fubar'
36
- N::O.to_configatron(:l, 'm').p.should == 'P'
37
- end
38
-
39
- it 'should convert a string to a Store object' do
40
- 'A::B::C'.to_configatron.d.should == configatron.a.b.c.d
25
+
26
+ if Class.respond_to?(:to_configatron)
27
+ describe 'to_configatron' do
28
+
29
+ it 'should return a Configatron::Store object based on the name of the class' do
30
+ Foo.to_configatron.should be_kind_of(Configatron::Store)
31
+ Foo.to_configatron.bar.should == :bar
32
+ A::B::C.to_configatron.d.should == 'D'
33
+ end
34
+
35
+ it 'should take an array to prepend to the object' do
36
+ Foo.to_configatron(:cachetastic).bar.should == 'cachetastic-fubar'
37
+ N::O.to_configatron(:l, 'm').p.should == 'P'
38
+ end
39
+
40
+ it 'should convert a string to a Store object' do
41
+ 'A::B::C'.to_configatron.d.should == configatron.a.b.c.d
42
+ end
41
43
  end
42
-
43
44
  end
44
-
45
- end
45
+
46
+ end
@@ -30,9 +30,9 @@ describe "configatron" do
30
30
  configatron.foo.test = 'hi!'
31
31
  configatron.foo.test.should == 'hi!'
32
32
  end
33
-
33
+
34
34
  describe "respond_to" do
35
-
35
+
36
36
  it 'should respond_to respond_to?' do
37
37
  configatron.test.should be_nil
38
38
  configatron.test = 'hi!'
@@ -46,11 +46,11 @@ describe "configatron" do
46
46
  configatron.foo.respond_to?(:test).should be_true
47
47
  configatron.foo.respond_to?(:plop).should be_false
48
48
  end
49
-
49
+
50
50
  end
51
-
51
+
52
52
  describe 'block assignment' do
53
-
53
+
54
54
  it 'should pass the store to the block' do
55
55
  configatron.test do |c|
56
56
  c.should === configatron.test
@@ -179,7 +179,7 @@ describe "configatron" do
179
179
  end
180
180
 
181
181
  describe 'lock' do
182
-
182
+
183
183
  before :each do
184
184
  configatron.letters.a = 'A'
185
185
  configatron.letters.b = 'B'
@@ -212,7 +212,7 @@ describe "configatron" do
212
212
  end
213
213
 
214
214
  describe 'then unlock' do
215
-
215
+
216
216
  before :each do
217
217
  configatron.unlock(:letters)
218
218
  end
@@ -228,9 +228,9 @@ describe "configatron" do
228
228
  it 'should raise an ArgumentError if unknown namespace is unlocked' do
229
229
  lambda { configatron.unlock(:numbers).should raise_error(ArgumentError) }
230
230
  end
231
-
231
+
232
232
  end
233
-
233
+
234
234
  end
235
235
 
236
236
  describe 'temp' do
@@ -374,14 +374,14 @@ describe "configatron" do
374
374
  configatron.food.list.should == [:apple, :banana, :tomato, :brocolli, :spinach]
375
375
  end
376
376
  end
377
-
377
+
378
378
  it "should handle complex yaml" do
379
379
  configatron.complex_development.bucket.should be_nil
380
380
  configatron.configure_from_yaml(File.join(File.dirname(__FILE__), 'complex.yml'))
381
381
  configatron.complex_development.bucket.should == 'develop'
382
382
  configatron.complex_development.access_key_id.should == 'access_key'
383
383
  end
384
-
384
+
385
385
  end
386
386
 
387
387
  it 'should return a parameter' do
@@ -566,47 +566,48 @@ configatron.one = 1
566
566
 
567
567
  end
568
568
 
569
- describe :blank? do
569
+ if Object.new.respond_to?(:blank?)
570
+ describe :blank? do
570
571
 
571
- context "uninitialized option" do
572
- specify { configatron.foo.bar.should be_blank }
573
- end
572
+ context "uninitialized option" do
573
+ specify { configatron.foo.bar.should be_blank }
574
+ end
574
575
 
575
- context "nil option" do
576
- before { configatron.foo.bar = nil }
577
- specify { configatron.foo.bar.should be_blank }
578
- end
576
+ context "nil option" do
577
+ before { configatron.foo.bar = nil }
578
+ specify { configatron.foo.bar.should be_blank }
579
+ end
579
580
 
580
- context "false option" do
581
- before { configatron.foo.bar = false }
582
- specify { configatron.foo.bar.should be_blank }
583
- end
581
+ context "false option" do
582
+ before { configatron.foo.bar = false }
583
+ specify { configatron.foo.bar.should be_blank }
584
+ end
584
585
 
585
- context "empty string option" do
586
- before { configatron.foo.bar = "" }
587
- specify { configatron.foo.bar.should be_blank }
588
- end
586
+ context "empty string option" do
587
+ before { configatron.foo.bar = "" }
588
+ specify { configatron.foo.bar.should be_blank }
589
+ end
589
590
 
590
- context "empty hash option" do
591
- before { configatron.foo.bar = {} }
592
- specify { configatron.foo.bar.should be_blank }
593
- end
591
+ context "empty hash option" do
592
+ before { configatron.foo.bar = {} }
593
+ specify { configatron.foo.bar.should be_blank }
594
+ end
594
595
 
595
- context "empty array option" do
596
- before { configatron.foo.bar = [] }
597
- specify { configatron.foo.bar.should be_blank }
598
- end
596
+ context "empty array option" do
597
+ before { configatron.foo.bar = [] }
598
+ specify { configatron.foo.bar.should be_blank }
599
+ end
600
+
601
+ context "defined option" do
602
+ before { configatron.foo.bar = 'asd' }
603
+ subject { configatron.foo.bar }
604
+ it { should_not be_blank }
605
+ it { should == 'asd' }
606
+ end
599
607
 
600
- context "defined option" do
601
- before { configatron.foo.bar = 'asd' }
602
- subject { configatron.foo.bar }
603
- it { should_not be_blank }
604
- it { should == 'asd' }
605
608
  end
606
-
607
609
  end
608
610
 
609
-
610
611
  describe "boolean test" do
611
612
 
612
613
  context "nil option" do
@@ -625,5 +626,5 @@ configatron.one = 1
625
626
  end
626
627
 
627
628
  end
628
-
629
+
629
630
  end
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configatron
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.0
4
+ version: 2.13.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Mark Bates
@@ -13,15 +14,17 @@ dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: yamler
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: 0.1.0
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: 0.1.0
27
30
  description: A powerful Ruby configuration system.
@@ -41,7 +44,7 @@ files:
41
44
  - Rakefile
42
45
  - configatron.gemspec
43
46
  - lib/configatron.rb
44
- - lib/configatron/configatron.rb
47
+ - lib/configatron/core.rb
45
48
  - lib/configatron/core_ext/class.rb
46
49
  - lib/configatron/core_ext/kernel.rb
47
50
  - lib/configatron/core_ext/object.rb
@@ -70,26 +73,33 @@ files:
70
73
  - spec/support/rails.rb
71
74
  homepage: http://www.metabates.com
72
75
  licenses: []
73
- metadata: {}
74
76
  post_install_message:
75
77
  rdoc_options: []
76
78
  require_paths:
77
79
  - lib
78
80
  required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
79
82
  requirements:
80
- - - '>='
83
+ - - ! '>='
81
84
  - !ruby/object:Gem::Version
82
85
  version: '0'
86
+ segments:
87
+ - 0
88
+ hash: -1505577042870860442
83
89
  required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
84
91
  requirements:
85
- - - '>='
92
+ - - ! '>='
86
93
  - !ruby/object:Gem::Version
87
94
  version: '0'
95
+ segments:
96
+ - 0
97
+ hash: -1505577042870860442
88
98
  requirements: []
89
99
  rubyforge_project:
90
- rubygems_version: 2.0.3
100
+ rubygems_version: 1.8.25
91
101
  signing_key:
92
- specification_version: 4
102
+ specification_version: 3
93
103
  summary: A powerful Ruby configuration system.
94
104
  test_files:
95
105
  - spec/configatron/proc_spec.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 7ad275e874cd8d84144f386f237517860fdfe0d9
4
- data.tar.gz: 05020e5145f79ee869a6738a75b4ac3d14db2cf7
5
- SHA512:
6
- metadata.gz: 15c5147856dd716772faf24d8ddfec36132fe55813988475528dcf2faf3e2221525dc87fb1be027f15a82bb9dd922f8c0cc01921efd22f25c8b868da86d851d1
7
- data.tar.gz: ba5f57da5bcc09e13ba7bae188e94ecdcea75de67ca248cee9fd208709b02390d1b2e2cab8a9df59dab37cd0c85fd657dec77dc18da5a700cd1e357830999994