19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/aipp/patcher.rb', line 19
def attach_patches
verbose_info_method = method(:verbose_info)
self.class.patches[self.class]&.each do |(klass, attribute, block)|
klass.instance_eval do
alias_method :"original_#{attribute}=", :"#{attribute}="
define_method(:"#{attribute}=") do |value|
error = catch :abort do
value = block.call(self, value)
verbose_info_method.call("Patching #{self.inspect} with #{attribute}=#{value.inspect}", color: :magenta)
end
fail "patching #{self.inspect} with #{attribute}=#{value.inspect} failed: #{error}" if error
send(:"original_#{attribute}=", value)
end
end
end
self
end
|