class DelegateCached::SourceInstaller
Public Instance Methods
callback_if_statement()
click to toggle source
# File lib/delegate_cached/source_installer.rb, line 53 def callback_if_statement return nil if @source.reflection.macro == :has_one ", if: :#{@source.column}_changed?" end
install_accessor_override_method()
click to toggle source
# File lib/delegate_cached/source_installer.rb, line 26 def install_accessor_override_method @source.model.class_eval %( def #{@source.column} unless self['#{@source.column}'].nil? return self['#{@source.column}'] end #{update_if_update_when_nil_option} #{@source.association}.#{@target.column} end ) end
install_callback()
click to toggle source
# File lib/delegate_cached/source_installer.rb, line 47 def install_callback @source.model.class_eval %( before_save :#{set_method_name}#{callback_if_statement} ) end
install_instance_methods()
click to toggle source
# File lib/delegate_cached/source_installer.rb, line 3 def install_instance_methods install_update_method install_accessor_override_method install_setter_override_method install_callback end
install_setter_override_method()
click to toggle source
# File lib/delegate_cached/source_installer.rb, line 38 def install_setter_override_method @source.model.class_eval %( def #{set_method_name} return unless #{@source.association} self['#{@source.column}'] = #{@source.association}.#{@target.column} end ) end
install_update_method()
click to toggle source
# File lib/delegate_cached/source_installer.rb, line 18 def install_update_method @source.model.class_eval %( def #{update_method_name} update(#{@source.column}: #{@source.association}.#{@target.column}) end ) end
set_method_name()
click to toggle source
# File lib/delegate_cached/source_installer.rb, line 14 def set_method_name "set_delegate_cached_value_for_#{@source.column}" end
update_if_update_when_nil_option()
click to toggle source
# File lib/delegate_cached/source_installer.rb, line 58 def update_if_update_when_nil_option update_method_name if options[:update_when_nil] end
update_method_name()
click to toggle source
# File lib/delegate_cached/source_installer.rb, line 10 def update_method_name "update_delegate_cached_value_for_#{@source.column}" end