Skip to content

Commit

Permalink
CCOL-2039: Add block to partition! function
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Pereira committed Nov 29, 2023
1 parent 2c2cff1 commit ef26945
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/deimos/active_record_consume/batch_record_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,25 @@ def filter!(method)
self.batch_records.delete_if { |record| !method.call(record.record) }
end

# Filter and return removed invalid batch records by the specified method or block
# @param method [Proc]
# @param block [Proc]
# @return [Array<BatchRecord>]
def partition!(method)
valid, invalid = case method.parameters.size
when 2
self.batch_records.partition do |record|
method.call(record.record, record.associations)
end
def partition!(method=nil, &block)
valid, invalid = if method.nil?
self.batch_records.partition(&block)
else
self.batch_records.partition do |record|
method.call(record.record)
case method.parameters.size
when 2
self.batch_records.partition do |record|
method.call(record.record, record.associations)
end
else
self.batch_records.partition do |record|
method.call(record.record)
end
end
end
end
self.batch_records = valid
invalid
end
Expand Down

0 comments on commit ef26945

Please sign in to comment.