Module: DeepDive
- Includes:
- API
- Defined in:
- lib/deep_dive/deep_dive.rb
Defined Under Namespace
Modules: API, CMeth
Classes: DeepDiveException
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from API
#_patch_at, #dclone, #ddup
Class Method Details
.included(base) ⇒ Object
169
170
171
|
# File 'lib/deep_dive/deep_dive.rb', line 169
def self.included(base)
base.extend(CMeth)
end
|
.inherited(sub) ⇒ Object
173
174
175
|
# File 'lib/deep_dive/deep_dive.rb', line 173
def self.inherited(sub)
sub.include(DeepDive)
end
|
.verbose=(t) ⇒ Object
21
22
23
|
# File 'lib/deep_dive/deep_dive.rb', line 21
def self.verbose=(t)
@@verbosity = t
end
|
.verbose? ⇒ Boolean
25
26
27
|
# File 'lib/deep_dive/deep_dive.rb', line 25
def self.verbose?
defined?(@@verbosity) && @@verbosity
end
|
Instance Method Details
#_replicate(dupit: true, oc: {}, patch: {}) ⇒ Object
Not meant to be called externally. Use either ddup or dclone. The patch list will take the value and use that wherver it finds the key instance variable down the object graph.
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/deep_dive/deep_dive.rb', line 60
def _replicate(dupit: true, oc: {}, patch: {})
unless oc.member? self
puts "DeepDive: replicating #{self.class}:<#{self.object_id.to_s(16)}>" if DeepDive::verbose?
copy = oc[self] = if dupit
dup
else
clone
end
copy.instance_variables.map do |var|
[var, instance_variable_get(var)]
end.reject do |var, ob|
not ob.respond_to? :_replicate
end.reject do |var, ob|
self.class.excluded?(var, self)
end.each do |var, value|
unless patch.member? var
puts "DeepDive: rep instance var #{self.class}.#{var}(#{value.class}:<#{value.object_id.to_s(16)}>)" if DeepDive::verbose?
copy.instance_variable_set(var, value._replicate(oc: oc,
dupit: dupit,
patch: patch))
else
puts "DeepDive: PATCH instance var #{self.class}.#{var}(#{patch[var].class}:<#{patch[var].object_id.to_s(16)}>)" if DeepDive::verbose?
copy.instance_variable_set(var, patch[var])
end
end
end
oc[self]
end
|