Module: Mobility::ActiveRecord::AttributeMethods

Defined in:
lib/mobility/active_record/attribute_methods.rb

Overview

Included into model if model has ActiveRecord::AttributeMethods among its ancestors.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(model) ⇒ Array<String>

Adds translated attributes to attributes.

Returns:

  • (Array<String>)

    Model attributes



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mobility/active_record/attribute_methods.rb', line 15

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

Instance Method Details

#attributesArray<String>

Adds translated attributes to attributes.

Returns:

  • (Array<String>)

    Model attributes



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mobility/active_record/attribute_methods.rb', line 15

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_attributesArray<String>

Translated attributes defined on model.

Returns:

  • (Array<String>)

    Translated attributes



29
30
31
32
33
# File 'lib/mobility/active_record/attribute_methods.rb', line 29

def translated_attributes
  translated_attribute_names.inject({}) do |attributes, name|
    attributes.merge(name.to_s => send(name))
  end
end