Sha256: 893f03cae863803713aefcdc1a640a07bccfa367bf8756c3139b167db5adeb56
Contents?: true
Size: 965 Bytes
Versions: 6
Compression:
Stored size: 965 Bytes
Contents
module Mobility module ActiveRecord =begin Included into model if model has +ActiveRecord::AttributeMethods+ among its ancestors. =end module AttributeMethods delegate :translated_attribute_names, to: :class # Adds translated attributes to +attributes+. # @return [Array<String>] Model attributes # @!method attributes def self.included(model) attributes_method = Module.new do def attributes super.merge(translated_attributes) end end model.class_eval do alias_method :untranslated_attributes, :attributes include attributes_method end end # Translated attributes defined on model. # @return [Array<String>] Translated attributes def translated_attributes translated_attribute_names.inject({}) do |attributes, name| attributes.merge(name.to_s => send(name)) end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems