instance method define_method_attribute=

Ruby on Rails edge

Since edge Private — implementation detail, not part of the public API

Signature

define_method_attribute=(canonical_name, owner:, as: canonical_name)

No documentation comment.

Parameters

canonical_name req
owner keyreq
as key = canonical_name
Source
# File activerecord/lib/active_record/readonly_attributes.rb, line 62
        def define_method_attribute=(canonical_name, owner:, as: canonical_name)
          if ActiveRecord._raise_on_assign_to_attr_readonly && readonly_attribute?(canonical_name)
            ActiveModel::AttributeMethods::AttrNames.define_attribute_accessor_method(
              canonical_name, writer: true,
            ) do |temp_method_name, attr_name_expr|
              owner.define_cached_method(temp_method_name, as: "#{as}=", namespace: :active_record_readonly) do |batch|
                batch <<
                  "def #{temp_method_name}(value)" <<
                  "  unless new_record?" <<
                  "    raise ActiveRecord::ReadonlyAttributeError.new(#{attr_name_expr})" <<
                  "  end" <<
                  "  @attributes.write_from_user(#{attr_name_expr}, value)" <<
                  "end"
              end
            end
          else
            super
          end
        end

Defined in activerecord/lib/active_record/readonly_attributes.rb line 62 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::ReadonlyAttributes::ClassMethods

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close