Sha256: aaf97f84c7fb4b082c4dd7b763a0cafef9705f44e49c46e78492ae22c27b502f

Contents?: true

Size: 874 Bytes

Versions: 11

Compression:

Stored size: 874 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
      # @!method attributes
      def self.included(model)
        model.class_eval do
          alias_method :untranslated_attributes, :attributes

          def attributes
            super.merge(translated_attributes)
          end
        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

11 entries across 11 versions & 1 rubygems

Version Path
mobility-0.1.17 lib/mobility/active_model/attribute_methods.rb
mobility-0.1.16 lib/mobility/active_model/attribute_methods.rb
mobility-0.1.15 lib/mobility/active_model/attribute_methods.rb
mobility-0.1.14 lib/mobility/active_model/attribute_methods.rb
mobility-0.1.13 lib/mobility/active_model/attribute_methods.rb
mobility-0.1.12 lib/mobility/active_model/attribute_methods.rb
mobility-0.1.11 lib/mobility/active_model/attribute_methods.rb
mobility-0.1.10 lib/mobility/active_model/attribute_methods.rb
mobility-0.1.7 lib/mobility/active_model/attribute_methods.rb
mobility-0.1.6 lib/mobility/active_model/attribute_methods.rb
mobility-0.1.5 lib/mobility/active_model/attribute_methods.rb