Skip to content

Instantly share code, notes, and snippets.

@iloveivyxuan
Created August 15, 2017 06:49
Show Gist options
  • Save iloveivyxuan/7dfbfc40b2e3c658148bbb52075c614f to your computer and use it in GitHub Desktop.
Save iloveivyxuan/7dfbfc40b2e3c658148bbb52075c614f to your computer and use it in GitHub Desktop.
Define Area Nodes -- Add a contain operator to Arel Nodes
# app/config/initializers/arel.rb
require 'arel/nodes/binary'
require 'arel/predications'
require 'arel/visitors/postgresql'
module Arel
class Nodes::ContainsArray < Arel::Nodes::Binary
def operator
:"@>"
end
end
class Visitors::PostgreSQL
private
def visit_Arel_Nodes_ContainsArray(o, collector)
infix_value o, collector, ' @> '
end
end
module Predications
def contains(other)
Nodes::ContainsArray.new self, Nodes.build_quoted(other, self)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment