module Sequel::Plugins::LazyAttributes::ClassMethods
Public Instance Methods
Source
# File lib/sequel/plugins/lazy_attributes.rb 42 def freeze 43 @lazy_attributes_module.freeze if @lazy_attributes_module 44 45 super 46 end
Freeze lazy attributes module when freezing model class.
Calls superclass method
Source
# File lib/sequel/plugins/lazy_attributes.rb 51 def lazy_attributes(*attrs) 52 unless select = dataset.opts[:select] 53 select = dataset.columns.map{|c| Sequel.qualify(dataset.first_source, c)} 54 end 55 db_schema = @db_schema 56 set_dataset(dataset.select(*select.reject{|c| attrs.include?(dataset.send(:_hash_key_symbol, c))})) 57 @db_schema = db_schema 58 attrs.each{|a| define_lazy_attribute_getter(a)} 59 end
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.
Private Instance Methods
Source
# File lib/sequel/plugins/lazy_attributes.rb 66 def define_lazy_attribute_getter(a, opts=OPTS) 67 include(@lazy_attributes_module ||= Sequel.set_temp_name(Module.new){"#{name}::@lazy_attributes_module"}) unless @lazy_attributes_module 68 @lazy_attributes_module.class_eval do 69 define_method(a) do 70 if !values.has_key?(a) && !new? 71 lazy_attribute_lookup(a, opts) 72 else 73 super() 74 end 75 end 76 alias_method(a, a) 77 end 78 end
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