Sha256: f7f2dbf8ead23485cd0556de76d10e954e15f5639be8eae48b2d1c6aa64e951a

Contents?: true

Size: 1.08 KB

Versions: 26

Compression:

Stored size: 1.08 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::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::Plugins::Arel::Nodes::Hstore] Arel node for value of
        #   attribute key on hstore column
        def self.build_node(attr, locale)
          column_name = column_affix % attr
          Plugins::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

26 entries across 26 versions & 1 rubygems

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