Sha256: 4e778486e60a9c4d7d3f2010bec9099f0c70c9828fd7ab5749f8b2af251ee6ab

Contents?: true

Size: 731 Bytes

Versions: 4

Compression:

Stored size: 731 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

class ActiveRecord::Base
  prepend AdaptiveAlias::ActiveModelPatches::WriteAttribute
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
adaptive_alias-0.2.4 lib/adaptive_alias/active_model_patches/write_attribute.rb
adaptive_alias-0.2.3 lib/adaptive_alias/active_model_patches/write_attribute.rb
adaptive_alias-0.2.2 lib/adaptive_alias/active_model_patches/write_attribute.rb
adaptive_alias-0.2.1 lib/adaptive_alias/active_model_patches/write_attribute.rb