module Mongoid::Attributes::ClassMethods
Public Instance Methods
alias_attribute(name, original)
click to toggle source
Alias the provided name to the original field. This will provide an aliased getter, setter, existence check, and all dirty attribute methods.
@example Alias the attribute.
class Product include Mongoid::Document field :price, :type => Float alias_attribute :cost, :price end
@param [ Symbol ] name The new name. @param [ Symbol ] original The original name.
@since 2.3.0
# File lib/mongoid/attributes.rb, line 323 def alias_attribute(name, original) aliased_fields[name.to_s] = original.to_s alias_method name, original alias_method "#{name}=", "#{original}=" alias_method "#{name}?", "#{original}?" alias_method "#{name}_change", "#{original}_change" alias_method "#{name}_changed?", "#{original}_changed?" alias_method "reset_#{name}!", "reset_#{original}!" alias_method "reset_#{name}_to_default!", "reset_#{original}_to_default!" alias_method "#{name}_was", "#{original}_was" alias_method "#{name}_will_change!", "#{original}_will_change!" alias_method "#{name}_before_type_cast", "#{original}_before_type_cast" end