Sha256: 31b017761e6e239a1c611fa9ce2d4d63bd448da928821394cef259a6e4961670

Contents?: true

Size: 860 Bytes

Versions: 3

Compression:

Stored size: 860 Bytes

Contents

require "mobility/backends/active_record/jsonb"

module Mobility
  module Backends
    class ActiveRecord::Container::QueryMethods < ActiveRecord::QueryMethods
      include ActiveRecord::PgQueryMethods
      attr_reader :column_name, :column

      def initialize(_attributes, options)
        super
        @column_name = options[:column_name]
        @column      = arel_table[@column_name]
      end

      private

      def matches(key, value, locale)
        build_infix(:'->',
                    build_infix(:'->', column, quote(locale)),
                    quote(key)).eq(quote(value.to_json))
      end

      def has_locale(key, locale)
        build_infix(:'?', column, quote(locale)).and(
          build_infix(:'?',
                      build_infix(:'->', column, quote(locale)),
                      quote(key)))
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mobility-0.4.3 lib/mobility/backends/active_record/container/query_methods.rb
mobility-0.4.2 lib/mobility/backends/active_record/container/query_methods.rb
mobility-0.4.1 lib/mobility/backends/active_record/container/query_methods.rb