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
-
.[](url) ⇒ Nil, WeaselDiesel
deprecated
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.
-
.add(service) ⇒ Array<WeaselDiesel>
Add a service to the array tracking the playco services.
-
.all ⇒ Array<WeaselDiesel>
Returns an array of services.
-
.find(verb, url) ⇒ Nil, WeaselDiesel
Returns a service based on its verb and url.
- .named(name) ⇒ WeaselDiesel deprecated Deprecated.
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
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
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 |
.all ⇒ Array<WeaselDiesel>
Returns an array of services
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
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
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 |