Class: Elasticsearch::Model::MongoidExtensions::Localized::ProcessMappings

Inherits:
Struct
  • Object
show all
Defined in:
lib/elasticsearch/model/mongoid_extensions/localized.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clsObject

Returns the value of attribute cls

Returns:

  • (Object)

    the current value of cls



9
10
11
# File 'lib/elasticsearch/model/mongoid_extensions/localized.rb', line 9

def cls
  @cls
end

#mappingObject

Returns the value of attribute mapping

Returns:

  • (Object)

    the current value of mapping



9
10
11
# File 'lib/elasticsearch/model/mongoid_extensions/localized.rb', line 9

def mapping
  @mapping
end

Class Method Details

.call(*args) ⇒ Object



10
11
12
# File 'lib/elasticsearch/model/mongoid_extensions/localized.rb', line 10

def self.call(*args)
  new(*args).call
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/elasticsearch/model/mongoid_extensions/localized.rb', line 14

def call
  mapping.each do |field_name, options|
    next unless field = cls.fields[field_name.to_s] || cls.fields.detect { |_, meta| meta.options[:as] == field_name.to_sym }.try(:last)
    next unless field.localized?
    next if mapping[field_name]&.frozen?
    mapping[field_name] = ::I18n.available_locales.each_with_object({ type: 'object', properties: {} }) do |locale, res|
      res[:properties][locale] = options.dup
    end
    mapping[field_name].freeze
  end
  mapping
end