Module: Mcmire::ArAttrLazy::BaseExt::ClassMethods
- Defined in:
- lib/mcmire/ar_attr_lazy/base_ext.rb
Instance Method Summary collapse
- #find_with_attr_lazy(*args) ⇒ Object
- #read_lazy_attribute(record, attr) ⇒ Object
- #unlazy_column_list ⇒ Object
- #unlazy_column_names ⇒ Object
Instance Method Details
#find_with_attr_lazy(*args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mcmire/ar_attr_lazy/base_ext.rb', line 13 def find_with_attr_lazy(*args) # don't limit :select clause if there aren't any lazy attributes defined on this model # or we're inside a scope right now that has already defined :select if attr_lazy_columns.empty? or (scope = scope(:find) and scope[:select]) find_without_attr_lazy(*args) else with_scope(:find => { :select => unlazy_column_list }) do find_without_attr_lazy(*args) end end end |
#read_lazy_attribute(record, attr) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/mcmire/ar_attr_lazy/base_ext.rb', line 25 def read_lazy_attribute(record, attr) # we use with_exclusive_scope here to override any :includes that may have happened in a parent scope select = [primary_key, attr].map {|c| "#{quoted_table_name}.#{connection.quote_column_name(c)}" }.join(",") with_exclusive_scope(:find => { :select => select }) do find_without_attr_lazy(record[primary_key])[attr] end end |
#unlazy_column_list ⇒ Object
9 10 11 |
# File 'lib/mcmire/ar_attr_lazy/base_ext.rb', line 9 def unlazy_column_list unlazy_column_names.map {|c| "#{quoted_table_name}.#{connection.quote_column_name(c)}" }.join(",") end |
#unlazy_column_names ⇒ Object
5 6 7 |
# File 'lib/mcmire/ar_attr_lazy/base_ext.rb', line 5 def unlazy_column_names column_names - attr_lazy_columns end |