once-ler 0.0.8 → 0.0.9

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.
@@ -96,11 +96,9 @@ module Onceler
96
96
  group.onceler.reset!
97
97
  end
98
98
 
99
- # only the outer-most group needs to do this
100
- unless parent_onceler
101
- before :each do
102
- onceler.replay_into!(self)
103
- end
99
+ group_class = self
100
+ prepend_before(:each) do
101
+ group_class.onceler.replay_into!(self)
104
102
  end
105
103
  end
106
104
 
@@ -24,24 +24,36 @@ module Onceler
24
24
  instance_eval(&recording.block)
25
25
  end
26
26
 
27
+ def __retvals
28
+ @__retvals.slice(*@__retvals_recorded.keys)
29
+ end
30
+
27
31
  def __ivars
28
32
  ivars = instance_variables - @__ignore_ivars
29
33
  ivars.inject({}) do |hash, key|
30
34
  if key.to_s !~ /\A@__/
31
35
  val = instance_variable_get(key)
32
- hash[key] = val
36
+ hash[key] = val unless __inherited_ivar?(key, val)
33
37
  end
34
38
  hash
35
39
  end
36
40
  end
37
41
 
42
+ def __inherited_ivar?(key, val)
43
+ return false unless @__inherited_ivar_cache
44
+ # need to do both types of comparison, i.e. it's the same object in
45
+ # memory, and nothing about it has been changed
46
+ @__inherited_ivar_cache[key] == val && @__inherited_ivars.equal?(val)
47
+ end
48
+
38
49
  def __data
39
- @__data ||= Marshal.dump([__ivars, @__retvals])
50
+ @__data ||= Marshal.dump([__ivars, __retvals])
40
51
  end
41
52
 
42
53
  def copy_from(other)
43
- ivars, @__retvals = Marshal.load(other.__data)
44
- ivars.each do |key, value|
54
+ @__inherited_ivar_cache = Marshal.load(other.__data).first
55
+ @__inherited_ivars, @__retvals = Marshal.load(other.__data)
56
+ @__inherited_ivars.each do |key, value|
45
57
  instance_variable_set(key, value)
46
58
  end
47
59
  @__retvals.each do |key, value|
@@ -39,7 +39,11 @@ module Onceler
39
39
  end
40
40
 
41
41
  def [](name)
42
- @retvals[name]
42
+ if @retvals && @retvals.key?(name)
43
+ @retvals[name]
44
+ elsif parent
45
+ parent[name]
46
+ end
43
47
  end
44
48
 
45
49
  def record!
@@ -85,11 +89,16 @@ module Onceler
85
89
  end
86
90
  end
87
91
 
92
+ def parent
93
+ @group_class.parent_onceler
94
+ end
95
+
88
96
  def replay_into!(instance)
89
97
  reconsitute_data!
90
98
  @ivars.each do |key, value|
91
99
  instance.instance_variable_set(key, value)
92
100
  end
101
+ @retvals
93
102
  end
94
103
 
95
104
  # TODO: configurable transaction fu (say, if you have multiple
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: once-ler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: