Sha256: cba78c6701b831d40ba168be57d46e65fe273413f609c736ec479cdbe90baf56

Contents?: true

Size: 788 Bytes

Versions: 7

Compression:

Stored size: 788 Bytes

Contents

require 'active_record'

module AdaptiveAlias
  module ActiveModelPatches
    module WriteAttribute
      def write_attribute(attr_name, value)
        name = attr_name.to_s
        name = self.class.attribute_aliases[name] || name
        super(name, value)
      end

      # This method exists to avoid the expensive primary_key check internally, without
      # breaking compatibility with the write_attribute API
      def _write_attribute(attr_name, value) # :nodoc:
        name = attr_name.to_s
        name = self.class.attribute_aliases[name] || name
        super(name, value)
      end
    end
  end
end

# Nested module include is not supported until ruby 3.0
class ActiveRecord::Base
  prepend AdaptiveAlias::ActiveModelPatches::WriteAttribute
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
adaptive_alias-1.3.0 lib/adaptive_alias/active_model_patches/write_attribute.rb
adaptive_alias-1.2.1 lib/adaptive_alias/active_model_patches/write_attribute.rb
adaptive_alias-1.2.0 lib/adaptive_alias/active_model_patches/write_attribute.rb
adaptive_alias-1.1.2 lib/adaptive_alias/active_model_patches/write_attribute.rb
adaptive_alias-1.1.1 lib/adaptive_alias/active_model_patches/write_attribute.rb
adaptive_alias-1.1.0 lib/adaptive_alias/active_model_patches/write_attribute.rb
adaptive_alias-1.0.0 lib/adaptive_alias/active_model_patches/write_attribute.rb