once-ler 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/onceler/basic_helpers.rb +3 -5
- data/lib/onceler/recordable.rb +16 -4
- data/lib/onceler/recorder.rb +10 -1
- metadata +1 -1
@@ -96,11 +96,9 @@ module Onceler
|
|
96
96
|
group.onceler.reset!
|
97
97
|
end
|
98
98
|
|
99
|
-
|
100
|
-
|
101
|
-
|
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
|
|
data/lib/onceler/recordable.rb
CHANGED
@@ -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,
|
50
|
+
@__data ||= Marshal.dump([__ivars, __retvals])
|
40
51
|
end
|
41
52
|
|
42
53
|
def copy_from(other)
|
43
|
-
|
44
|
-
|
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|
|
data/lib/onceler/recorder.rb
CHANGED
@@ -39,7 +39,11 @@ module Onceler
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def [](name)
|
42
|
-
@retvals
|
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
|