-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
154 additions
and
64 deletions.
There are no files selected for viewing
89 changes: 66 additions & 23 deletions
89
app/controllers/washout_builder/washout_builder_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,77 @@ | ||
require_relative "../../../lib/washout_builder/document/generator" | ||
class WashoutBuilder::WashoutBuilderController < ActionController::Base | ||
protect_from_forgery | ||
|
||
def all | ||
# get a list of unique controller names | ||
controllers = Rails.application.routes.routes.map do |route| | ||
if route.defaults[:action] == "_generate_doc" | ||
{:class => "#{route.defaults[:controller]}_controller".camelize.constantize, :name => route.defaults[:controller] } | ||
end | ||
end.uniq.compact | ||
|
||
@services = [] | ||
unless controllers.blank? | ||
controllers.map do |hash| | ||
namespace = hash[:class].soap_config.namespace | ||
@services << { | ||
'service_name' => hash[:class].to_s.underscore.gsub("_controller", "").camelize , | ||
'namespace' => namespace, | ||
'endpoint' => namespace.gsub("/wsdl", "/action"), | ||
'documentation_url' => "#{request.protocol}#{request.host_with_port}/#{hash[:name]}/doc", | ||
} | ||
end | ||
route = params[:name].present? ? controller_is_a_service?(params[:name]) : nil | ||
if route.present? | ||
@document = initialize_service_generator(route) | ||
render :template => "wash_with_html/doc", :layout => false, | ||
:content_type => 'text/html' | ||
else | ||
all_services | ||
end | ||
|
||
|
||
end | ||
|
||
|
||
private | ||
|
||
|
||
def initialize_service_generator(route) | ||
controller_class_name = controller_class(route.defaults[:controller]) | ||
WashoutBuilder::Document::Generator.new( | ||
:config => controller_class_name.soap_config, | ||
:service_class => controller_class_name, | ||
:soap_actions => controller_class_name.soap_actions | ||
) | ||
end | ||
|
||
|
||
def all_services | ||
@map_controllers = map_controllers | ||
@services = @map_controllers.blank? ? [] : @map_controllers.map do |controller_name| | ||
{ | ||
'service_name' => controller_name.camelize , | ||
'namespace' => service_namespace(controller_name), | ||
'endpoint' => service_endpoint(controller_name), | ||
'documentation_url' => service_documentation_url(controller_name), | ||
} | ||
end | ||
|
||
render :template => "wash_with_html/all_services", :layout => false, | ||
:content_type => 'text/html' | ||
|
||
end | ||
|
||
def all_controllers | ||
Rails.application.routes.routes | ||
end | ||
|
||
def map_controllers | ||
all_controllers.map do |route| | ||
route.defaults[:controller] if route.defaults[:action] == "_generate_doc" | ||
end.uniq.compact | ||
end | ||
|
||
def controller_is_a_service?(controller) | ||
route = all_controllers.detect do |route| | ||
route.defaults[:controller].try(:camelize) == controller.camelize && route.defaults[:action] == "_generate_doc" | ||
end | ||
end | ||
|
||
|
||
|
||
def controller_class(controller) | ||
"#{controller}_controller".camelize.constantize | ||
end | ||
|
||
def service_namespace(controller_name) | ||
controller_class(controller_name).soap_config.namespace | ||
end | ||
|
||
def service_endpoint(controller_name) | ||
service_namespace(controller_name).gsub("/wsdl", "/action") | ||
end | ||
|
||
def service_documentation_url(controller_name) | ||
"#{request.protocol}#{request.host_with_port}/#{controller_name}/doc" | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
WashoutBuilder::Engine.routes.draw do | ||
root :to =>"washout_builder#all" | ||
|
||
|
||
match '*name' => "washout_builder#all", :as => :washout_builder_service, :via => :get | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module WashoutBuilder | ||
VERSION = "0.11.5" | ||
VERSION = "0.11.6" | ||
end |