1 module ActionWebService # :nodoc:
2 module Container # :nodoc:
3 module Direct # :nodoc:
4 class ContainerError < ActionWebServiceError # :nodoc:
7 def self.included(base) # :nodoc:
8 base.extend(ClassMethods)
12 # Attaches ActionWebService API +definition+ to the calling class.
14 # Action Controllers can have a default associated API, removing the need
15 # to call this method if you follow the Action Web Service naming conventions.
17 # A controller with a class name of GoogleSearchController will
18 # implicitly load <tt>app/apis/google_search_api.rb</tt>, and expect the
19 # API definition class to be named <tt>GoogleSearchAPI</tt> or
20 # <tt>GoogleSearchApi</tt>.
22 # ==== Service class example
24 # class MyService < ActionWebService::Base
25 # web_service_api MyAPI
28 # class MyAPI < ActionWebService::API::Base
32 # ==== Controller class example
34 # class MyController < ActionController::Base
35 # web_service_api MyAPI
38 # class MyAPI < ActionWebService::API::Base
41 def web_service_api(definition=nil)
43 read_inheritable_attribute("web_service_api")
45 if definition.is_a?(Symbol)
46 raise(ContainerError, "symbols can only be used for #web_service_api inside of a controller")
48 unless definition.respond_to?(:ancestors) && definition.ancestors.include?(ActionWebService::API::Base)
49 raise(ContainerError, "#{definition.to_s} is not a valid API definition")
51 write_inheritable_attribute("web_service_api", definition)
52 call_web_service_api_callbacks(self, definition)
56 def add_web_service_api_callback(&block) # :nodoc:
57 write_inheritable_array("web_service_api_callbacks", [block])
61 def call_web_service_api_callbacks(container_class, definition)
62 (read_inheritable_attribute("web_service_api_callbacks") || []).each do |block|
63 block.call(container_class, definition)