runcoderun-configatron 2.2.2.1 → 2.2.2.2

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.
data/lib/configatron.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  base = File.join(File.dirname(__FILE__), 'configatron')
2
2
  require 'yaml'
3
3
  require 'erb'
4
- require File.join(base, 'blank_slate')
4
+ require File.join(base, 'configatron_blank_slate')
5
5
  require File.join(base, 'configatron')
6
6
  require File.join(base, 'store')
7
7
  require File.join(base, 'errors')
@@ -1,10 +1,8 @@
1
1
  require 'singleton'
2
2
 
3
- class Configatron
3
+ class Configatron < ConfigatronBlankSlate
4
4
  include Singleton
5
5
 
6
- alias_method :send!, :send
7
-
8
6
  def initialize # :nodoc:
9
7
  @_namespace = [:default]
10
8
  reset!
@@ -48,7 +46,7 @@ class Configatron
48
46
  @_store.delete(@_namespace.pop)
49
47
  end
50
48
 
51
- undef :inspect # :nodoc:
52
- undef :nil? # :nodoc:
49
+ # undef :inspect # :nodoc:
50
+ # undef :nil? # :nodoc:
53
51
 
54
52
  end
@@ -0,0 +1,59 @@
1
+ #--
2
+ # Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
3
+ # All rights reserved.
4
+
5
+ # Permission is granted for use, copying, modification, distribution,
6
+ # and distribution of modified versions of this work as long as the
7
+ # above copyright notice is included.
8
+ #++
9
+
10
+ # This version of BlankSlate was taken from Builder and modified by Rob Sanheim
11
+ # to remove hooks into the various built-in callbacks (ie method_added).
12
+ # Not sure if we need that complexity (yet) in configatron's use case.
13
+ #
14
+ ######################################################################
15
+ # BlankSlate provides an abstract base class with no predefined
16
+ # methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
17
+ # BlankSlate is useful as a base class when writing classes that
18
+ # depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
19
+ #
20
+ class ConfigatronBlankSlate
21
+ # These methods are used by configatron internals, so we have to whitelist them.
22
+ # We could probably do some alias magic to get them to be proper __foo style methods
23
+ #, but this is okay for now.
24
+ CONFIGATRON_WHITELIST = %w[instance_eval methods instance_variable_get is_a? class]
25
+
26
+ class << self
27
+
28
+ # Hide the method named +name+ in the BlankSlate class. Don't
29
+ # hide methods in +CONFIGATRON_WHITELIST+ or any method beginning with "__".
30
+ def hide(name)
31
+ if instance_methods.include?(name.to_s) and
32
+ name !~ /^(__|#{CONFIGATRON_WHITELIST.join("|")})/
33
+ @hidden_methods ||= {}
34
+ @hidden_methods[name.to_sym] = instance_method(name)
35
+ undef_method name
36
+ end
37
+ end
38
+
39
+ def find_hidden_method(name)
40
+ @hidden_methods ||= {}
41
+ @hidden_methods[name] || superclass.find_hidden_method(name)
42
+ end
43
+
44
+ # Redefine a previously hidden method so that it may be called on a blank
45
+ # slate object.
46
+ def reveal(name)
47
+ bound_method = nil
48
+ unbound_method = find_hidden_method(name)
49
+ fail "Don't know how to reveal method '#{name}'" unless unbound_method
50
+ define_method(name) do |*args|
51
+ bound_method ||= unbound_method.bind(self)
52
+ bound_method.call(*args)
53
+ end
54
+ end
55
+ end
56
+
57
+ instance_methods.each { |m| hide(m) }
58
+
59
+ end
@@ -1,5 +1,5 @@
1
1
  class Configatron
2
- class Store < BlankSlate
2
+ class Store < ::ConfigatronBlankSlate
3
3
  # alias_method :__send!, :__send__
4
4
 
5
5
  # Takes an optional Hash of parameters
@@ -1,6 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
2
 
3
- describe Configatron::BlankSlate do
3
+ describe ConfigatronBlankSlate do
4
4
 
5
5
  before(:each) do
6
6
  configatron.reset!
@@ -8,14 +8,14 @@ describe Configatron::BlankSlate do
8
8
 
9
9
  it "should respond to __id__ and __send__ built in methods" do
10
10
  lambda {
11
- Configatron::BlankSlate.new.__id__
12
- Configatron::BlankSlate.new.__send__
11
+ ConfigatronBlankSlate.new.__id__
12
+ ConfigatronBlankSlate.new.__send__
13
13
  }.should_not raise_error(NoMethodError)
14
14
  end
15
15
 
16
16
  it "should have methods on the CONFIGATRON_WHITELIST" do
17
- blank_slate = Configatron::BlankSlate.new
18
- Configatron::BlankSlate::CONFIGATRON_WHITELIST.each do |meth|
17
+ blank_slate = ConfigatronBlankSlate.new
18
+ ConfigatronBlankSlate::CONFIGATRON_WHITELIST.each do |meth|
19
19
  lambda {
20
20
  blank_slate__send__
21
21
  }.should_not raise_error(NoMethodError)
@@ -25,10 +25,10 @@ describe "configatron" do
25
25
  configatron.one.should == 1
26
26
  end
27
27
 
28
- it 'should protect basic methods' do
29
- pending("Not sure if this really applies any more...there is no reason to _not_ let users set a key called 'object_id' now")
30
- lambda{configatron.object_id = 123456}.should raise_error(Configatron::ProtectedParameter)
31
- lambda{configatron.foo.object_id = 123456}.should raise_error(Configatron::ProtectedParameter)
28
+ it 'should allow setting properties with same name as Object/Kernel builtins' do
29
+ configatron.object_id.should be_nil
30
+ configatron.object_id = "my-object-id"
31
+ configatron.object_id.should == "my-object-id"
32
32
  end
33
33
 
34
34
  it 'should work with nested parameters' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: runcoderun-configatron
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2.1
4
+ version: 2.2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-20 00:00:00 -08:00
12
+ date: 2009-02-11 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,8 +22,8 @@ extensions: []
22
22
  extra_rdoc_files:
23
23
  - README
24
24
  files:
25
- - lib/configatron/blank_slate.rb
26
25
  - lib/configatron/configatron.rb
26
+ - lib/configatron/configatron_blank_slate.rb
27
27
  - lib/configatron/core_ext/class.rb
28
28
  - lib/configatron/core_ext/kernel.rb
29
29
  - lib/configatron/core_ext/object.rb
@@ -1,61 +0,0 @@
1
- #--
2
- # Copyright 2004, 2006 by Jim Weirich (jim@weirichhouse.org).
3
- # All rights reserved.
4
-
5
- # Permission is granted for use, copying, modification, distribution,
6
- # and distribution of modified versions of this work as long as the
7
- # above copyright notice is included.
8
- #++
9
-
10
- # This version of BlankSlate was taken from Builder and modified by Rob Sanheim
11
- # to remove hooks into the various built-in callbacks (ie method_added).
12
- # Not sure if we need that complexity (yet) in configatron's use case.
13
- #
14
- ######################################################################
15
- # BlankSlate provides an abstract base class with no predefined
16
- # methods (except for <tt>\_\_send__</tt> and <tt>\_\_id__</tt>).
17
- # BlankSlate is useful as a base class when writing classes that
18
- # depend upon <tt>method_missing</tt> (e.g. dynamic proxies).
19
- #
20
- class Configatron
21
- class BlankSlate
22
- # These methods are used by configatron internals, so we have to whitelist them.
23
- # We could probably do some alias magic to get them to be proper __foo style methods
24
- #, but this is okay for now.
25
- CONFIGATRON_WHITELIST = %w[instance_eval methods instance_variable_get is_a? class]
26
-
27
- class << self
28
-
29
- # Hide the method named +name+ in the BlankSlate class. Don't
30
- # hide methods in +CONFIGATRON_WHITELIST+ or any method beginning with "__".
31
- def hide(name)
32
- if instance_methods.include?(name.to_s) and
33
- name !~ /^(__|#{CONFIGATRON_WHITELIST.join("|")})/
34
- @hidden_methods ||= {}
35
- @hidden_methods[name.to_sym] = instance_method(name)
36
- undef_method name
37
- end
38
- end
39
-
40
- def find_hidden_method(name)
41
- @hidden_methods ||= {}
42
- @hidden_methods[name] || superclass.find_hidden_method(name)
43
- end
44
-
45
- # Redefine a previously hidden method so that it may be called on a blank
46
- # slate object.
47
- def reveal(name)
48
- bound_method = nil
49
- unbound_method = find_hidden_method(name)
50
- fail "Don't know how to reveal method '#{name}'" unless unbound_method
51
- define_method(name) do |*args|
52
- bound_method ||= unbound_method.bind(self)
53
- bound_method.call(*args)
54
- end
55
- end
56
- end
57
-
58
- instance_methods.each { |m| hide(m) }
59
-
60
- end
61
- end