Module: Surrealist::Wrapper

Defined in:
lib/surrealist/wrapper.rb

Overview

A helper class for wrapping hashes.

Class Method Summary collapse

Class Method Details

.wrap(hash, carrier, klass = false) ⇒ Hash

Wraps the schema hash into root/namespaces if there is a need to.

Parameters:

  • hash (Object)

    to be wrapped.

  • carrier (Object)

    instance of Carrier class that carries arguments passed to surrealize

  • klass (String) (defaults to: false)

    instance's class name.

Returns:

  • (Hash)

    a wrapped hash.


14
15
16
17
18
19
20
21
22
# File 'lib/surrealist/wrapper.rb', line 14

def wrap(hash, carrier, klass = false)
  namespaces_condition = carrier.include_namespaces || carrier.namespaces_nesting_level != DEFAULT_NESTING_LEVEL # rubocop:disable Metrics/LineLength

  if !klass && (carrier.include_root || namespaces_condition)
    Surrealist::ExceptionRaiser.raise_unknown_root!
  end

  possibly_wrapped_hash(hash, klass, carrier, namespaces_condition)
end