Module: Mongoid::Attributes::Readonly::ClassMethods
- Defined in:
- lib/mongoid/attributes/readonly.rb
Instance Method Summary collapse
-
#attr_readonly(*names) ⇒ Object
Defines an attribute as readonly.
Instance Method Details
#attr_readonly(*names) ⇒ Object
Defines an attribute as readonly. This will ensure that the value for the attribute is only set when the document is new or we are creating. In other cases, the field write will be ignored with the exception of #remove_attribute and #update_attribute, where an error will get raised.
48 49 50 51 52 |
# File 'lib/mongoid/attributes/readonly.rb', line 48 def attr_readonly(*names) names.each do |name| readonly_attributes << name.to_s end end |