Sha256: 0cb52c577a5a35f9c46e97a08f14360961a0914f2e467aa387f8551b94bfe3a4

Contents?: true

Size: 845 Bytes

Versions: 2

Compression:

Stored size: 845 Bytes

Contents

# frozen_string_literal: true
require "mobility/backends/sequel/pg_query_methods"
require "mobility/backends/sequel/query_methods"

Sequel.extension :pg_json, :pg_json_ops

module Mobility
  module Backends
    class Sequel::Container::JsonbQueryMethods < Sequel::QueryMethods
      include Sequel::PgQueryMethods
      attr_reader :column_name

      def initialize(attributes, options)
        super
        @column_name = options[:column_name]
        define_query_methods
      end

      private

      def matches(key, value, locale)
        build_op(column_name)[locale][key.to_s] =~ value.to_json
      end

      def has_locale(key, locale)
        build_op(column_name).has_key?(locale) & build_op(column_name)[locale].has_key?(key.to_s)
      end

      def build_op(key)
        ::Sequel.pg_jsonb_op(key)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mobility-0.5.1 lib/mobility/backends/sequel/container/jsonb_query_methods.rb
mobility-0.5.0 lib/mobility/backends/sequel/container/jsonb_query_methods.rb