lib/mobility/backends/sequel/jsonb/query_methods.rb in mobility-0.5.1 vs lib/mobility/backends/sequel/jsonb/query_methods.rb in mobility-0.6.0

- old
+ new

@@ -4,24 +4,31 @@ Sequel.extension :pg_json, :pg_json_ops module Mobility module Backends - class Sequel::Jsonb::QueryMethods < Sequel::QueryMethods - include Sequel::PgQueryMethods + module Sequel + class Jsonb::QueryMethods < QueryMethods + include PgQueryMethods - private + def matches(key, locale) + build_op(key)[locale] + end - def matches(key, value, locale) - build_op(key)[locale] =~ value.to_json - end + def exists(key, locale) + build_op(key).has_key?(locale) + end - def has_locale(key, locale) - build_op(key).has_key?(locale) - end + def quote(value) + value && value.to_json + end - def build_op(key) - ::Sequel.pg_jsonb_op(key) + private + + def build_op(key) + ::Sequel.pg_jsonb_op(column_name(key)) + end end + Jsonb.private_constant :QueryMethods end end end