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


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


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'


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


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


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


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


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


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


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