Class: WashoutBuilder::Document::Generator

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(route_details, controller) ⇒ void

Method used to initialize the instance of object

See Also:


24
25
26
27
28
29
30
# File 'lib/washout_builder/document/generator.rb', line 24

def initialize(route_details, controller)
  self.route_details = route_details
  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

#configWashOut::SoapConfig


16
# File 'lib/washout_builder/document/generator.rb', line 16

attr_accessor :soap_actions, :config, :controller_name, :route_details

#controller_nameString


16
# File 'lib/washout_builder/document/generator.rb', line 16

attr_accessor :soap_actions, :config, :controller_name, :route_details

#route_detailsObject

class that is used to generate HTML documentation for a soap service


16
17
18
# File 'lib/washout_builder/document/generator.rb', line 16

def route_details
  @route_details
end

#soap_actionsHash


16
17
18
# File 'lib/washout_builder/document/generator.rb', line 16

def soap_actions
  @soap_actions
end

Instance Method Details

#actions_with_exceptionsArray<String>

Returns an array with all the operations that can raise an exception at least or more


178
179
180
# File 'lib/washout_builder/document/generator.rb', line 178

def actions_with_exceptions
  soap_actions.select { |_operation, formats| !formats[:raises].blank? }
end

#all_soap_action_namesArray<String>

Returns the names of all operations sorted alphabetically


157
158
159
# File 'lib/washout_builder/document/generator.rb', line 157

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


124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/washout_builder/document/generator.rb', line 124

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_typesArray<WashOut::Param>

Returns an array with all the complex types sorted alphabetically


166
167
168
169
170
171
172
# File 'lib/washout_builder/document/generator.rb', line 166

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


49
50
51
# File 'lib/washout_builder/document/generator.rb', line 49

def controller_class(controller)
  "#{controller}_controller".camelize.constantize
end

#controller_route_helpersObject


32
33
34
# File 'lib/washout_builder/document/generator.rb', line 32

def controller_route_helpers
  route_details[:route_set].url_helpers
end

#endpointString

Retrieves the endpoint of the soap service based on its namespace

See Also:


58
59
60
# File 'lib/washout_builder/document/generator.rb', line 58

def endpoint
  namespace.blank? ? nil : namespace.gsub('/wsdl', '/action')
end

#exceptions_raisedArray<Class>

Returns all the exception raised by all operations


187
188
189
# File 'lib/washout_builder/document/generator.rb', line 187

def exceptions_raised
  actions_with_exceptions.map { |_operation, formats| formats[:raises].is_a?(Array) ? formats[:raises] : [formats[:raises]] }.flatten
end

#fault_typesArray<Class>

Returns all the exception classes raised by all operations sorted alphabetically

See Also:


221
222
223
224
225
# File 'lib/washout_builder/document/generator.rb', line 221

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_raisedArray<Class>

Fiters the exceptions raised by checking if they classes inherit from WashOout::SoapError

See Also:


195
196
197
# File 'lib/washout_builder/document/generator.rb', line 195

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


206
207
208
209
210
211
212
# File 'lib/washout_builder/document/generator.rb', line 206

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_typesArray<WashOut::Param>

Returns the arguments of all operations

See Also:


141
142
143
# File 'lib/washout_builder/document/generator.rb', line 141

def input_types
  argument_types('input')
end

#namespaceString

Returns the namespace used for the controller by using the soap configuration of the controller


40
41
42
# File 'lib/washout_builder/document/generator.rb', line 40

def namespace
  controller_route_helpers.url_for(controller: controller_name, action: "_generate_wsdl", only_path: true)
end

#operation_exceptions(operation_name) ⇒ Array<Class>

Returns the exceptions that a specific operation can raise


99
100
101
102
103
104
105
# File 'lib/washout_builder/document/generator.rb', line 99

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

#operationsArray<String>

returns a collection of all operation that the service responds to


82
83
84
# File 'lib/washout_builder/document/generator.rb', line 82

def operations
  soap_actions.map { |operation, _formats| operation }
end

#output_typesArray<Error>

Returns the arguments of all operations

See Also:


149
150
151
# File 'lib/washout_builder/document/generator.rb', line 149

def output_types
  argument_types('output')
end

#serviceString

Returns the service name using camelcase letter


66
67
68
# File 'lib/washout_builder/document/generator.rb', line 66

def service
  controller_name.blank? ? nil : controller_name.camelize
end

#service_descriptionString

Returns the service description if the service can respond to description method


74
75
76
# File 'lib/washout_builder/document/generator.rb', line 74

def service_description
  config.respond_to?(:description) ? config.description : nil
end

#sort_complex_types(types, type) ⇒ Hash

Sorts a hash by a key alphabetically


115
116
117
# File 'lib/washout_builder/document/generator.rb', line 115

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_operationsArray<String>

returns the operations of a service by sorting them alphabetically and removes duplicates


90
91
92
# File 'lib/washout_builder/document/generator.rb', line 90

def sorted_operations
  soap_actions.sort_by { |operation, _formats| operation.downcase }.uniq unless soap_actions.blank?
end