config_leaf 0.0.1 → 0.0.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/README.md CHANGED
@@ -41,7 +41,7 @@ their object has been instantiated:
41
41
  @list = []
42
42
 
43
43
  # Allow the user access via ConfigLeaf syntax.
44
- ConfigLeaf.wrap object, &block if block_given?
44
+ ConfigLeaf.wrap self, &block if block_given?
45
45
  end
46
46
 
47
47
  def reverse!
@@ -54,21 +54,21 @@ their object has been instantiated:
54
54
  end
55
55
  end
56
56
 
57
- # User uses the ConfigLeaf block.
58
- object = Cheese.new do
57
+ # User uses the ConfigLeaf block syntax.
58
+ object1 = Cheese.new do
59
59
  list [1, 2, 3] # Calls object.list = [1, 2, 3]
60
60
  list << 4 # Calls object.list << 4
61
61
  value 5 # Calls object.value = 5
62
62
  value list.size # Calls object.value = object.list.size
63
63
  reverse! # Calls object.reverse!
64
-
65
- # These would be possible if using instance_eval, but not here.
66
- #explode! # Not allowed because it is protected (raises an exception).
67
- #@value = 5 # Would set @value on the wrapper, not in the wrapped object, so has no effect.
64
+
65
+ ## @value = 99 # Would set @value on the wrapper, not in the wrapped object, so raises an exception.
66
+
67
+ ## explode! # Not allowed because it is protected (raises an exception).
68
68
  end
69
69
 
70
70
  # User chooses to not use ConfigLeaf block syntax by requesting a block parameter.
71
- object = Cheese.new do |c|
71
+ object2 = Cheese.new do |c|
72
72
  c.list = [1, 2, 3]
73
73
  c.list << 4
74
74
  c.value = 5
@@ -76,6 +76,9 @@ their object has been instantiated:
76
76
  c.reverse!
77
77
  end
78
78
 
79
+ p object1 #=> #<Cheese:0x4340658 @value=4, @list=[4, 3, 2, 1]>
80
+ p object2 #=> #<Cheese:0x45d2b58 @value=4, @list=[4, 3, 2, 1]>
81
+
79
82
  Contributing
80
83
  ------------
81
84
 
data/lib/config_leaf.rb CHANGED
@@ -43,7 +43,7 @@ module ConfigLeaf
43
43
  # @value = 0
44
44
  # @list = []
45
45
  #
46
- # ConfigLeaf.wrap object, &block if block_given?
46
+ # ConfigLeaf.wrap self, &block if block_given?
47
47
  # end
48
48
  #
49
49
  # def invert
@@ -52,7 +52,7 @@ module ConfigLeaf
52
52
  # end
53
53
  #
54
54
  # # User chooses to use the ConfigLeaf block syntax.
55
- # object = Cheese.new do
55
+ # object1 = Cheese.new do
56
56
  # list [1, 2, 3] # Calls object.list = [1, 2, 3]
57
57
  # list << 4 # Calls object.list << 4
58
58
  # value 5 # Calls object.value = 5
@@ -61,7 +61,7 @@ module ConfigLeaf
61
61
  # end
62
62
  #
63
63
  # # User chooses to not use ConfigLeaf block syntax by requesting a block parameter.
64
- # object = Cheese.new do |c|
64
+ # object2 = Cheese.new do |c|
65
65
  # c.list = [1, 2, 3]
66
66
  # c.list << 4
67
67
  # c.value = 5
@@ -1,3 +1,3 @@
1
1
  module ConfigLeaf
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -9,7 +9,7 @@ module ConfigLeaf
9
9
  alias_method :wrap, :new
10
10
  end
11
11
 
12
- # If passed a block, the DSLWrapper will #instance_eval it automatically.
12
+ # If passed a block, the Wrapper will #instance_eval it automatically.
13
13
  #
14
14
  # @param owner [Object] Object to redirect the public methods of.
15
15
  def initialize(owner, &block)
@@ -37,6 +37,11 @@ module ConfigLeaf
37
37
  end
38
38
 
39
39
  instance_eval &block if block_given?
40
+
41
+ if instance_variables != [:@_owner]
42
+ altered = instance_variables - [:@_owner]
43
+ raise "Instance variable#{altered.one? ? '' : 's'} #{altered.join ", "} set in ConfigLeaf scope"
44
+ end
40
45
  end
41
46
 
42
47
  private
@@ -88,6 +88,16 @@ describe ConfigLeaf::Wrapper do
88
88
  end
89
89
  end
90
90
 
91
+ context "in block" do
92
+ it "should fail if an ivar were changed during the block, since they would be discarded!" do
93
+ lambda { described_class.wrap owner do @frog = 12 end }.should raise_error RuntimeError, "Instance variable @frog set in ConfigLeaf scope"
94
+ end
95
+
96
+ it "should fail if any ivars were changed during the block, since they would be discarded!" do
97
+ lambda { described_class.wrap owner do @frog = 12; @fish = 1 end }.should raise_error RuntimeError, "Instance variables @frog, @fish set in ConfigLeaf scope"
98
+ end
99
+ end
100
+
91
101
  describe "" do
92
102
  it "should instance_eval when given a block on the constructor (.new)" do
93
103
  mock(owner).frog(5)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_leaf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-19 00:00:00.000000000 Z
12
+ date: 2012-10-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -130,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
130
  version: '0'
131
131
  segments:
132
132
  - 0
133
- hash: 196843955
133
+ hash: 847368189
134
134
  required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  none: false
136
136
  requirements:
@@ -139,10 +139,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  version: '0'
140
140
  segments:
141
141
  - 0
142
- hash: 196843955
142
+ hash: 847368189
143
143
  requirements: []
144
144
  rubyforge_project:
145
- rubygems_version: 1.8.23
145
+ rubygems_version: 1.8.24
146
146
  signing_key:
147
147
  specification_version: 3
148
148
  summary: Terse configuration syntax for objects