Module: WSList

Defined in:
lib/ws_list.rb

Overview

Wrapper module to keep track of all defined services

Defined Under Namespace

Classes: DuplicateServiceDescription, UnknownService

Class Method Summary collapse

Class Method Details

.[](url) ⇒ Nil, WeaselDiesel

Deprecated.

use #find instead since this method doesn’t support a verb being passed and the url might or might not match depending on the leading slash.

Returns a service based on its url

Parameters:

  • url (String)

    The url of the service you are looking for.

Returns:



60
61
62
# File 'lib/ws_list.rb', line 60

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

.add(service) ⇒ Array<WeaselDiesel>

Add a service to the array tracking the playco services

Parameters:

Returns:

Raises:

  • DuplicateServiceDescription If a service is being duplicated.



18
19
20
21
22
23
24
25
# File 'lib/ws_list.rb', line 18

def add(service)
  @list ||= []
  if WSList.find(service.verb, service.url)
    raise DuplicateServiceDescription, "A service accessible via #{service.verb} #{service.url} already exists"
  end
  @list << service
  @list
end

.allArray<WeaselDiesel>

Returns an array of services

Returns:



31
32
33
# File 'lib/ws_list.rb', line 31

def all
  @list || []
end

.find(verb, url) ⇒ Nil, WeaselDiesel

Returns a service based on its verb and url

Parameters:

  • verb (String)

    The request method (GET, POST, PUT, DELETE)

  • url (String)

    The url of the service you are looking for.

Returns:



71
72
73
74
75
# File 'lib/ws_list.rb', line 71

def find(verb, url)
  verb = verb.to_s.downcase.to_sym
  slashed_url = url.start_with?('/') ? url : "/#{url}"
  @list.find{|service| service.verb == verb && service.url == slashed_url}
end

.named(name) ⇒ WeaselDiesel

Deprecated.

Returns a service based on its name

Parameters:

  • name (String)

    The name of the service you are looking for.

Returns:

Raises:

  • (UnknownService)

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



43
44
45
46
47
48
49
50
# File 'lib/ws_list.rb', line 43

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