module AIPP::Patcher
Public Class Methods
included(klass)
click to toggle source
# File lib/aipp/patcher.rb 4 def self.included(klass) 5 klass.extend(ClassMethods) 6 klass.class_variable_set(:@@patches, {}) 7 end
Public Instance Methods
attach_patches()
click to toggle source
# File lib/aipp/patcher.rb 19 def attach_patches 20 parser = self 21 self.class.patches[self.class]&.each do |(klass, attribute, block)| 22 klass.instance_eval do 23 alias_method :"original_#{attribute}=", :"#{attribute}=" 24 define_method(:"#{attribute}=") do |value| 25 catch :abort do 26 value = block.call(parser, self, value) 27 verbose_info("PATCH: #{self.inspect}", color: :magenta) 28 end 29 send(:"original_#{attribute}=", value) 30 end 31 end 32 end 33 self 34 end
detach_patches()
click to toggle source
# File lib/aipp/patcher.rb 36 def detach_patches 37 self.class.patches[self.class]&.each do |(klass, attribute, _)| 38 klass.instance_eval do 39 alias_method :"#{attribute}=", :"original_#{attribute}=" 40 remove_method :"original_#{attribute}=" 41 end 42 end 43 self 44 end