Class: Restful::Configuration::WebService
- Inherits:
-
Configurator
- Object
- Configurator
- Restful::Configuration::WebService
- Defined in:
- lib/restful/configuration.rb
Overview
Configuration object for one web service.
Options
-
:name => the name of the web service
-
:api_prefix => used to supply a prefix to generated name_route methods if method names cannot be inferred purely by resource class names.
A web service for Reservation might prefix with :guest_api, so the named routes would
be +guest_api_reservations_url+ rather than reservations_url, which might instead
return a path for accessing a Reservation through an HTML interface (perhaps through
a separate controller...)
-
:default_url_options => ActionController::UrlWriter requires a hash of default url options (notable { :host => ‘foo.com’ }). This can be set per WebService and globally via Restful.default_url_options.
Resources
Resources configurations are set with a call to register_resource
.
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ WebService
constructor
A new instance of WebService.
-
#register_resource(name, options = {}, &block) ⇒ Object
Adds a Restful::Configuration::Resource.
-
#resource_configuration_for(resource_key) ⇒ Object
Returns a deep clone of the requested resource looked up by the passed key.
Methods included from Configurable
#==, #deep_clone, #deeper_merge!, #explicitly_set?, #find_option, #hash, included, #option_names, #reset, #set, #to_hash
Constructor Details
#initialize(name, options = {}) ⇒ WebService
Returns a new instance of WebService.
319 320 321 |
# File 'lib/restful/configuration.rb', line 319 def initialize(name, = {}) super(.merge(:name => name)) end |
Instance Method Details
#register_resource(name, options = {}, &block) ⇒ Object
Adds a Restful::Configuration::Resource.
324 325 326 |
# File 'lib/restful/configuration.rb', line 324 def register_resource(name, = {}, &block) resources[name] = Resource.register(, &block) end |
#resource_configuration_for(resource_key) ⇒ Object
Returns a deep clone of the requested resource looked up by the passed key. Key may be a symbol, string, Class or instance of Class of the resource.
330 331 332 333 334 335 336 337 338 339 340 341 342 |
# File 'lib/restful/configuration.rb', line 330 def resource_configuration_for(resource_key) resource = case resource_key when Symbol resources[resource_key] when String resources[resource_key.to_sym] when Class resources[resource_key.name.underscore.to_sym] else resources[resource_key.class.name.underscore.to_sym] end return resource.nil? ? nil : resource.deep_clone end |