Module: Mongoid::Attributes::Readonly

Extended by:
ActiveSupport::Concern
Included in:
Mongoid::Attributes
Defined in:
build/mongoid-8.1/lib/mongoid/attributes/readonly.rb

Overview

This module defines behavior for readonly attributes.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#attribute_writable?(name) ⇒ true | false

Are we able to write the attribute with the provided name?

Examples:

Can we write the attribute?

model.attribute_writable?(:title)

Parameters:

  • name (String | Symbol)

    The name of the field.

Returns:

  • (true | false)

    If the document is new, or if the field is not readonly.



24
25
26
# File 'build/mongoid-8.1/lib/mongoid/attributes/readonly.rb', line 24

def attribute_writable?(name)
  new_record? || (!readonly_attributes.include?(name) && _loaded?(name))
end