module Sequel::Plugins::LazyAttributes::ClassMethods
Public Instance Methods
freeze()
click to toggle source
Freeze lazy attributes module when freezing model class.
Calls superclass method
# File lib/sequel/plugins/lazy_attributes.rb, line 51 def freeze @lazy_attributes_module.freeze if @lazy_attributes_module super end
lazy_attributes(*attrs)
click to toggle source
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.
# File lib/sequel/plugins/lazy_attributes.rb, line 60 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
lazy_attributes_module()
click to toggle source
# File lib/sequel/plugins/lazy_attributes.rb, line 41 def lazy_attributes_module Sequel::Deprecation.deprecate('Sequel::Model.lazy_attributes_module', 'There is no replacement') @lazy_attributes_module end
lazy_attributes_module=(v)
click to toggle source
# File lib/sequel/plugins/lazy_attributes.rb, line 45 def lazy_attributes_module=(v) Sequel::Deprecation.deprecate('Sequel::Model.lazy_attributes_module=', 'There is no replacement') @lazy_attributes_module= v end
Private Instance Methods
define_lazy_attribute_getter(a, opts=OPTS)
click to toggle source
Add a lazy attribute getter method to the lazy_attributes_module. Options:
- :dataset
-
The base dataset to use for the lazy attribute lookup
- :table
-
The table name to use to qualify the attribute and primary key columns.
Calls superclass method
# File lib/sequel/plugins/lazy_attributes.rb, line 73 def define_lazy_attribute_getter(a, opts=OPTS) include(@lazy_attributes_module ||= Module.new) unless @lazy_attributes_module @lazy_attributes_module.class_eval do define_method(a) do if !values.has_key?(a) && !new? lazy_attribute_lookup(a, opts) else super() end end end end