Sha256: c6d6a2dc2d9d892aec40125af64b871fba8f3c53aa1634d8a91ce46b2c2f3999
Contents?: true
Size: 1.54 KB
Versions: 4
Compression:
Stored size: 1.54 KB
Contents
module ActiveRecord module ActsAs module InstanceMethods def acting_as?(other = nil) self.class.acting_as? other end def is_a?(klass) super || acting_as?(klass) end def actable_must_be_valid unless acting_as.valid? acting_as.errors.each do |att, message| errors.add(att, message) end end end protected :actable_must_be_valid def read_attribute(attr_name, *args, &block) if attribute_method?(attr_name.to_s) super else acting_as.read_attribute(attr_name, *args, &block) end end def write_attribute(attr_name, value, *args, &block) if attribute_method?(attr_name.to_s) super else acting_as.send(:write_attribute, attr_name, value, *args, &block) end end private :write_attribute def attributes acting_as.attributes.except(acting_as_reflection.type, acting_as_reflection.foreign_key).merge(super) end def attribute_names super | (acting_as.attribute_names - [acting_as_reflection.type, acting_as_reflection.foreign_key]) end def respond_to?(name, include_private = false) super || acting_as.respond_to?(name) end def dup super.acting_as = acting_as.dup end def method_missing(method, *args, &block) if acting_as.respond_to?(method) acting_as.send(method, *args, &block) else super end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems