Module: Mongoid::Attributes::ClassMethods

Defined in:
lib/mongoid/attributes.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#alias_attribute(name, original) ⇒ Object

Alias the provided name to the original field. This will provide an aliased getter, setter, existance check, and all dirty attribute methods.

Examples:

Alias the attribute.

class Product
  include Mongoid::Document
  field :price, :type => Float
  alias_attribute :cost, :price
end

Parameters:

  • name (Symbol)

    The new name.

  • original (Symbol)

    The original name.

Since:

  • 2.3.0



206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/mongoid/attributes.rb', line 206

def alias_attribute(name, original)
  class_eval "    alias :\#{name} :\#{original}\n    alias :\#{name}= :\#{original}=\n    alias :\#{name}? :\#{original}?\n    alias :\#{name}_change :\#{original}_change\n    alias :\#{name}_changed? :\#{original}_changed?\n    alias :reset_\#{name}! :reset_\#{original}!\n    alias :\#{name}_was :\#{original}_was\n    alias :\#{name}_will_change! :\#{original}_will_change!\n  RUBY\nend\n"