Sha256: a6374eb8ec99af6cc97026b8875707b5d6190d1ed67c2ea600bb6f1e6d40ad34
Contents?: true
Size: 1.34 KB
Versions: 4
Compression:
Stored size: 1.34 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, **options) translations[locale] end # @!macro backend_writer def write(locale, value, **options) 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
4 entries across 4 versions & 1 rubygems