Module: WSList

Defined in:
lib/ws_list.rb

Overview

Wrapper module to keep track of all defined services

Defined Under Namespace

Classes: UnknownService

Class Method Summary collapse

Class Method Details

.[](url) ⇒ Nil, WSDSL

Returns a service based on its url

Parameters:

  • url (String)

    The url of the service you are looking for.

Returns:

  • (Nil, WSDSL)

    The found service.



52
53
54
# File 'lib/ws_list.rb', line 52

def [](url)
  @list.find{|service| service.url == url}
end

.add(service) ⇒ Array<WSDSL>

Add a service to the array tracking the playco services

Parameters:

  • The (WSDSL)

    service to add.

Returns:

  • (Array<WSDSL>)

    All the added services.



16
17
18
19
20
# File 'lib/ws_list.rb', line 16

def add(service)
  @list ||= []
  @list << service unless @list.find{|s| s.url == service.url && s.verb == service.verb}
  @list
end

.allArray<WSDSL>

Returns an array of services

Returns:

  • (Array<WSDSL>)

    All the added services.



26
27
28
# File 'lib/ws_list.rb', line 26

def all
  @list || []
end

.named(name) ⇒ WSDSL

Returns a service based on its name

Parameters:

  • name (String)

    The name of the service you are looking for.

Returns:

  • (WSDSL)

    The found service.

Raises:

  • (UnknownService)

    if a service with the passed name isn’t found.



37
38
39
40
41
42
43
44
# File 'lib/ws_list.rb', line 37

def named(name)
  service = all.find{|service| service.name == name}
  if service.nil?
    raise UnknownService, "Service named #{name} isn't available"
  else
    service
  end
end