Module: NoBrainer::Document::LazyFetch

Extended by:
ActiveSupport::Concern
Defined in:
lib/no_brainer/document/lazy_fetch.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#assign_attributes(attrs, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/no_brainer/document/lazy_fetch.rb', line 9

def assign_attributes(attrs, options={})
  if options[:lazy_fetch].present?
    lazy_fetch = options[:lazy_fetch]
    lazy_fetch = lazy_fetch.keys if lazy_fetch.is_a?(Hash)
    @lazy_fetch = Set.new(lazy_fetch.map(&:to_s))
  end
  super
end

#reload(options = {}) ⇒ Object



18
19
20
21
22
23
# File 'lib/no_brainer/document/lazy_fetch.rb', line 18

def reload(options={})
  lazy_fetch = self.class.fields_to_lazy_fetch.to_a
  return super unless lazy_fetch.present?
  return super if options[:pluck]
  super(options.deep_merge(:without => lazy_fetch, :lazy_fetch => lazy_fetch))
end