From fd0b924296fb93b4acba525822e631f18d67815d Mon Sep 17 00:00:00 2001 From: Rada Bogdan Raul Date: Tue, 25 Aug 2015 18:16:09 +0300 Subject: [PATCH 1/3] documentation for complex types --- lib/washout_builder/document/complex_type.rb | 79 ++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/lib/washout_builder/document/complex_type.rb b/lib/washout_builder/document/complex_type.rb index 263f6dc..bd188ec 100644 --- a/lib/washout_builder/document/complex_type.rb +++ b/lib/washout_builder/document/complex_type.rb @@ -49,6 +49,11 @@ def complex_type_ancestors(config, complex_class, defined) classified? ? get_class_ancestors(config, complex_class, defined) : nil end + # iterates through all the elements of the current object + # and constructs a hash that has as keys the element names and as value their type + + # @return [Hash] THe hash that contains information about the structure of the current object as complex type + # @api public def find_param_structure map.each_with_object({}) do|item, memo| memo[item.name] = item.type @@ -56,10 +61,25 @@ def find_param_structure end end + # removes from this current object the elements that are inherited from other objects + # and set the map of the curent object to the new value + # + # @param [Array] keys An array with the keys that need to be removed from current object + # @return [void] + # @api public def remove_type_inheritable_elements(keys) self.map = map.delete_if { |element| keys.include?(element.name) } end + # Dirty hack to fix the first washout param type. + # This only applies if the first complex type is inheriting WashOutType + # its name should be set to its descendant and the map of the current object will be set to its descendant + # @see WashOut::Param#parse_builder_def + # + # @param [WashOut::SoapConfig] config an object that holds the soap configuration + # @param [Class, String] complex_class the name of the complex type either as a string or a class + # @return [void] + # @api public def fix_descendant_wash_out_type(config, complex_class) param_class = begin complex_class.is_a?(Class) ? complex_class : complex_class.constantize @@ -72,6 +92,14 @@ def fix_descendant_wash_out_type(config, complex_class) self.map = descendant.map end + # Method that is used to check if the current object has exactly same structure as one of his ancestors + # if it is true, will return true, otherwise will first remove the inheritated elements from his ancestor and then return false + # @see #find_param_structure + # @see #remove_type_inheritable_elements + # + # @param [WasOut::Param] ancestor The complex type that is used to compare to the current complex type + # @return [Boolean] returns true if both objects have same structure, otherwise will first remove the inheritated elements from his ancestor and then return false + # @api public def same_structure_as_ancestor?(ancestor) param_structure = find_param_structure ancestor_structure = ancestor.find_param_structure @@ -83,6 +111,14 @@ def same_structure_as_ancestor?(ancestor) end end + # Mehod that is used to get the ancestors of the current complex type + # the method will not filter the results by rejecting the classes 'ActiveRecord::Base', 'Object', 'BasicObject', 'WashOut::Type' + # @see WashoutBuilder::Document::SharedComplexType#get_complex_type_ancestors + # + # @param [Class, String] class_name the name of the on object that is used to fetch his ancestors + # @return [Array] Returns an array with all the classes from each the object inherits from but filters the results and removes the classes + # 'ActiveRecord::Base', 'Object', 'BasicObject', 'WashOut::Type' + # @api public def get_ancestors(class_name) param_class = begin class_name.is_a?(Class) ? class_name : class_name.constantize @@ -96,6 +132,14 @@ def get_ancestors(class_name) end end + # Method used to fetch the descendants of the current object + # @see #get_nested_complex_types + # @see WashOutParam#struct? + # + # @param [WashOut::SoapConfig] config an object that holds the soap configuration + # @param [Array] defined An Array with all the complex types that have been detected till now + # @return [Array] An array with all the complex types that + # @api public def complex_type_descendants(config, defined) if struct? c_names = [] @@ -105,6 +149,17 @@ def complex_type_descendants(config, defined) defined end + # Recursive method that tries to identify all the nested descendants of the current object + # @see #find_complex_class_name + # @see #fix_descendant_wash_out_type + # @see #complex_type_hash + # @see #complex_type_ancestors + # @see #complex_type_descendants + # + # @param [WashOut::SoapConfig] config holds the soap configuration + # @param [Array] defined An array with all the complex type structures that have been detected so far + # @return [Array] An array with all the complex type that have been detected while iterating to all the descendants of the current object and also contains the previous ones + # @api public def get_nested_complex_types(config, defined) defined = [] if defined.blank? complex_class = find_complex_class_name(defined) @@ -116,10 +171,23 @@ def get_nested_complex_types(config, defined) defined.sort_by { |hash| hash[:class].to_s.downcase }.uniq unless defined.blank? end + # method that constructs the a hash with the name of the ancestor ( the class name) and as value its elemen structure + # @see WashOut::Type#wash_out_param_map + # + # @param [WashoutType] ancestors The class that inherits from WashoutType + # @return [Hash] A hash that has as a key the class name in downcase letters and as value the mapping of the class attributes + # @api public def ancestor_structure(ancestors) { ancestors[0].to_s.downcase => ancestors[0].wash_out_param_map } end + # Constructs the complex type information wuth its name, with the object itself and his ancestors + # + # @param [Class] class_name The name of the class + # @param [WashOut::Param] object The object itself + # @param [Array] ancestors An array with all the ancestors that the object inherits from + # @return [Hash] A hash with that contains the params sent to the method + # @api public def complex_type_hash(class_name, object, ancestors) { class: class_name, @@ -128,6 +196,17 @@ def complex_type_hash(class_name, object, ancestors) } end + # A recursive method that fetches the ancestors of a given class (that inherits from WashoutType) + # @see #get_ancestors + # @see WashOut::Param#parse_def + # @see #same_structure_as_ancestor? + # @see #complex_type_hash + # + # @param [WashOut::SoapConfig] config holds the soap configuration + # @param [Class] class_name The name of the class that is used for fetching the ancestors + # @param [Array] defined An Array with all the complex types that have been detected so far + # @return [Array] An Array of classes from which the class that is sent as parameter inherits from + # @api public def get_class_ancestors(config, class_name, defined) ancestors = get_ancestors(class_name) return if ancestors.blank? From fb919fb46ba29f0c0529dba6e3fd6b73ee79a5a6 Mon Sep 17 00:00:00 2001 From: Rada Bogdan Raul Date: Tue, 25 Aug 2015 18:58:16 +0300 Subject: [PATCH 2/3] documentation for exception types --- .../document/exception_model.rb | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/lib/washout_builder/document/exception_model.rb b/lib/washout_builder/document/exception_model.rb index e55f3b8..9da37c1 100644 --- a/lib/washout_builder/document/exception_model.rb +++ b/lib/washout_builder/document/exception_model.rb @@ -1,6 +1,7 @@ require_relative './shared_complex_type' module WashoutBuilder module Document + # the class that is used for soap exceptions to build structure and find ancestors and descendants module ExceptionModel extend ActiveSupport::Concern include WashoutBuilder::Document::SharedComplexType @@ -9,6 +10,16 @@ def self.included(base) base.send :include, WashoutBuilder::Document::SharedComplexType end + # A recursive function that retrives all the ancestors of the current exception class + # @see #fault_ancestors + # @see #fault_ancestor_hash + # @see #find_fault_model_structure + # @see #fault_without_inheritable_elements + # + # @param [Array] defined An array that contains all the information about all the exception classes found so far + # @param [Boolean] _debug = false An optional parameter used for debugging purposes + # @return [Array] Array with all the exception classes from which the current exception class inherits from + # @api public def get_fault_class_ancestors(defined, _debug = false) bool_the_same = false ancestors = fault_ancestors @@ -21,22 +32,52 @@ def get_fault_class_ancestors(defined, _debug = false) ancestors unless bool_the_same end + # Removes the inheritable elements from current object that are inherited from the class send as argument + # @see #remove_fault_type_inheritable_elements + # + # @param [Class] ancestors describe ancestors + # @return [Type] description of returned object + # @api public def fault_without_inheritable_elements(ancestors) remove_fault_type_inheritable_elements(ancestors[0].find_fault_model_structure.keys) end + # Retrieves all the ancestors of the current exception class except ActiveRecord::Base', 'Object', 'BasicObject', 'Exception' + # + # @return [Array] Returns an array with all the classes from which the current exception class inherits from + # @api public def fault_ancestors get_complex_type_ancestors(self, ['ActiveRecord::Base', 'Object', 'BasicObject', 'Exception']) end + # constructs the structure of the current exception class by holding the instance, the structure, and its ancestors + # + # @param [Hash] structure A hash that contains the structure of the current exception class (@see #find_fault_model_structure) + # @param [Array] ancestors An array with all the exception classes from which the current object inherits from + # @return [Hash] options The hash that contains information about the current exception class + # @option options [WashoutBuilder::Document::ExceptionModel] :fault The current exception class that extends WashoutBuilder::Document::ExceptionModel + # @option options [Hash]:structure An hash that contains as keys the atribute names and as value the primitive and member type of that attributre + # @option options [Array] :ancestors An array with all the classes from which current class is inheriting from + # @api public def fault_ancestor_hash(structure, ancestors) { fault: self, structure: structure, ancestors: ancestors } end + # Removes the atributes that are send as argument + # @see #find_fault_model_structure + # + # @param [Array] keys The keys that have to be removed from the model structure + # @return [Hash] An hash that contains as keys the atribute names and as value the primitive and member type of that attribute + # @api public def remove_fault_type_inheritable_elements(keys) find_fault_model_structure.delete_if { |key, _value| keys.include?(key) } end + # Dirty hack to determine if a method has both a setter and a getter and not basic method inherited from Object class + # + # @param [String] method The method thats needs to be verified + # @return [Boolean] Returns true if current class responds to the method and has both a setter and a getter for that method and the method is not inherited from Object class + # @api public def check_valid_fault_method?(method) method != :== && method != :! && (instance_methods.include?(:"#{method}=") || @@ -44,6 +85,10 @@ def check_valid_fault_method?(method) ) end + # tries to fins all instance methods that have both a setter and a getter of the curent class + # @see #check_valid_fault_method? + # @return [Array] An array with all the atrributes and instance methods that have both a setter and a getter + # @api public def find_fault_attributes attrs = [] attrs = instance_methods(nil).map do |method| @@ -53,6 +98,11 @@ def find_fault_attributes attrs.concat(%w(message backtrace)) end + # Dirty hack to get the type of an atribute. Considering all other attributes as string type + # + # @param [String] method_name The name of the attribute to use + # @return [String] Returns the type of the attribute , Currently returns "integer" for attribute "code" and "string" for all others + # @api public def get_fault_type_method(method_name) case method_name.to_s.downcase when 'code' @@ -64,6 +114,12 @@ def get_fault_type_method(method_name) end end + # Description of method + # @see #find_fault_attributes + # @see #get_fault_type_method + # + # @return [Hash] An hash that contains as keys the atribute names and as value the primitive and member type of that attribute + # @api public def find_fault_model_structure h = {} find_fault_attributes.each do |method_name| From 4928b00da09261a648ab5b91af6e73b7d5f25fc9 Mon Sep 17 00:00:00 2001 From: Rada Bogdan Raul Date: Tue, 25 Aug 2015 20:27:37 +0300 Subject: [PATCH 3/3] 99 % documentation --- .../washout_builder_fault_type_helper.rb | 1 + ...washout_builder_method_arguments_helper.rb | 1 + .../washout_builder_method_list_helper.rb | 1 + ...shout_builder_method_return_type_helper.rb | 5 +- lib/washout_builder.rb | 2 +- lib/washout_builder/document/generator.rb | 109 ++++++++++++++++++ .../document/shared_complex_type.rb | 6 + lib/washout_builder/engine.rb | 1 + lib/washout_builder/soap.rb | 11 ++ lib/washout_builder/type.rb | 17 +++ lib/washout_builder/version.rb | 12 +- 11 files changed, 161 insertions(+), 5 deletions(-) diff --git a/app/helpers/washout_builder_fault_type_helper.rb b/app/helpers/washout_builder_fault_type_helper.rb index 516b84c..dafe372 100644 --- a/app/helpers/washout_builder_fault_type_helper.rb +++ b/app/helpers/washout_builder_fault_type_helper.rb @@ -1,3 +1,4 @@ +# method that is used to show that a method can raise a exception in HTML documentation module WashoutBuilderFaultTypeHelper # checks if a complex attribute of a complex type SoapFault is array or not # if the attribute is an array will print also the type of the elements contained in the array diff --git a/app/helpers/washout_builder_method_arguments_helper.rb b/app/helpers/washout_builder_method_arguments_helper.rb index 7ad4199..52a67cf 100644 --- a/app/helpers/washout_builder_method_arguments_helper.rb +++ b/app/helpers/washout_builder_method_arguments_helper.rb @@ -1,3 +1,4 @@ +# helper that is used to show the arguments of a method with their types in HTML documentation module WashoutBuilderMethodArgumentsHelper # displays the parameter of a method as argument and determines if the parameter is basic type or complex type # diff --git a/app/helpers/washout_builder_method_list_helper.rb b/app/helpers/washout_builder_method_list_helper.rb index 59c27a6..f65ab7c 100644 --- a/app/helpers/washout_builder_method_list_helper.rb +++ b/app/helpers/washout_builder_method_list_helper.rb @@ -1,3 +1,4 @@ +# helper that is used to list the method's return tyep as a LI element in HTML documentation module WashoutBuilderMethodListHelper # this method will create the return type of the method and check if the type is basic or complex type or array of types # diff --git a/app/helpers/washout_builder_method_return_type_helper.rb b/app/helpers/washout_builder_method_return_type_helper.rb index 3e55a0b..756d680 100644 --- a/app/helpers/washout_builder_method_return_type_helper.rb +++ b/app/helpers/washout_builder_method_return_type_helper.rb @@ -1,3 +1,4 @@ +# helper that is used to create the return types of methods in HTML documentation module WashoutBuilderMethodReturnTypeHelper # this method will print the return type next to the method name # @see WashoutBuilder::Document::ComplexType#find_complex_class_name @@ -30,8 +31,8 @@ def create_html_public_method_return_type(xml, pre, output) # @param [Array] pre The array that contains the html that will be appended to xml # @param [Array] output An array of params that need to be displayed, will check the type of each and will display it accordingly if is complex type or not # @param [Class] complex_class the name of the complex class - - # @return [String] + # + # @return [void] # # @api public def html_public_method_complex_type(pre, output, complex_class) diff --git a/lib/washout_builder.rb b/lib/washout_builder.rb index e51862a..d621331 100644 --- a/lib/washout_builder.rb +++ b/lib/washout_builder.rb @@ -40,7 +40,7 @@ def self.config WashOut::Param.class_eval do def self.parse_builder_def(soap_config, definition) raise '[] should not be used in your params. Use nil if you want to mark empty set.' if definition == [] - return [] if definition.nil? + return [] if definition.blank? # the following lines was removed because when generating the documentation # the "source_class" attrtibute of the object was not the name of the class of the complex tyoe diff --git a/lib/washout_builder/document/generator.rb b/lib/washout_builder/document/generator.rb index 4efd1ac..97d7f74 100644 --- a/lib/washout_builder/document/generator.rb +++ b/lib/washout_builder/document/generator.rb @@ -1,9 +1,26 @@ require_relative './exception_model' module WashoutBuilder module Document + # class that is used to generate HTML documentation for a soap service class Generator + # class that is used to generate HTML documentation for a soap service + # + # @!attribute soap_actions + # @return [Hash] Hash that contains all the actions to which the web service responds to and information about them + # + # @!attribute config + # @return [WashOut::SoapConfig] holds the soap configuration for the soap service + # + # @!attribute controller_name + # @return [String] The name of the controller that acts like a soap service attr_accessor :soap_actions, :config, :controller_name + # Method used to initialize the instance of object + # @see #controller_class + # + # @param [String] controller The name of the controller that acts like a soap service + # @return [void] + # @api public def initialize(controller) controller_class_name = controller_class(controller) self.config = controller_class_name.soap_config @@ -11,34 +28,69 @@ def initialize(controller) self.controller_name = controller end + # Returns the namespace used for the controller by using the soap configuration of the controller + # + # @return [String] description of returned object + # @api public def namespace config.respond_to?(:namespace) ? config.namespace : nil end + # Retrives the class of the controller by using its name + # + # @param [String] controller The name of the controller + # @return [Class] Returns the class of the controller + # @api public def controller_class(controller) "#{controller}_controller".camelize.constantize end + # Retrieves the endpoint of the soap service based on its namespace + # @see #namespace + # + # @return [String] Returns the current soap service's endpoint based on its namespace + # @api public def endpoint namespace.blank? ? nil : namespace.gsub('/wsdl', '/action') end + # Returns the service name using camelcase letter + # + # @return [String] Returns the service name using camelcase letter + # @api public def service controller_name.blank? ? nil : controller_name.camelize end + # Returns the service description if the service can respond to description method + # + # @return [String] Returns the service description if the service can respond to description method + # @api public def service_description config.respond_to?(:description) ? config.description : nil end + # returns a collection of all operation that the service responds to + # + # @return [Array] returns a collection of all operation that the service responds to + # @api public def operations soap_actions.map { |operation, _formats| operation } end + # returns the operations of a service by sorting them alphabetically and removes duplicates + # + # @return [Array] returns a collection of all operation that the service responds to sorted alphabetically + # @api public def sorted_operations soap_actions.sort_by { |operation, _formats| operation.downcase }.uniq unless soap_actions.blank? end + # Returns the exceptions that a specific operation can raise + # + # @param [String] operation_name describe operation_name + # @return [Array] returns an array with all the exception classes that the operation send as argument can raise + # @api public 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? @@ -47,10 +99,23 @@ def operation_exceptions(operation_name) faults.select { |x| WashoutBuilder::Type.valid_fault_class?(x) } end + # Sorts a hash by a key alphabetically + # + # @param [Hash] types Any kind of hash + # @option types [String, Symbol] :type The name of the key should be the same as the second argument + # @param [String, Symbol] type The key that is used for sorting alphabetically + # @return [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 + # @api public 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 + # Returns either the input arguments of a operation or the output types of that operation depending on the argument + # + # @param [String] type The type of the arguments that need to be returned ("input" or anything else ) + # @return [Array, Array] If the argument is "input" will return the arguments of the operation , ottherwise the return type + # @api public def argument_types(type) format_type = (type == 'input') ? 'builder_in' : 'builder_out' types = [] @@ -64,18 +129,35 @@ def argument_types(type) types end + # Returns the arguments of all operations + # @see #argument_types + # @return [Array] An array with all the arguments types of all operations the service responds to + # @api public def input_types argument_types('input') end + # Returns the arguments of all operations + # @see #argument_types + # @return [Array] An array with all the exceptions that all operations can raise + # @api public def output_types argument_types('output') end + # Returns the names of all operations sorted alphabetically + # + # @return [Array] An array with all the names of all operations sorted alphabetically + # @api public def all_soap_action_names operations.map(&:to_s).sort_by(&:downcase).uniq unless soap_actions.blank? end + # Returns all the complex types sorted alphabetically + # @see WashoutBuilder::Document::ComplexType#get_nested_complex_types + + # @return [Array] Returns an array with all the complex types sorted alphabetically + # @api public def complex_types defined = [] (input_types + output_types).each do |p| @@ -84,18 +166,38 @@ def complex_types defined = sort_complex_types(defined, 'class') end + # Returns an array with all the operations that can raise an exception at least or more + # + # @return [Array] Returns an array with all the names of all operations that can raise an exception or more + # @api public def actions_with_exceptions soap_actions.select { |_operation, formats| !formats[:raises].blank? } end + # Returns all the exception raised by all operations + # @see #actions_with_exceptions + # + # @return [Array] Returns an array with all the exception classes that are raised by all operations + # @api public def exceptions_raised actions_with_exceptions.map { |_operation, formats| formats[:raises].is_a?(Array) ? formats[:raises] : [formats[:raises]] }.flatten end + # Fiters the exceptions raised by checking if they classes inherit from WashOout::SoapError + # @see #exceptions_raised + # @return [Array] returns the exceptions that are raised by all operations filtering only the ones that inherit from WashOut::SoapError + # @api public def filter_exceptions_raised exceptions_raised.select { |x| WashoutBuilder::Type.valid_fault_class?(x) } unless actions_with_exceptions.blank? end + # Retuens all the exception classes that can be raised by all operations with their ancestors also + # @see #filter_exceptions_raised + # @see WashoutBuilder::Document::ExceptionModel#get_fault_class_ancestors + # + # @param [Array] base_fault_array An array with the base exception classes from which we try to identify their ancestors + # @return [Array>Class>] Returns all the exception classes that can be raised by all operations with their ancestors also + # @api public def get_complex_fault_types(base_fault_array) fault_types = [] defined = filter_exceptions_raised @@ -104,6 +206,13 @@ def get_complex_fault_types(base_fault_array) fault_types end + # Returns all the exception classes raised by all operations sorted alphabetically + # @see WashoutBuilder::Type#all_fault_classes + # @see #get_complex_fault_types + # @see #sort_complex_types + # + # @return [Array] Returns all the exception classes that can be raised by all operations with their ancestors also sorted alphabetically + # @api public def fault_types base_fault = [WashoutBuilder::Type.all_fault_classes.first] fault_types = get_complex_fault_types(base_fault) diff --git a/lib/washout_builder/document/shared_complex_type.rb b/lib/washout_builder/document/shared_complex_type.rb index 877ed55..69da917 100644 --- a/lib/washout_builder/document/shared_complex_type.rb +++ b/lib/washout_builder/document/shared_complex_type.rb @@ -1,6 +1,12 @@ module WashoutBuilder module Document + # module that is used for both complex types and exception class to find their ancestors and filter out some of the ancestors module SharedComplexType + # Method that is used to fetch the ancestors of a class and fiter the ancestors that are present in the second argument + # + # @param [Class] class_name The class that is used to fetch the ancestors for + # @param [Array] array The array of classes that should be fitered from the ancestors if they are present + # @return [Array] The classes from which the class given as first argument inherits from but filtering the classes passed as second argument def get_complex_type_ancestors(class_name, array) (class_name.ancestors - class_name.included_modules).delete_if { |x| x.to_s.downcase == class_name.to_s.downcase || array.include?(x.to_s) } end diff --git a/lib/washout_builder/engine.rb b/lib/washout_builder/engine.rb index 7c59371..4a7cfa8 100644 --- a/lib/washout_builder/engine.rb +++ b/lib/washout_builder/engine.rb @@ -1,4 +1,5 @@ module WashoutBuilder + # the engine that is used to mount inside the rails application class Engine < ::Rails::Engine isolate_namespace WashoutBuilder initializer 'washout_builder.configuration' do |_app| diff --git a/lib/washout_builder/soap.rb b/lib/washout_builder/soap.rb index c56988d..a86002e 100644 --- a/lib/washout_builder/soap.rb +++ b/lib/washout_builder/soap.rb @@ -1,13 +1,24 @@ require 'active_support/concern' module WashoutBuilder + # the module that is used for soap actions to parse their definition and hold the infoirmation about + # their arguments and return types module SOAP extend ActiveSupport::Concern include WashOut::SOAP if defined?(WashOut::SOAP) include WashOut::Rails::Controller if defined?(WashOut::Rails::Controller) + # module that is used to define a soap action for a controller module ClassMethods + # module that is used to define a soap action for a controller + # + # @!attribute soap_actions + # @return [Hash] Hash that contains all the actions to which the web service responds to and information about them + # + # @!attribute washout_builder_action + # @return [String] holds the action of the controller attr_accessor :soap_actions, :washout_builder_action + # Define a SOAP action +action+. The function has two required +options+: # :args and :return. Each is a type +definition+ of format described in # WashOut::Param#parse_def. diff --git a/lib/washout_builder/type.rb b/lib/washout_builder/type.rb index 6ce5cb5..b49d8c6 100644 --- a/lib/washout_builder/type.rb +++ b/lib/washout_builder/type.rb @@ -1,7 +1,13 @@ module WashoutBuilder + # class that is used to define the basic types and the basic exception classes that should be considered class Type + # the basic types that are considered when checking an object type BASIC_TYPES = %w(string integer double boolean date datetime float time int) + # returns all the exception classes that should be considered to be detected + # + # @return [Array] returns all the exception classes that should be considered to be detected + # @api public def self.all_fault_classes faults = [] faults << WashOut::SOAPError if defined?(WashOut::SOAPError) @@ -10,10 +16,21 @@ def self.all_fault_classes faults end + # Checks if a exception class inherits from the basic ones + # @see #all_fault_classes + # + # @param [Class] fault_class the exception class that needs to be checks if has as ancestor one of the base classes + # @return [Boolean] Returns true if the class inherits from the basic classes or false otherwise + # @api public def self.ancestor_fault?(fault_class) fault_class.ancestors.find { |fault| all_fault_classes.include?(fault) }.present? end + # Checks if a exception class is valid, by checking if either is a basic exception class or has as ancerstor one ot the base classes + # + # @param [Class] fault The exception class that needs to be checks if has as ancestor one of the base classes or is one of them + # @return [Boolean] Returns true if the class inherits from the basic classes or is one of them, otherwise false + # @api public def self.valid_fault_class?(fault) fault.is_a?(Class) && (ancestor_fault?(fault) || all_fault_classes.include?(fault)) end diff --git a/lib/washout_builder/version.rb b/lib/washout_builder/version.rb index 14433cf..46acb36 100644 --- a/lib/washout_builder/version.rb +++ b/lib/washout_builder/version.rb @@ -1,14 +1,22 @@ -module WashoutBuilder # Returns the version of the currently loaded Rails as a Gem::Version +# Returns the version of the currently loaded gem as a Gem::Version +module WashoutBuilder + # Returns the version of the currently loaded gem as a Gem::Version def self.gem_version Gem::Version.new VERSION::STRING end + # the module that is used to generate the gem version module VERSION + # the major version of the gem MAJOR = 0 + # the minor version of the gem MINOR = 16 - TINY = 1 + # the tiny version of the gem + TINY = 2 + # if the version should be a e PRE = nil + # the full version of the gem composed from major minor tiny and prerelease versions STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.') end end