Class: Angus::SDoc::Definitions::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/angus/definitions/service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeService

Returns a new instance of Service.



38
39
40
41
42
43
44
# File 'lib/angus/definitions/service.rb', line 38

def initialize
  @messages = {}
  @operations = Set.new
  @proxy_operations = Set.new
  @representations = Set.new
  @glossary = Angus::SDoc::Definitions::Glossary.new
end

Instance Attribute Details

#code_nameString

Returns the service code name is a unique identifier. It has to be human-readable and a valid literal identifier.

Returns:

  • (String)

    the service code name is a unique identifier. It has to be human-readable and a valid literal identifier.



12
13
14
# File 'lib/angus/definitions/service.rb', line 12

def code_name
  @code_name
end

#glossaryGlossary

Returns the glossary of the service.

Returns:

  • (Glossary)

    the glossary of the service.



36
37
38
# File 'lib/angus/definitions/service.rb', line 36

def glossary
  @glossary
end

#messagesHash<String, Message>

Returns the messages associated with the service.

Returns:

  • (Hash<String, Message>)

    the messages associated with the service.



20
21
22
# File 'lib/angus/definitions/service.rb', line 20

def messages
  @messages
end

#nameString

Returns the name of the service.

Returns:

  • (String)

    the name of the service.



7
8
9
# File 'lib/angus/definitions/service.rb', line 7

def name
  @name
end

#operationsSet<Operation>

Returns the operations of the service.

Returns:

  • (Set<Operation>)

    the operations of the service.



24
25
26
# File 'lib/angus/definitions/service.rb', line 24

def operations
  @operations
end

#proxy_operationsSet<ProxyOperation>

Returns the proxy operations of the service.

Returns:



28
29
30
# File 'lib/angus/definitions/service.rb', line 28

def proxy_operations
  @proxy_operations
end

#representationsSet<Representation>

Returns the representations of the service.

Returns:



32
33
34
# File 'lib/angus/definitions/service.rb', line 32

def representations
  @representations
end

#versionString

Returns the version of the service.

Returns:

  • (String)

    the version of the service.



16
17
18
# File 'lib/angus/definitions/service.rb', line 16

def version
  @version
end

Instance Method Details

#merge(other) ⇒ Object

Note:

This method does not merge glossary terms.

Merge the following definitions:

- Operations.
- Representations.
- Messages.

Parameters:

  • other (Service)

    The service to be merged.



72
73
74
75
76
77
# File 'lib/angus/definitions/service.rb', line 72

def merge(other)
  self.operations.merge!(other.operations)
  self.representations += other.representations

  self.messages.merge!(other.messages)
end

#message(key, level = nil) ⇒ Message

Returns the message that matches the given key and level.

This method searches for messages in all the operations and returns the first message that matches.

Parameters:

  • key (#to_s)

    The key of the message.

  • level (String) (defaults to: nil)

    The level of the message Possible values are the *_LEVEL constants from Message

Returns:

  • (Message)

    the message or nil if no one matches.



56
57
58
59
60
61
62
# File 'lib/angus/definitions/service.rb', line 56

def message(key, level = nil)
  message = self.messages.find do |message_key, message|
    message_key == key && (!level || message.level.downcase == level)
  end

  message.last if message
end

#operation_definition(namespace, operation_code_name) ⇒ Operation

Returns the operation definition that matches with the given operation name.

Parameters:

  • operation_code_name

    The operation code name.

Returns:



84
85
86
# File 'lib/angus/definitions/service.rb', line 84

def operation_definition(namespace, operation_code_name)
  @operations[namespace].find { |operation| operation.code_name == operation_code_name }
end

#proxy_operations_for(service) ⇒ Array<ProxyOperation>

TODO:

Does it receives the service or the service name?

TODO:

Verify if this method is being called by remote-client and if it receives the service name.

Returns the proxy operations for a given service.

Parameters:

  • service

    The service name.

Returns:



94
95
96
97
98
# File 'lib/angus/definitions/service.rb', line 94

def proxy_operations_for(service)
  self.proxy_operations.select do |op|
    op.service_name == service
  end
end

#representations_hashHash<String, Representation>

Returns a hash with the representations.

Examples:

{
  key => rollback_payment_multi,
  value => {representation}
}

Returns:



107
108
109
110
111
112
113
# File 'lib/angus/definitions/service.rb', line 107

def representations_hash
  hash = {}
  @representations.each do |representation|
    hash[representation.name] = representation
  end
  hash
end