Module: WashoutBuilder::Document::ComplexType
- Extended by:
- ActiveSupport::Concern
- Includes:
- SharedComplexType
- Defined in:
- lib/washout_builder/document/complex_type.rb
Instance Method Summary
collapse
#get_complex_type_ancestors
Instance Method Details
#ancestor_structure(ancestors) ⇒ Object
97
98
99
|
# File 'lib/washout_builder/document/complex_type.rb', line 97
def ancestor_structure(ancestors)
{ ancestors[0].to_s.downcase => ancestors[0].wash_out_param_map }
end
|
#complex_type_ancestors(config, complex_class, defined) ⇒ Object
24
25
26
|
# File 'lib/washout_builder/document/complex_type.rb', line 24
def complex_type_ancestors(config, complex_class, defined)
classified? ? get_class_ancestors(config, complex_class, defined) : nil
end
|
#complex_type_descendants(config, defined) ⇒ Object
75
76
77
78
79
80
81
82
|
# File 'lib/washout_builder/document/complex_type.rb', line 75
def complex_type_descendants(config,defined)
if struct?
c_names = []
map.each { |obj| c_names.concat(obj.get_nested_complex_types(config, defined)) }
defined.concat(c_names)
end
defined
end
|
#complex_type_hash(class_name, object, ancestors) ⇒ Object
101
102
103
|
# File 'lib/washout_builder/document/complex_type.rb', line 101
def complex_type_hash(class_name, object, ancestors)
{:class =>class_name, :obj =>object , :ancestors => ancestors }
end
|
#fix_descendant_wash_out_type(config, complex_class) ⇒ Object
43
44
45
46
47
48
49
50
|
# File 'lib/washout_builder/document/complex_type.rb', line 43
def fix_descendant_wash_out_type(config, complex_class)
param_class = complex_class.is_a?(Class) ? complex_class : complex_class.constantize rescue nil
if param_class.present? && param_class.ancestors.include?(WashOut::Type) && map[0].present?
descendant = WashOut::Param.parse_builder_def(config, param_class.wash_out_param_map)[0]
self.name = descendant.name
self.map = descendant.map
end
end
|
#get_ancestors(class_name) ⇒ Object
65
66
67
68
69
70
71
72
|
# File 'lib/washout_builder/document/complex_type.rb', line 65
def get_ancestors(class_name)
param_class = class_name.is_a?(Class) ? class_name : class_name.constantize rescue nil
if param_class.nil?
return nil
else
get_complex_type_ancestors(param_class, ["ActiveRecord::Base", "Object", "BasicObject", "WashOut::Type" ])
end
end
|
#get_class_ancestors(config, class_name, defined) ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/washout_builder/document/complex_type.rb', line 106
def get_class_ancestors( config, class_name, defined)
bool_the_same = false
ancestors = get_ancestors(class_name)
unless ancestors.blank?
ancestor_object = WashOut::Param.parse_def(config,ancestor_structure(ancestors))[0]
bool_the_same = same_structure_as_ancestor?( ancestor_object)
unless bool_the_same
top_ancestors = get_class_ancestors(config, ancestors[0], defined)
defined << complex_type_hash(ancestors[0],ancestor_object , top_ancestors)
end
ancestors unless bool_the_same
end
end
|
#get_complex_class_name(defined = []) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/washout_builder/document/complex_type.rb', line 8
def get_complex_class_name(defined = [])
complex_class = struct? ? basic_type.gsub(".","/").camelize : nil
unless complex_class.nil? || defined.blank?
complex_obj_found = defined.detect {|hash| hash[:class] == complex_class}
if !complex_obj_found.nil? && struct? && !classified?
raise RuntimeError, "Duplicate use of `#{basic_type}` type name. Consider using classified types."
end
end
complex_class
end
|
#get_nested_complex_types(config, defined) ⇒ Object
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/washout_builder/document/complex_type.rb', line 85
def get_nested_complex_types(config,defined)
defined = [] if defined.blank?
complex_class = get_complex_class_name( defined)
fix_descendant_wash_out_type( config, complex_class)
unless complex_class.nil?
defined << complex_type_hash(complex_class, self, complex_type_ancestors(config, complex_class, defined))
end
defined = complex_type_descendants(config, defined)
defined.sort_by { |hash| hash[:class].to_s.downcase }.uniq unless defined.blank?
end
|
#get_param_structure ⇒ Object
29
30
31
|
# File 'lib/washout_builder/document/complex_type.rb', line 29
def get_param_structure
map.inject({}) {|h,element| h[element.name] = element.type;h }
end
|
#remove_type_inheritable_elements(keys) ⇒ Object
34
35
36
|
# File 'lib/washout_builder/document/complex_type.rb', line 34
def remove_type_inheritable_elements( keys)
self.map = self.map.delete_if{|element| keys.include?(element.name) }
end
|
#same_structure_as_ancestor?(ancestor) ⇒ Boolean
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/washout_builder/document/complex_type.rb', line 53
def same_structure_as_ancestor?(ancestor)
param_structure = get_param_structure
ancestor_structure = ancestor.get_param_structure
if param_structure.keys == ancestor_structure.keys
return true
else
remove_type_inheritable_elements( ancestor_structure.keys)
return false
end
end
|