Method: Chewy::Type::Import::ClassMethods#compose

Defined in:
lib/chewy/type/import.rb

#compose(object, crutches = nil, fields: []) ⇒ Hash

Composes a single document from the passed object. Uses either witchcraft or normal composing under the hood.

Parameters:

  • object (Object)

    a data source object

  • crutches (Object) (defaults to: nil)

    optional crutches object; if ommited - a crutch for the single passed object is created as a fallback

  • fields (Array<Symbol>) (defaults to: [])

    and array of fields to restrict the generated document

Returns:

  • (Hash)

    a JSON-ready hash



116
117
118
119
120
121
122
123
124
# File 'lib/chewy/type/import.rb', line 116

def compose(object, crutches = nil, fields: [])
  crutches ||= Chewy::Type::Crutch::Crutches.new self, [object]

  if witchcraft? && root.children.present?
    cauldron(fields: fields).brew(object, crutches)
  else
    root.compose(object, crutches, fields: fields)
  end
end