Sha256: 2a9865de7019f64f04f1abdb5e2907e7b2e7309129898bc679235356910d00b3
Contents?: true
Size: 1.33 KB
Versions: 5
Compression:
Stored size: 1.33 KB
Contents
module Mobility module Backend =begin Internal class used by ActiveRecord backends that store values as a hash. =end class ActiveRecord::HashValued include Backend # @!group Backend Accessors # # @!macro backend_reader def read(locale, **_) translations[locale] end # @!macro backend_writer def write(locale, value, **_) translations[locale] = value end # @!endgroup def translations model.read_attribute(attribute) end alias_method :new_cache, :translations def write_to_cache? true end setup do |attributes, options| attributes.each { |attribute| store attribute, coder: Coder } before_validation do attributes.each { |attribute| self.send(:"#{attribute}=", {}) if send(attribute).nil? } end end class Coder def self.dump(obj) if obj.is_a? Hash obj = obj.inject({}) do |translations, (locale, value)| translations[locale] = value if value.present? translations end else raise ArgumentError, "Attribute is supposed to be a Hash, but was a #{obj.class}. -- #{obj.inspect}" end end def self.load(obj) obj end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems