Class: Mobility::Plugins::ActiveRecord::AttributeMethods

Inherits:
Module
  • Object
show all
Defined in:
lib/mobility/plugins/active_record/attribute_methods.rb

Overview

Module builder adding translated attributes to #attributes hash on model instance. See Mobility::Plugins::AttributeMethods for further details.

Instance Method Summary collapse

Constructor Details

#initialize(*attribute_names) ⇒ AttributeMethods

Returns a new instance of AttributeMethods.


21
22
23
24
25
26
27
28
# File 'lib/mobility/plugins/active_record/attribute_methods.rb', line 21

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
end

Instance Method Details

#included(model_class) ⇒ Object


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

def included(model_class)
  model_class.class_eval do
    define_method :untranslated_attributes, ::ActiveRecord::Base.instance_method(:attributes)
  end
end