Sha256: 33db41c6c15dd4c7043f859d8fae4d9fecde3231ad8ac1e7b82cf785219499bd
Contents?: true
Size: 1.01 KB
Versions: 3
Compression:
Stored size: 1.01 KB
Contents
module Mobility module Plugins =begin Module builder adding translated attributes to #attributes hash on model instance. See {Mobility::Plugins::AttributeMethods} for further details. =end module ActiveRecord module TranslatedAttributes def translated_attributes {} end def attributes super.merge(translated_attributes) end end class AttributeMethods < Module def initialize(*attribute_names) include TranslatedAttributes define_method :translated_attributes do super().merge(attribute_names.inject({}) do |attributes, name| attributes.merge(name.to_s => send(name)) end) end delegate :translated_attribute_names, to: :class end def included(model_class) model_class.class_eval do define_method :untranslated_attributes, ::ActiveRecord::Base.instance_method(:attributes) end end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems