class DelegateCached::TargetInstaller
Public Instance Methods
install_callback()
click to toggle source
# File lib/delegate_cached/target_installer.rb, line 16 def install_callback @target.model.class_eval %( after_save :#{update_method_name}, if: :#{@target.column}_changed? ) end
install_instance_methods()
click to toggle source
# File lib/delegate_cached/target_installer.rb, line 3 def install_instance_methods install_update_method install_callback unless options[:no_callback] || options[:polymorphic] end
install_update_method()
click to toggle source
# File lib/delegate_cached/target_installer.rb, line 8 def install_update_method @target.model.class_eval %( def #{update_method_name} #{update_method_body} end ) end
update_all_line()
click to toggle source
# File lib/delegate_cached/target_installer.rb, line 36 def update_all_line ".update_all(#{@source.column}: #{@target.column})" end
update_method_body()
click to toggle source
# File lib/delegate_cached/target_installer.rb, line 27 def update_method_body case @source.reflection.macro when :belongs_to update_method_body_for_has_one_or_has_many when :has_one update_method_body_for_belongs_to end end
update_method_body_for_belongs_to()
click to toggle source
# File lib/delegate_cached/target_installer.rb, line 47 def update_method_body_for_belongs_to %( #{@source.model}.where(id: #{@target.association}_id) #{update_all_line} ) end
update_method_body_for_has_one_or_has_many()
click to toggle source
# File lib/delegate_cached/target_installer.rb, line 40 def update_method_body_for_has_one_or_has_many %( #{@source.model}.where(#{@source.association}_id: id) #{update_all_line} ) end
update_method_name()
click to toggle source
# File lib/delegate_cached/target_installer.rb, line 22 def update_method_name 'update_delegate_cached_value_for_' \ "#{@source.plural_underscored_model_name}_#{@source.column}" end