Added web_service generator (run ./script/generate web_service for help) #776 [Leon Bredt]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@851 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 2581806a
Description:
The web service generator creates the controller and API definition for
a web service.
The generator takes a web service name and a list of API methods as arguments.
The web service name may be given in CamelCase or under_score and should
contain no extra suffixes. To create a web service within a
module, specify the web service name as 'module/webservice'.
The generator creates a controller class in app/controllers, an API definition
in app/apis, and a functional test suite in test/functional.
Example:
./script/generate web_service User add edit list remove
User web service.
Controller: app/controllers/user_controller.rb
API: app/apis/user_api.rb
Test: test/functional/user_api_test.rb
Modules Example:
./script/generate web_service 'api/registration' register renew
Registration web service.
Controller: app/controllers/api/registration_controller.rb
API: app/apis/api/registration_api.rb
Test: test/functional/api/registration_api_test.rb
class <%= class_name %>Api < ActionWebService::API::Base
<% for method_name in args -%>
api_method :<%= method_name %>
<% end -%>
end
class <%= class_name %>Controller < ApplicationController
wsdl_service_name '<%= class_name %>'
<% for method_name in args -%>
def <%= method_name %>
end
<% end -%>
end
require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
require '<%= file_path %>_controller'
class <%= class_name %>Controller; def rescue_action(e) raise e end; end
class <%= class_name %>ControllerApiTest < Test::Unit::TestCase
def setup
@controller = <%= class_name %>Controller.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
<% for method_name in args -%>
def test_<%= method_name %>
result = invoke :<%= method_name %>
assert_equal nil, result
end
<% end -%>
end
class WebServiceGenerator < Rails::Generator::NamedBase
def manifest
record do |m|
# Check for class naming collisions.
m.class_collisions class_path, "#{class_name}Api", "#{class_name}Controller", "#{class_name}ApiTest"
# API and test directories.
m.directory File.join('app/apis', class_path)
m.directory File.join('app/controllers', class_path)
m.directory File.join('test/functional', class_path)
# API definition, controller, and functional test.
m.template 'api_definition.rb',
File.join('app/apis',
class_path,
"#{file_name}_api.rb")
m.template 'controller.rb',
File.join('app/controllers',
class_path,
"#{file_name}_controller.rb")
m.template 'functional_test.rb',
File.join('test/functional',
class_path,
"#{file_name}_api_test.rb")
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册