Module: Sequel::Plugins::LazyAttributes::ClassMethods
- Defined in:
- lib/sequel/plugins/lazy_attributes.rb
Instance Attribute Summary collapse
-
#lazy_attributes_module ⇒ Object
Module to store the lazy attribute getter methods, so they can be overridden and call super to get the lazy attribute behavior.
Instance Method Summary collapse
-
#lazy_attributes(*attrs) ⇒ Object
Remove the given attributes from the list of columns selected by default.
Instance Attribute Details
#lazy_attributes_module ⇒ Object
Module to store the lazy attribute getter methods, so they can be overridden and call super to get the lazy attribute behavior
43 44 45 |
# File 'lib/sequel/plugins/lazy_attributes.rb', line 43 def lazy_attributes_module @lazy_attributes_module end |
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.
48 49 50 51 52 53 54 |
# File 'lib/sequel/plugins/lazy_attributes.rb', line 48 def lazy_attributes(*attrs) unless select = dataset.opts[:select] select = dataset.columns.map{|c| Sequel.qualify(dataset.first_source, c)} end set_dataset(dataset.select(*select.reject{|c| attrs.include?(dataset.send(:_hash_key_symbol, c))})) attrs.each{|a| define_lazy_attribute_getter(a)} end |