Sha256: 738a187aade9d707a79d8fbc219de1c65c818c8bcdb8c00a9914bbb9d65bab20
Contents?: true
Size: 1.45 KB
Versions: 12
Compression:
Stored size: 1.45 KB
Contents
# frozen_string_literal: true require "mobility/util" require "mobility/backends/sequel" require "mobility/backends/hash_valued" module Mobility module Backends =begin Internal class used by Sequel backends backed by a Postgres data type (hstore, jsonb). =end module Sequel class PgHash include Sequel include HashValued def read(locale, options = {}) super(locale.to_s, options) end def write(locale, value, options = {}) super(locale.to_s, value, options) end # @!macro backend_iterator def each_locale super { |l| yield l.to_sym } end def translations model[column_name.to_sym] end backend = self setup do |attributes, options| columns = attributes.map { |attribute| (options[:column_affix] % attribute).to_sym } mod = Module.new do define_method :before_validation do columns.each do |column| self[column].delete_if { |_, v| Util.blank?(v) } end super() end end include mod backend.define_hash_initializer(mod, columns) backend.define_column_changes(mod, attributes, column_affix: options[:column_affix]) plugin :defaults_setter columns.each { |column| default_values[column] = {} } end end private_constant :PgHash end end end
Version data entries
12 entries across 12 versions & 1 rubygems