Module: ActiveRecord::Bitwise::RelationExtension

Extended by:
T::Sig
Defined in:
lib/active_record/bitwise.rb

Overview

Prepended to ActiveRecord::Relation to handle batch updates and where poisoning

Instance Method Summary collapse

Instance Method Details

#update_all(updates) ⇒ Object



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/active_record/bitwise.rb', line 193

def update_all(updates)
  if updates.is_a?(Hash) && T.unsafe(self).klass.respond_to?(:bitwise_definitions)
    processed_updates = updates.dup
    T.unsafe(self).klass.bitwise_definitions.each_key do |column_name|
      [column_name, column_name.to_s].each do |key|
        next unless processed_updates.key?(key)

        val = processed_updates[key]
        next if val.is_a?(Integer)

        typecaster = T.unsafe(self).klass.attribute_types[column_name.to_s]
        processed_updates[key] = typecaster.serialize(typecaster.cast(val)) if typecaster.is_a?(ActiveRecord::Bitwise::Type)
      end
    end
    super(processed_updates)
  else
    super
  end
end

#where(*args) ⇒ Object



220
221
222
223
# File 'lib/active_record/bitwise.rb', line 220

def where(*args)
  check_bitwise_query!(args.first) if args.first.is_a?(Hash) && T.unsafe(self).klass.respond_to?(:bitwise_definitions)
  super
end