Class: WashoutBuilder::Document::Generator
- Inherits:
-
Object
- Object
- WashoutBuilder::Document::Generator
- Defined in:
- lib/washout_builder/document/generator.rb
Overview
class that is used to generate HTML documentation for a soap service
Instance Attribute Summary collapse
-
#config ⇒ WashOut::SoapConfig
Holds the soap configuration for the soap service.
-
#controller_name ⇒ String
The name of the controller that acts like a soap service.
-
#soap_actions ⇒ Hash
Hash that contains all the actions to which the web service responds to and information about them.
Instance Method Summary collapse
-
#actions_with_exceptions ⇒ Array<String>
Returns an array with all the operations that can raise an exception at least or more.
-
#all_soap_action_names ⇒ Array<String>
Returns the names of all operations sorted alphabetically.
-
#argument_types(type) ⇒ Array<WashOutParam>, Array<Error>
Returns either the input arguments of a operation or the output types of that operation depending on the argument.
-
#complex_types ⇒ Array<WashOut::Param>
Returns an array with all the complex types sorted alphabetically.
-
#controller_class(controller) ⇒ Class
Retrives the class of the controller by using its name.
-
#endpoint ⇒ String
Retrieves the endpoint of the soap service based on its namespace.
-
#exceptions_raised ⇒ Array<Class>
Returns all the exception raised by all operations.
-
#fault_types ⇒ Array<Class>
Returns all the exception classes raised by all operations sorted alphabetically.
-
#filter_exceptions_raised ⇒ Array<Class>
Fiters the exceptions raised by checking if they classes inherit from WashOout::SoapError.
-
#get_complex_fault_types(base_fault_array) ⇒ Array
Retuens all the exception classes that can be raised by all operations with their ancestors also.
-
#initialize(controller) ⇒ void
constructor
Method used to initialize the instance of object.
-
#input_types ⇒ Array<WashOut::Param>
Returns the arguments of all operations.
-
#namespace ⇒ String
Returns the namespace used for the controller by using the soap configuration of the controller.
-
#operation_exceptions(operation_name) ⇒ Array<Class>
Returns the exceptions that a specific operation can raise.
-
#operations ⇒ Array<String>
returns a collection of all operation that the service responds to.
-
#output_types ⇒ Array<Error>
Returns the arguments of all operations.
-
#service ⇒ String
Returns the service name using camelcase letter.
-
#service_description ⇒ String
Returns the service description if the service can respond to description method.
-
#sort_complex_types(types, type) ⇒ Hash
Sorts a hash by a key alphabetically.
-
#sorted_operations ⇒ Array<String>
returns the operations of a service by sorting them alphabetically and removes duplicates.
Constructor Details
#initialize(controller) ⇒ void
Method used to initialize the instance of object
24 25 26 27 28 29 |
# File 'lib/washout_builder/document/generator.rb', line 24 def initialize(controller) controller_class_name = controller_class(controller) self.config = controller_class_name.soap_config self.soap_actions = controller_class_name.soap_actions self.controller_name = controller end |
Instance Attribute Details
#config ⇒ WashOut::SoapConfig
Returns holds the soap configuration for the soap service.
16 |
# File 'lib/washout_builder/document/generator.rb', line 16 attr_accessor :soap_actions, :config, :controller_name |
#controller_name ⇒ String
Returns The name of the controller that acts like a soap service.
16 |
# File 'lib/washout_builder/document/generator.rb', line 16 attr_accessor :soap_actions, :config, :controller_name |
#soap_actions ⇒ Hash
Returns Hash that contains all the actions to which the web service responds to and information about them.
16 17 18 |
# File 'lib/washout_builder/document/generator.rb', line 16 def soap_actions @soap_actions end |
Instance Method Details
#actions_with_exceptions ⇒ Array<String>
Returns an array with all the operations that can raise an exception at least or more
173 174 175 |
# File 'lib/washout_builder/document/generator.rb', line 173 def actions_with_exceptions soap_actions.select { |_operation, formats| !formats[:raises].blank? } end |
#all_soap_action_names ⇒ Array<String>
Returns the names of all operations sorted alphabetically
152 153 154 |
# File 'lib/washout_builder/document/generator.rb', line 152 def all_soap_action_names operations.map(&:to_s).sort_by(&:downcase).uniq unless soap_actions.blank? end |
#argument_types(type) ⇒ Array<WashOutParam>, Array<Error>
Returns either the input arguments of a operation or the output types of that operation depending on the argument
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/washout_builder/document/generator.rb', line 119 def argument_types(type) format_type = (type == 'input') ? 'builder_in' : 'builder_out' types = [] unless soap_actions.blank? soap_actions.each do |_operation, formats| (formats[format_type.to_sym]).each do |p| types << p end end end types end |
#complex_types ⇒ Array<WashOut::Param>
Returns an array with all the complex types sorted alphabetically
161 162 163 164 165 166 167 |
# File 'lib/washout_builder/document/generator.rb', line 161 def complex_types defined = [] (input_types + output_types).each do |p| defined.concat(p.get_nested_complex_types(config, defined)) end defined = sort_complex_types(defined, 'class') end |
#controller_class(controller) ⇒ Class
Retrives the class of the controller by using its name
44 45 46 |
# File 'lib/washout_builder/document/generator.rb', line 44 def controller_class(controller) "#{controller}_controller".camelize.constantize end |
#endpoint ⇒ String
Retrieves the endpoint of the soap service based on its namespace
53 54 55 |
# File 'lib/washout_builder/document/generator.rb', line 53 def endpoint namespace.blank? ? nil : namespace.gsub('/wsdl', '/action') end |
#exceptions_raised ⇒ Array<Class>
Returns all the exception raised by all operations
182 183 184 |
# File 'lib/washout_builder/document/generator.rb', line 182 def exceptions_raised actions_with_exceptions.map { |_operation, formats| formats[:raises].is_a?(Array) ? formats[:raises] : [formats[:raises]] }.flatten end |
#fault_types ⇒ Array<Class>
Returns all the exception classes raised by all operations sorted alphabetically
216 217 218 219 220 |
# File 'lib/washout_builder/document/generator.rb', line 216 def fault_types base_fault = [WashoutBuilder::Type.all_fault_classes.first] fault_types = get_complex_fault_types(base_fault) sort_complex_types(fault_types, 'fault') end |
#filter_exceptions_raised ⇒ Array<Class>
Fiters the exceptions raised by checking if they classes inherit from WashOout::SoapError
190 191 192 |
# File 'lib/washout_builder/document/generator.rb', line 190 def filter_exceptions_raised exceptions_raised.select { |x| WashoutBuilder::Type.valid_fault_class?(x) } unless actions_with_exceptions.blank? end |
#get_complex_fault_types(base_fault_array) ⇒ Array
Retuens all the exception classes that can be raised by all operations with their ancestors also
201 202 203 204 205 206 207 |
# File 'lib/washout_builder/document/generator.rb', line 201 def get_complex_fault_types(base_fault_array) fault_types = [] defined = filter_exceptions_raised defined = defined.blank? ? base_fault_array : defined.concat(base_fault_array) defined.each { |exception_class| exception_class.get_fault_class_ancestors(fault_types, true) } unless defined.blank? fault_types end |
#input_types ⇒ Array<WashOut::Param>
Returns the arguments of all operations
136 137 138 |
# File 'lib/washout_builder/document/generator.rb', line 136 def input_types argument_types('input') end |
#namespace ⇒ String
Returns the namespace used for the controller by using the soap configuration of the controller
35 36 37 |
# File 'lib/washout_builder/document/generator.rb', line 35 def namespace config.respond_to?(:namespace) ? config.namespace : nil end |
#operation_exceptions(operation_name) ⇒ Array<Class>
Returns the exceptions that a specific operation can raise
94 95 96 97 98 99 100 |
# File 'lib/washout_builder/document/generator.rb', line 94 def operation_exceptions(operation_name) hash_object = soap_actions.find { |operation, _formats| operation.to_s.downcase == operation_name.to_s.downcase } return if hash_object.blank? faults = hash_object[1][:raises] faults = faults.is_a?(Array) ? faults : [faults] faults.select { |x| WashoutBuilder::Type.valid_fault_class?(x) } end |
#operations ⇒ Array<String>
returns a collection of all operation that the service responds to
77 78 79 |
# File 'lib/washout_builder/document/generator.rb', line 77 def operations soap_actions.map { |operation, _formats| operation } end |
#output_types ⇒ Array<Error>
Returns the arguments of all operations
144 145 146 |
# File 'lib/washout_builder/document/generator.rb', line 144 def output_types argument_types('output') end |
#service ⇒ String
Returns the service name using camelcase letter
61 62 63 |
# File 'lib/washout_builder/document/generator.rb', line 61 def service controller_name.blank? ? nil : controller_name.camelize end |
#service_description ⇒ String
Returns the service description if the service can respond to description method
69 70 71 |
# File 'lib/washout_builder/document/generator.rb', line 69 def service_description config.respond_to?(:description) ? config.description : nil end |
#sort_complex_types(types, type) ⇒ Hash
Sorts a hash by a key alphabetically
110 111 112 |
# File 'lib/washout_builder/document/generator.rb', line 110 def sort_complex_types(types, type) types.sort_by { |hash| hash[type.to_sym].to_s.downcase }.uniq { |hash| hash[type.to_sym] } unless types.blank? end |
#sorted_operations ⇒ Array<String>
returns the operations of a service by sorting them alphabetically and removes duplicates
85 86 87 |
# File 'lib/washout_builder/document/generator.rb', line 85 def sorted_operations soap_actions.sort_by { |operation, _formats| operation.downcase }.uniq unless soap_actions.blank? end |