Sha256: 57743dfe54bcd7485f8c3d8877d0d22a20b9ad2ad364d220ceb2c4300c27df28

Contents?: true

Size: 938 Bytes

Versions: 2

Compression:

Stored size: 938 Bytes

Contents

require 'mobility/backend/active_record/hash_valued'

module Mobility
  module Backend
=begin

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

@see Mobility::Backend::ActiveRecord::HashValued

=end
    class ActiveRecord::Hstore < ActiveRecord::HashValued
      autoload :QueryMethods, 'mobility/backend/active_record/hstore/query_methods'

      # @!group Backend Accessors
      # @!macro backend_reader
      # @!method read(locale, **options)

      # @!group Backend Accessors
      # @!macro backend_writer
      def write(locale, value, **)
        translations[locale] = value && value.to_s
      end
      # @!endgroup

      setup do |attributes, options|
        query_methods = Module.new do
          define_method :i18n do
            @mobility_scope ||= super().extending(QueryMethods.new(attributes, options))
          end
        end
        extend query_methods
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mobility-0.1.5 lib/mobility/backend/active_record/hstore.rb
mobility-0.1.4 lib/mobility/backend/active_record/hstore.rb