Sha256: 0fe031dd4ec367bedef528baa44b510ebf540748225642f32a368f7050d28682

Contents?: true

Size: 886 Bytes

Versions: 5

Compression:

Stored size: 886 Bytes

Contents

# frozen_string_literal: true
require "mobility/backends/active_record"
require "mobility/backends/hash_valued"

module Mobility
  module Backends
=begin

Internal class used by ActiveRecord backends backed by a Postgres data type
(hstore, jsonb).

=end
    module ActiveRecord
      class PgHash
        include ActiveRecord
        include HashValued

        def read(locale, _options = nil)
          translations[locale.to_s]
        end

        def write(locale, value, _options = nil)
          if value.nil?
            translations.delete(locale.to_s)
          else
            translations[locale.to_s] = value
          end
        end

        # @!macro backend_iterator
        def each_locale
          super { |l| yield l.to_sym }
        end

        def translations
          model[column_name]
        end
      end
      private_constant :PgHash
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mobility-1.3.1 lib/mobility/backends/active_record/pg_hash.rb
mobility-1.3.0 lib/mobility/backends/active_record/pg_hash.rb
mobility-1.3.0.rc3 lib/mobility/backends/active_record/pg_hash.rb
mobility-1.3.0.rc2 lib/mobility/backends/active_record/pg_hash.rb
mobility-1.3.0.rc1 lib/mobility/backends/active_record/pg_hash.rb