Skip to content

Instantly share code, notes, and snippets.

@jacksonpires
Last active May 26, 2023 21:37
Show Gist options
  • Save jacksonpires/ab4c7078b64d5741734694aa945e4403 to your computer and use it in GitHub Desktop.
Save jacksonpires/ab4c7078b64d5741734694aa945e4403 to your computer and use it in GitHub Desktop.
Create a custom node on Arel
# frozen_string_literal: true
module ArelNodesTrgm
class Arel::Nodes::Trgm < Arel::Nodes::InfixOperation
def initialize(left, right)
super(:"%", left, right)
end
end
class Arel::Visitors::PostgreSQL < Arel::Visitors::ToSql
alias_method(
:visit_Arel_Nodes_Trgm,
:visit_Arel_Nodes_InfixOperation
)
end
end
# to use, just "include ArelNodesTrgm"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment