Sha256: 4b4f8f54232d8d18bce5e7b016b8db671a57b3b89d1f9c780c5754dcc12c70d9

Contents?: true

Size: 1007 Bytes

Versions: 6

Compression:

Stored size: 1007 Bytes

Contents

module ActiveRecord
    module CheckArrayBeforeUpdate
      def mark_arrays_for_update
        @attributes_cache.each do |name, value|
          attribute_will_change!(name) if Array === value && _read_attribute(name) != value
        end
      end
    end
  if VERSION::MAJOR < 3
    module CheckArrayBeforeUpdate
      def self.included(base)
        base.alias_method_chain :update, :check_array
        base.send(:alias_method, :_read_attribute, :read_attribute)
      end

      def update_with_check_array
        mark_arrays_for_update
        update_without_check_array
      end
    end
  else
    module CheckArrayBeforeUpdate
      include ActiveSupport::Concern

      if VERSION::MAJOR == 3 && VERSION::MINOR >= 2
        def _read_attribute(attr_name)
          column_for_attribute(attr_name).type_cast(@attributes[attr_name])
        end
      end

      def update(*)
        mark_arrays_for_update
        super
      end
    end
  end
  Base.__send__ :include, CheckArrayBeforeUpdate
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
ar_jdbc_pg_array-0.1.1-java lib/ar_jdbc_pg_array/allways_save.rb
ar_jdbc_pg_array-0.1.0-java lib/ar_jdbc_pg_array/allways_save.rb
ar_pg_array-0.11.2 lib/ar_pg_array/allways_save.rb
ar_pg_array-0.11.1 lib/ar_pg_array/allways_save.rb
ar_pg_array-0.11.0 lib/ar_pg_array/allways_save.rb
ar_pg_array-0.9.13 lib/ar_pg_array/allways_save.rb