Sha256: f2340fad87723d3e138a54500a85f9fd8957acaa4d7bd1422a19fd01421030d6

Contents?: true

Size: 1.44 KB

Versions: 20

Compression:

Stored size: 1.44 KB

Contents

require 'mobility/backends/active_record/pg_hash'
require 'mobility/arel/nodes/pg_ops'

module Mobility
  module Backends
=begin

Implements the {Mobility::Backends::Jsonb} backend for ActiveRecord models.

@see Mobility::Backends::HashValued

=end
    module ActiveRecord
      class Jsonb < PgHash
        # @!group Backend Accessors
        #
        # @!method read(locale, **options)
        #   @note Translation may be any json type, but querying will only work on
        #     string-typed values.
        #   @param [Symbol] locale Locale to read
        #   @param [Hash] options
        #   @return [String,Integer,Boolean] Value of translation

        # @!method write(locale, value, **options)
        #   @note Translation may be any json type, but querying will only work on
        #     string-typed values.
        #   @param [Symbol] locale Locale to write
        #   @param [String,Integer,Boolean] value Value to write
        #   @param [Hash] options
        #   @return [String,Integer,Boolean] Updated value
        # @!endgroup

        # @param [String] attr Attribute name
        # @param [Symbol] locale Locale
        # @return [Mobility::Arel::Nodes::Jsonb] Arel node for value of
        #   attribute key on jsonb column
        def self.build_node(attr, locale)
          column_name = column_affix % attr
          Arel::Nodes::Jsonb.new(model_class.arel_table[column_name], build_quoted(locale))
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
mobility-0.8.13 lib/mobility/backends/active_record/jsonb.rb
mobility-0.8.11 lib/mobility/backends/active_record/jsonb.rb
mobility-0.8.10 lib/mobility/backends/active_record/jsonb.rb
mobility-0.8.9 lib/mobility/backends/active_record/jsonb.rb
mobility-0.8.8 lib/mobility/backends/active_record/jsonb.rb
mobility-0.8.7 lib/mobility/backends/active_record/jsonb.rb
mobility-0.8.6 lib/mobility/backends/active_record/jsonb.rb
mobility-0.8.5 lib/mobility/backends/active_record/jsonb.rb
mobility-0.8.4 lib/mobility/backends/active_record/jsonb.rb
mobility-0.8.3 lib/mobility/backends/active_record/jsonb.rb
mobility-0.8.2 lib/mobility/backends/active_record/jsonb.rb
mobility-0.8.1 lib/mobility/backends/active_record/jsonb.rb
mobility-0.8.0 lib/mobility/backends/active_record/jsonb.rb
mobility-0.7.6 lib/mobility/backends/active_record/jsonb.rb
mobility-0.7.5 lib/mobility/backends/active_record/jsonb.rb
mobility-0.7.4 lib/mobility/backends/active_record/jsonb.rb
mobility-0.7.3 lib/mobility/backends/active_record/jsonb.rb
mobility-0.7.2 lib/mobility/backends/active_record/jsonb.rb
mobility-0.7.1 lib/mobility/backends/active_record/jsonb.rb
mobility-0.7.0 lib/mobility/backends/active_record/jsonb.rb