Sha256: 613f90a2b854ab40213292953b45a571f02edcd0b01477d03095ac576ce6d8da

Contents?: true

Size: 1.25 KB

Versions: 9

Compression:

Stored size: 1.25 KB

Contents

require "mobility/util"
require "mobility/backends/sequel"
require "mobility/backends/hash_valued"
require "mobility/backend/stringify_locale"
require "mobility/sequel/column_changes"

module Mobility
  module Backends
=begin

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

=end
    class Sequel::PgHash
      include Sequel
      include HashValued
      include StringifyLocale

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

      def translations
        model[attribute.to_sym]
      end

      setup do |attributes|
        method_overrides = Module.new do
          define_method :initialize_set do |values|
            attributes.each { |attribute| self[attribute.to_sym] = {} }
            super(values)
          end
          define_method :before_validation do
            attributes.each do |attribute|
              self[attribute.to_sym].delete_if { |_, v| Util.blank?(v) }
            end
            super()
          end
        end
        include method_overrides
        include Mobility::Sequel::ColumnChanges.new(attributes)

        plugin :defaults_setter
        attributes.each { |attribute| default_values[attribute.to_sym] = {} }
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mobility-0.3.6 lib/mobility/backends/sequel/pg_hash.rb
mobility-0.3.5 lib/mobility/backends/sequel/pg_hash.rb
mobility-0.3.4 lib/mobility/backends/sequel/pg_hash.rb
mobility-0.3.3 lib/mobility/backends/sequel/pg_hash.rb
mobility-0.3.2 lib/mobility/backends/sequel/pg_hash.rb
mobility-0.3.1 lib/mobility/backends/sequel/pg_hash.rb
mobility-0.3.0 lib/mobility/backends/sequel/pg_hash.rb
mobility-0.2.3 lib/mobility/backends/sequel/pg_hash.rb
mobility-0.2.2 lib/mobility/backends/sequel/pg_hash.rb