module Sequel::Plugins::ForbidLazyLoad::InstanceMethods
Public Instance Methods
allow_lazy_load()
click to toggle source
Set this model instance to allow lazy loading of associations.
# File lib/sequel/plugins/forbid_lazy_load.rb, line 133 def allow_lazy_load @forbid_lazy_load = false self end
forbid_lazy_load()
click to toggle source
Set this model instance to not allow lazy loading of associations.
# File lib/sequel/plugins/forbid_lazy_load.rb, line 139 def forbid_lazy_load @forbid_lazy_load = true self end
Private Instance Methods
_load_associated_object(opts, dynamic_opts)
click to toggle source
Allow lazy loading for objects returned by singular associations.
Calls superclass method
# File lib/sequel/plugins/forbid_lazy_load.rb, line 147 def _load_associated_object(opts, dynamic_opts) # The implementation that loads these associations does # .all.first, which would result in the object returned being # marked as forbidding lazy load. obj = super obj.allow_lazy_load if obj.is_a?(InstanceMethods) obj end
_load_associated_objects(opts, dynamic_opts=OPTS)
click to toggle source
Raise an Error if lazy loading has been forbidden for the instance, association, or call.
Calls superclass method
# File lib/sequel/plugins/forbid_lazy_load.rb, line 158 def _load_associated_objects(opts, dynamic_opts=OPTS) case dynamic_opts[:forbid_lazy_load] when false # nothing when nil unless dynamic_opts[:reload] case opts[:forbid_lazy_load] when nil raise Error, "lazy loading forbidden for this object (association: #{opts.inspect}, object: #{inspect})" if @forbid_lazy_load when false # nothing else raise Error, "lazy loading forbidden for this association (#{opts.inspect})" end end else raise Error, "lazy loading forbidden for this association method call (association: #{opts.inspect})" end super end