Skip to content

Instantly share code, notes, and snippets.

@kaspth
Created April 24, 2024 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaspth/7263e05d19989ce10e28553ff6bcf483 to your computer and use it in GitHub Desktop.
Save kaspth/7263e05d19989ce10e28553ff6bcf483 to your computer and use it in GitHub Desktop.
class ActiveRecord::Relation::Loaded < Data.define(:records)
def where(**conditions)
records = @records.dup
conditions.each do |key, value|
records.select! { |record| record.send(key) == value }
end
with(records:)
end
# Not sure how to maintain the order of the passed in keys?
# Also need to parse SQL statements
def order(*ascending_clauses, **clauses)
clauses = ascending_clauses.chain(clauses).map do |key, direction = :asc|
end
with(records: records.sort_by { clauses.call _1 })
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment