Sha256: f4e06496492b41447faf3b2a0b51794e9e5fd8128337b7d3b9e64c8984be781a

Contents?: true

Size: 939 Bytes

Versions: 5

Compression:

Stored size: 939 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

5 entries across 5 versions & 1 rubygems

Version Path
mobility-0.1.12 lib/mobility/backend/active_record/hstore.rb
mobility-0.1.11 lib/mobility/backend/active_record/hstore.rb
mobility-0.1.10 lib/mobility/backend/active_record/hstore.rb
mobility-0.1.7 lib/mobility/backend/active_record/hstore.rb
mobility-0.1.6 lib/mobility/backend/active_record/hstore.rb