class ActiveRecord::Base
Public Instance Methods
calculated(*args)
click to toggle source
# File lib/calculated_attributes/model_methods.rb, line 22 def calculated(*args) if self.class.respond_to? :scoped self.class.scoped.calculated(*args).find(id) else self.class.all.calculated(*args).find(id) end end
method_missing(sym, *args)
click to toggle source
Calls superclass method
# File lib/calculated_attributes/model_methods.rb, line 30 def method_missing(sym, *args) no_sym_in_attr = if @attributes.respond_to? :include? !@attributes.include?(sym.to_s) else !@attributes.key?(sym.to_s) end if no_sym_in_attr && (self.class.calculated.calculated[sym] || self.class.base_class.calculated.calculated[sym]) Rails.logger.warn("Using calculated value without including it in the relation: #{sym}") if defined? Rails class_with_attr = if self.class.calculated.calculated[sym] self.class else self.class.base_class end if class_with_attr.respond_to? :scoped class_with_attr.scoped.calculated(sym => args).find(id).send(sym) else class_with_attr.all.calculated(sym => args).find(id).send(sym) end else super end end
respond_to_missing?(method, include_private = false)
click to toggle source
Calls superclass method
# File lib/calculated_attributes/model_methods.rb, line 55 def respond_to_missing?(method, include_private = false) no_sym_in_attr = if @attributes.respond_to? :include? !@attributes.include?(method.to_s) elsif @attributes.respond_to? :key? !@attributes.key?(method.to_s) else true end super || (no_sym_in_attr && (self.class.calculated.calculated[method] || self.class.base_class.calculated.calculated[method])) end