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
134 def allow_lazy_load
135   @forbid_lazy_load = false
136   self
137 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
140 def forbid_lazy_load
141   @forbid_lazy_load = true
142   self
143 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
148 def _load_associated_object(opts, dynamic_opts)
149   # The implementation that loads these associations does
150   # .all.first, which would result in the object returned being
151   # marked as forbidding lazy load.
152   obj = super
153   obj.allow_lazy_load if obj.is_a?(InstanceMethods)
154   obj
155 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
159 def _load_associated_objects(opts, dynamic_opts=OPTS)
160   case dynamic_opts[:forbid_lazy_load]
161   when false
162     # nothing
163   when nil
164     unless dynamic_opts[:reload]
165       case opts[:forbid_lazy_load]
166       when nil
167         raise Error, "lazy loading forbidden for this object (association: #{opts.inspect}, object: #{inspect})" if @forbid_lazy_load
168       when false
169         # nothing
170       else
171         raise Error, "lazy loading forbidden for this association (#{opts.inspect})"
172       end
173     end
174   else
175     raise Error, "lazy loading forbidden for this association method call (association: #{opts.inspect})"
176   end
177 
178   super
179 end