Class: Mongoid::Archivable::ProcessLocalizedFields
- Inherits:
-
Struct
- Object
- Struct
- Mongoid::Archivable::ProcessLocalizedFields
- Defined in:
- lib/mongoid/archivable/process_localized_fields.rb
Overview
loops through all fields on document, as well as on its embedded relations and makes sure all attributes that belong to localized fields are assigned via their *_translations writer
Instance Attribute Summary collapse
-
#attrs ⇒ Object
Returns the value of attribute attrs.
-
#cls ⇒ Object
Returns the value of attribute cls.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(cls, attrs = {}) ⇒ ProcessLocalizedFields
constructor
A new instance of ProcessLocalizedFields.
Constructor Details
#initialize(cls, attrs = {}) ⇒ ProcessLocalizedFields
Returns a new instance of ProcessLocalizedFields.
11 12 13 |
# File 'lib/mongoid/archivable/process_localized_fields.rb', line 11 def initialize(cls, attrs = {}) super(cls, attrs) end |
Instance Attribute Details
#attrs ⇒ Object
Returns the value of attribute attrs
6 7 8 |
# File 'lib/mongoid/archivable/process_localized_fields.rb', line 6 def attrs @attrs end |
#cls ⇒ Object
Returns the value of attribute cls
6 7 8 |
# File 'lib/mongoid/archivable/process_localized_fields.rb', line 6 def cls @cls end |
Class Method Details
.call(*args) ⇒ Object
7 8 9 |
# File 'lib/mongoid/archivable/process_localized_fields.rb', line 7 def self.call(*args) new(*args).call end |
Instance Method Details
#call ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mongoid/archivable/process_localized_fields.rb', line 15 def call attrs = convert_fields .each do |relation| relation_name = relation.name.to_s # convert embeds_many if attrs[relation_name].is_a?(Array) attrs[relation_name] = attrs[relation_name].map do |att| relation_class = Hash[att].fetch('_type', relation.class_name).constantize ProcessLocalizedFields.call(relation_class, Hash[att]) end # convert embeds_one elsif att = attrs[relation_name] relation_class = Hash[att].fetch('_type', relation.class_name).constantize attrs[relation_name] = ProcessLocalizedFields.call(relation_class, Hash[att]) end end attrs end |