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



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

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

Instance Attribute Details

#code_nameString



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

def code_name
  @code_name
end

#glossaryGlossary



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

def glossary
  @glossary
end

#messagesHash<String, Message>



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

def messages
  @messages
end

#nameString



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

def name
  @name
end

#operationsSet<Operation>



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

def operations
  @operations
end

#proxy_operationsSet<ProxyOperation>



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

def proxy_operations
  @proxy_operations
end

#representationsSet<Representation>



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

def representations
  @representations
end

#versionString



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.


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

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.



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

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.



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

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.



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

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}
}


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

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