Module: Angus::SDoc::DefinitionsUtils

Defined in:
lib/angus/definitions_utils.rb

Class Method Summary collapse

Class Method Details

.include_representation(name, representations, into) ⇒ Object

Note:

The purpose of this method is to be used as an utility method from a method which selects a subset of representations.

Inserts a representation and its children into a destination.

Parameters:

  • name (String)

    The representation name.

  • representations (Hash)

    The source of the representations.

  • into (Hash)

    the destination hash.



60
61
62
63
64
65
66
67
68
# File 'lib/angus/definitions_utils.rb', line 60

def self.include_representation(name, representations, into)
  if representation = representations[name]
    into[name] = representation
    representation.each do |field|
      field_type = field['type'] || field['elements_type']
      include_representation(field_type, representations, into)
    end
  end
end

.slice(definition, operation_names) ⇒ Hash

TODO:

Explain better this method. Needs refactor?

Builds a new definition hash based on the given operation names.

Parameters:

  • definition (Hash)

    The service definition.

  • operation_names (Array<String>)

    The names of the operations.

Returns:

  • (Hash)

    the definition.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/angus/definitions_utils.rb', line 12

def self.slice(definition, operation_names)
  result = {
    :operations => {},
    :representations => {},
    :messages => {}
  }

  result[:service] = definition['service']

  representations = Set.new
  messages = Set.new

  definition['operations'].each do |code_name, operation|
    if operation_names.include?(code_name)
      result[:operations][code_name] = operation

      types = (operation['response'] || []).map do |element|
        element['type'] || element['elements_type']
      end

      representations += types

      messages += (operation['messages'] || []).map do |message|
        message['key']
      end

    end
  end

  representations.each do |name|
    include_representation(name, definition['representations'], result[:representations])
  end

  messages.each do |key|
    result[:messages][key] = definition['messages'][key]
  end

  result
end