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(controller) ⇒ void

Method used to initialize the instance of object

Parameters:

  • controller (String)

    The name of the controller that acts like a soap service

See Also:



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

#configWashOut::SoapConfig

Returns holds the soap configuration for the soap service.

Returns:

  • (WashOut::SoapConfig)

    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_nameString

Returns The name of the controller that acts like a soap service.

Returns:

  • (String)

    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_actionsHash

Returns Hash that contains all the actions to which the web service responds to and information about them.

Returns:

  • (Hash)

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

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

Returns:

  • (Array<String>)

    Returns an array with all the names of all operations that can raise an exception 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_namesArray<String>

Returns the names of all operations sorted alphabetically

Returns:

  • (Array<String>)

    An array with all 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

Parameters:

  • type (String)

    The type of the arguments that need to be returned (“input” or anything else )

Returns:

  • (Array<WashOutParam>, Array<Error>)

    If the argument is “input” will return the arguments of the operation , ottherwise the return type



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

Returns an array with all the complex types sorted alphabetically

Returns:

  • (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

Parameters:

  • controller (String)

    The name of the controller

Returns:

  • (Class)

    Returns the class of the controller



44
45
46
# File 'lib/washout_builder/document/generator.rb', line 44

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

#endpointString

Retrieves the endpoint of the soap service based on its namespace

Returns:

  • (String)

    Returns the current soap service’s endpoint based on its namespace

See Also:



53
54
55
# File 'lib/washout_builder/document/generator.rb', line 53

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

#exceptions_raisedArray<Class>

Returns all the exception raised by all operations

Returns:

  • (Array<Class>)

    Returns an array with all the exception classes that are raised by all operations

See Also:



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

Returns all the exception classes raised by all operations sorted alphabetically

Returns:

  • (Array<Class>)

    Returns all the exception classes that can be raised by all operations with their ancestors also sorted alphabetically

See Also:



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

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

Returns:

  • (Array<Class>)

    returns the exceptions that are raised by all operations filtering only the ones that inherit from WashOut::SoapError

See Also:



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

Parameters:

  • base_fault_array (Array<Class>)

    An array with the base exception classes from which we try to identify their ancestors

Returns:

  • (Array)

    Class>] Returns all the exception classes that can be raised by all operations with their ancestors also

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

Returns the arguments of all operations

Returns:

  • (Array<WashOut::Param>)

    An array with all the arguments types of all operations the service responds to

See Also:



136
137
138
# File 'lib/washout_builder/document/generator.rb', line 136

def input_types
  argument_types('input')
end

#namespaceString

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

Returns:

  • (String)

    description of returned object



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

Parameters:

  • operation_name (String)

    describe operation_name

Returns:

  • (Array<Class>)

    returns an array with all the exception classes that the operation send as argument 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

#operationsArray<String>

returns a collection of all operation that the service responds to

Returns:

  • (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_typesArray<Error>

Returns the arguments of all operations

Returns:

  • (Array<Error>)

    An array with all the exceptions that all operations can raise

See Also:



144
145
146
# File 'lib/washout_builder/document/generator.rb', line 144

def output_types
  argument_types('output')
end

#serviceString

Returns the service name using camelcase letter

Returns:

  • (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_descriptionString

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

Returns:

  • (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

Parameters:

  • types (Hash)

    Any kind of hash @option types [String, Symbol] :type The name of the key should be the same as the second argument

  • type (String, Symbol)

    The key that is used for sorting alphabetically

Returns:

  • (Hash)

    options Same hash sorted alphabetically by the specified key and without duplicates @option options [String, Symbol] :type The name of the key should be the same as the second argument



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

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

Returns:

  • (Array<String>)

    returns a collection of all operation that the service responds to sorted alphabetically



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