Sha256: 958f131949217f88ecaf6e610d8f4547ea7acacb45cbe683ff8a5bde6538cd63

Contents?: true

Size: 1.53 KB

Versions: 26

Compression:

Stored size: 1.53 KB

Contents

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

module Mobility
  module Backends
=begin

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

@see Mobility::Backends::HashValued

=end
    module ActiveRecord
      class Json < PgHash
        # @!group Backend Accessors
        #
        # @!method read(locale, **options)
        #   @note Translation may be string, integer or boolean-valued since
        #     value is stored on a JSON hash.
        #   @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 string, integer or boolean-valued since
        #     value is stored on a JSON hash.
        #   @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::Plugins::Arel::Nodes::Json] Arel node for value of
        #   attribute key on jsonb column
        def self.build_node(attr, locale)
          column_name = column_affix % attr
          Plugins::Arel::Nodes::Json.new(model_class.arel_table[column_name], build_quoted(locale))
        end
      end
    end

    register_backend(:active_record_json, ActiveRecord::Json)
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
mobility-1.3.0.rc3 lib/mobility/backends/active_record/json.rb
mobility-1.3.0.rc2 lib/mobility/backends/active_record/json.rb
mobility-1.3.0.rc1 lib/mobility/backends/active_record/json.rb
mobility-1.2.9 lib/mobility/backends/active_record/json.rb
mobility-1.2.8 lib/mobility/backends/active_record/json.rb
mobility-1.2.7 lib/mobility/backends/active_record/json.rb
mobility-1.2.6 lib/mobility/backends/active_record/json.rb
mobility-1.2.5 lib/mobility/backends/active_record/json.rb
mobility-1.2.4 lib/mobility/backends/active_record/json.rb
mobility-1.2.3 lib/mobility/backends/active_record/json.rb
mobility-1.2.2 lib/mobility/backends/active_record/json.rb
mobility-1.2.1 lib/mobility/backends/active_record/json.rb
mobility-1.2.0 lib/mobility/backends/active_record/json.rb
mobility-1.1.3 lib/mobility/backends/active_record/json.rb
mobility-1.1.2 lib/mobility/backends/active_record/json.rb
mobility-1.1.1 lib/mobility/backends/active_record/json.rb
mobility-1.1.0 lib/mobility/backends/active_record/json.rb
mobility-1.0.7 lib/mobility/backends/active_record/json.rb
mobility-1.0.6 lib/mobility/backends/active_record/json.rb
mobility-1.0.5 lib/mobility/backends/active_record/json.rb