Module: WashoutBuilder::Document::ExceptionModel

Extended by:
ActiveSupport::Concern
Includes:
SharedComplexType
Defined in:
lib/washout_builder/document/exception_model.rb

Overview

the class that is used for soap exceptions to build structure and find ancestors and descendants

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SharedComplexType

#get_complex_type_ancestors

Class Method Details

.included(base) ⇒ Object



9
10
11
# File 'lib/washout_builder/document/exception_model.rb', line 9

def self.included(base)
  base.send :include, WashoutBuilder::Document::SharedComplexType
end

Instance Method Details

#check_valid_fault_method?(method) ⇒ Boolean

Dirty hack to determine if a method has both a setter and a getter and not basic method inherited from Object class

Parameters:

  • method (String)

    The method thats needs to be verified

Returns:

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



81
82
83
84
85
86
# File 'lib/washout_builder/document/exception_model.rb', line 81

def check_valid_fault_method?(method)
  method != :== && method != :! &&
    (instance_methods.include?(:"#{method}=") ||
      instance_methods.include?(:"#{method}")
    )
end

#fault_ancestor_hash(structure, ancestors) ⇒ Hash

constructs the structure of the current exception class by holding the instance, the structure, and its ancestors

Parameters:

  • structure (Hash)

    A hash that contains the structure of the current exception class (@see #find_fault_model_structure)

  • ancestors (Array<Class>)

    An array with all the exception classes from which the current object inherits from

  • options (Hash)

    a customizable set of options

Returns:

  • (Hash)

    options The hash that contains information about the current exception class



62
63
64
# File 'lib/washout_builder/document/exception_model.rb', line 62

def fault_ancestor_hash(structure, ancestors)
  { fault: self, structure: structure, ancestors: ancestors }
end

#fault_ancestorsArray<Class>

Retrieves all the ancestors of the current exception class except ActiveRecord::Base’, ‘Object’, ‘BasicObject’, ‘Exception’

Returns:

  • (Array<Class>)

    Returns an array with all the classes from which the current exception class inherits from



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

def fault_ancestors
  get_complex_type_ancestors(self, ['ActiveRecord::Base', 'Object', 'BasicObject', 'Exception'])
end

#fault_without_inheritable_elements(ancestors) ⇒ Type

Removes the inheritable elements from current object that are inherited from the class send as argument

Parameters:

  • ancestors (Class)

    describe ancestors

Returns:

  • (Type)

    description of returned object

See Also:



41
42
43
# File 'lib/washout_builder/document/exception_model.rb', line 41

def fault_without_inheritable_elements(ancestors)
  remove_fault_type_inheritable_elements(ancestors[0].find_fault_model_structure.keys)
end

#find_fault_attributesArray<String>

tries to fins all instance methods that have both a setter and a getter of the curent class

Returns:

  • (Array<String>)

    An array with all the atrributes and instance methods that have both a setter and a getter

See Also:



92
93
94
95
96
97
98
99
# File 'lib/washout_builder/document/exception_model.rb', line 92

def find_fault_attributes
  attrs = []
  attrs = instance_methods(nil).map do |method|
    method.to_s if check_valid_fault_method?(method)
  end
  attrs = attrs.delete_if { |method| method.end_with?('=') && attrs.include?(method.delete('=')) }
  attrs.concat(%w(message backtrace))
end

#find_fault_model_structureHash

Description of method

Returns:

  • (Hash)

    An hash that contains as keys the atribute names and as value the primitive and member type of that attribute

See Also:



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

def find_fault_model_structure
  h = {}
  find_fault_attributes.each do |method_name|
    method_name = method_name.to_s.end_with?('=') ? method_name.to_s.delete('=') : method_name
    primitive_type = get_fault_type_method(method_name)
    h["#{method_name}"] = {
      primitive: "#{primitive_type}",
      member_type: nil
    }
  end
  h
end

#get_fault_class_ancestors(defined, _debug = false) ⇒ Array<Class>

A recursive function that retrives all the ancestors of the current exception class

Parameters:

  • defined (Array<Hash>)

    An array that contains all the information about all the exception classes found so far

  • _debug (Boolean) (defaults to: false)

    false An optional parameter used for debugging purposes

Returns:

  • (Array<Class>)

    Array with all the exception classes from which the current exception class inherits from

See Also:



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/washout_builder/document/exception_model.rb', line 23

def get_fault_class_ancestors(defined, _debug = false)
  bool_the_same = false
  ancestors = fault_ancestors
  if ancestors.blank?
    defined << fault_ancestor_hash(find_fault_model_structure, [])
  else
    defined << fault_ancestor_hash(fault_without_inheritable_elements(ancestors), ancestors)
    ancestors[0].get_fault_class_ancestors(defined)
  end
  ancestors unless bool_the_same
end

#get_fault_type_method(method_name) ⇒ String

Dirty hack to get the type of an atribute. Considering all other attributes as string type

Parameters:

  • method_name (String)

    The name of the attribute to use

Returns:

  • (String)

    Returns the type of the attribute , Currently returns “integer” for attribute “code” and “string” for all others



106
107
108
109
110
111
112
113
114
115
# File 'lib/washout_builder/document/exception_model.rb', line 106

def get_fault_type_method(method_name)
  case method_name.to_s.downcase
    when 'code'
      'integer'
    when 'message', 'backtrace'
      'string'
    else
      'string'
  end
end

#remove_fault_type_inheritable_elements(keys) ⇒ Hash

Removes the atributes that are send as argument

Parameters:

  • keys (Array<String>)

    The keys that have to be removed from the model structure

Returns:

  • (Hash)

    An hash that contains as keys the atribute names and as value the primitive and member type of that attribute

See Also:



72
73
74
# File 'lib/washout_builder/document/exception_model.rb', line 72

def remove_fault_type_inheritable_elements(keys)
  find_fault_model_structure.delete_if { |key, _value| keys.include?(key) }
end