Class: Surrealist::Carrier Private

Inherits:
Object
  • Object
show all
Defined in:
lib/surrealist/carrier.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A data structure to carry arguments across methods.

Constant Summary collapse

BOOLEANS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

[true, false, nil].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Carrier

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Carrier.



28
29
30
31
32
33
34
# File 'lib/surrealist/carrier.rb', line 28

def initialize(**args)
  @camelize                 = args.delete(:camelize) || false
  @include_root             = args.delete(:include_root) || false
  @include_namespaces       = args.delete(:include_namespaces) || false
  @root                     = args.delete(:root) || nil
  @namespaces_nesting_level = args.delete(:namespaces_nesting_level) || DEFAULT_NESTING_LEVEL
end

Instance Attribute Details

#camelizeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/surrealist/carrier.rb', line 9

def camelize
  @camelize
end

#include_namespacesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/surrealist/carrier.rb', line 9

def include_namespaces
  @include_namespaces
end

#include_rootObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/surrealist/carrier.rb', line 9

def include_root
  @include_root
end

#namespaces_nesting_levelObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/surrealist/carrier.rb', line 9

def namespaces_nesting_level
  @namespaces_nesting_level
end

#rootObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



9
10
11
# File 'lib/surrealist/carrier.rb', line 9

def root
  @root
end

Class Method Details

.call(**args) ⇒ Carrier

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Public wrapper for Carrier.

Parameters:

  • camelize (Boolean)

    optional argument for converting hash to camelBack.

  • include_root (Boolean)

    optional argument for having the root key of the resulting hash as instance’s class name.

  • include_namespaces (Boolean)

    optional argument for having root key as a nested hash of instance’s namespaces. Animal::Cat.new.surrealize -> (animal: { cat: { weight: ‘3 kilos’ } })

  • root (String)

    optional argument for using a specified root key for the resulting hash

  • namespaces_nesting_level (Integer)

    level of namespaces nesting.

Returns:

  • (Carrier)

    self if type checks were passed.

Raises:

  • ArgumentError if types of arguments are wrong.



24
25
26
# File 'lib/surrealist/carrier.rb', line 24

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

Instance Method Details

#no_args_provided?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks if all arguments are set to default

Returns:

  • (Boolean)


48
49
50
# File 'lib/surrealist/carrier.rb', line 48

def no_args_provided?
  @no_args_provided ||= no_args_provided
end

#parametersHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns all arguments

Returns:

  • (Hash)


55
56
57
58
# File 'lib/surrealist/carrier.rb', line 55

def parameters
  { camelize: camelize, include_root: include_root, include_namespaces: include_namespaces,
    root: root, namespaces_nesting_level: namespaces_nesting_level }
end

#sanitize!Carrier

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Performs type checks

Returns:

  • (Carrier)

    self if check were passed



39
40
41
42
43
44
45
# File 'lib/surrealist/carrier.rb', line 39

def sanitize!
  check_booleans!
  check_namespaces_nesting!
  check_root!
  strip_root!
  self
end