Module: Sequel::Plugins::LazyAttributes::ClassMethods

Defined in:
lib/sequel/plugins/lazy_attributes.rb

Instance Method Summary collapse

Instance Method Details

#lazy_attributes(*attrs) ⇒ Object

Remove the given attributes from the list of columns selected by default. For each attribute given, create an accessor method that allows a lazy lookup of the attribute. Each attribute should be given as a symbol.



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sequel/plugins/lazy_attributes.rb', line 35

def lazy_attributes(*attrs)
  set_dataset(dataset.select(*(columns - attrs)))
  attrs.each do |a|
    define_method(a) do
      if !values.include?(a) && !new?
        lazy_attribute_lookup(a)
      else
        super()
      end
    end
  end
end