module ActiveFedora::AttributeMethods::Read::ClassMethods

def define_method_attribute(canonical_name, owner: nil, as: canonical_name)

def define_method_attribute(canonical_name, owner: nil, as: canonical_name)
  ActiveModel::AttributeMethods::AttrNames.define_attribute_accessor_method(
    owner, canonical_name
  ) do |temp_method_name, attr_name_expr|
    # rubocop:disable Style/LineEndConcatenation
    if ActiveModel.version >= Gem::Version.new('7.0.0')
      owner.define_cached_method(temp_method_name, as: as, namespace: :active_fedora) do |batch|
        batch <<
          "def #{temp_method_name}" <<
          "  _read_attribute(#{attr_name_expr}) { |n| missing_attribute(n, caller) }" <<
          "end"
      end
    else
      owner <<
        "def #{temp_method_name}" <<
        "  _read_attribute(#{attr_name_expr}) { |n| missing_attribute(n, caller) }" <<
        "end"
    end
    # rubocop:enable Style/LineEndConcatenation
  end
end