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