Sha256: b3ac4ec6eaca8b4d4c67dba9e76ad70cd552e8aa7032402eddcb181b6d569442

Contents?: true

Size: 691 Bytes

Versions: 5

Compression:

Stored size: 691 Bytes

Contents

module Mobility
  module ActiveModel
=begin

Included into model if model has +ActiveModel::AttributeMethods+ among its
ancestors.

=end
    module AttributeMethods
      delegate :translated_attribute_names, to: :class

      # Adds translated attributes to +attributes+.
      # @return [Array<String>] Model attributes
      def attributes
        super.merge(translated_attributes)
      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

5 entries across 5 versions & 1 rubygems

Version Path
mobility-0.1.4 lib/mobility/active_model/attribute_methods.rb
mobility-0.1.3 lib/mobility/active_model/attribute_methods.rb
mobility-0.1.2 lib/mobility/active_model/attribute_methods.rb
mobility-0.1.1 lib/mobility/active_model/attribute_methods.rb
mobility-0.1.0 lib/mobility/active_model/attribute_methods.rb