Method: Mongo::Options::Mapper#transform

Defined in:
lib/mongo/options/mapper.rb

#transform(options, mappings) ⇒ Hash

Transforms the provided options to a new set of options given the provided mapping.

Options which are not present in the provided mapping are returned unmodified.

Examples:

Transform the options.

Mapper.transform({ name: 1 }, { :name => :nombre })

Parameters:

  • options (Hash)

    The options to transform

  • mappings (Hash)

    The key mappings.

Returns:

  • (Hash)

    The transformed options.

Since:

  • 2.0.0



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/mongo/options/mapper.rb', line 42

def transform(options, mappings)
  map = transform_keys_to_strings(mappings)
  opts = transform_keys_to_strings(options)
  opts.reduce({}) do |transformed, (key, value)|
    if map[key]
      transformed[map[key]] = value
    else
      transformed[key] = value
    end
    transformed
  end
end