module Urbix::ActsAsView::ClassMethods
Public Class Methods
view()
click to toggle source
# File lib/urbix/acts_as_view.rb, line 113 def self.view # View method return ActiveRecord Relation to retrieve view element in one request sc,fc,wc = self.class_variable_get(:@@_View__Relations) select(sc).from(fc).where(wc) end
Public Instance Methods
acts_as_view(options = {}) { |vr| ... }
click to toggle source
# File lib/urbix/acts_as_view.rb, line 102 def acts_as_view(options = {}) Logger.debug "ActsAsView on #{self}" # 1. call block to customise views attributes vr = ViewRelations.new(self) yield vr if block_given? sc = self.columns_hash.keys.collect{|col| "#{self.table_name}.#{col}"} sc << vr.select_clause unless vr.select_clause.empty? fc = vr.from_clause wc = vr.join_clause self.class_variable_set(:@@_View__Relations,[sc,fc,wc]) class_eval do def self.view # View method return ActiveRecord Relation to retrieve view element in one request sc,fc,wc = self.class_variable_get(:@@_View__Relations) select(sc).from(fc).where(wc) end end end