Sha256: 38b8e9dda8ef9122e1461a3eb23df201d74605c0e73cc947b299c97db00e49e6

Contents?: true

Size: 915 Bytes

Versions: 1

Compression:

Stored size: 915 Bytes

Contents

# frozen_string_literal: true
require 'mobility/backends/active_record/pg_query_methods'
require "mobility/backends/active_record/query_methods"

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

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

        def matches(key, locale)
          build_infix(:'->>', build_infix(:'->', column, build_quoted(locale)), build_quoted(key))
        end

        def exists(key, locale)
          matches(key, locale).eq(nil).not
        end

        def absent(key, locale)
          matches(key, locale).eq(nil)
        end

        def quote(value)
          value.to_s
        end
      end
      Container.private_constant :JsonQueryMethods
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mobility-0.6.0 lib/mobility/backends/active_record/container/json_query_methods.rb