Sha256: 3419a24689da613765e4f4f3707d2dead50fac3e3fd228071d0271849865a8ca

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

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

module Mobility
  module Backends
=begin

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

@see Mobility::Backends::HashValued

=end
    module ActiveRecord
      class Hstore < PgHash
        # @!group Backend Accessors
        # @!macro backend_reader
        # @!method read(locale, options = {})

        # @!macro backend_writer
        def write(locale, value, options = {})
          super(locale, value && value.to_s, **options)
        end
        # @!endgroup

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

    register_backend(:active_record_hstore, ActiveRecord::Hstore)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mobility-1.0.0.beta2 lib/mobility/backends/active_record/hstore.rb
mobility-1.0.0.beta1 lib/mobility/backends/active_record/hstore.rb