washout_builder 0.9.12 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +8 -8
  2. data/.travis.yml +6 -0
  3. data/Gemfile +11 -0
  4. data/README.rdoc +2 -1
  5. data/Rakefile +3 -1
  6. data/app/helpers/washout_builder_helper.rb +7 -169
  7. data/app/views/wash_with_html/doc.builder +11 -11
  8. data/lib/washout_builder.rb +24 -5
  9. data/lib/washout_builder/dispatcher.rb +6 -7
  10. data/lib/washout_builder/document/complex_type.rb +102 -0
  11. data/lib/washout_builder/document/generator.rb +114 -0
  12. data/lib/washout_builder/document/virtus_model.rb +45 -0
  13. data/lib/washout_builder/type.rb +2 -1
  14. data/lib/washout_builder/version.rb +1 -1
  15. data/spec/app/controllers/washout_builder_controller_spec.rb +8 -0
  16. data/spec/app/helpers/washout_builder_helper_spec.rb +8 -0
  17. data/spec/app/integration/washout_builder_all_services_spec.rb +7 -0
  18. data/spec/app/integration/washout_builder_service_spec.rb +7 -0
  19. data/spec/dummy/Rakefile +7 -0
  20. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  21. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  22. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  23. data/spec/dummy/config.ru +4 -0
  24. data/spec/dummy/config/application.rb +51 -0
  25. data/spec/dummy/config/boot.rb +10 -0
  26. data/spec/dummy/config/environment.rb +5 -0
  27. data/spec/dummy/config/environments/development.rb +23 -0
  28. data/spec/dummy/config/environments/test.rb +29 -0
  29. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  30. data/spec/dummy/config/initializers/inflections.rb +10 -0
  31. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  32. data/spec/dummy/config/initializers/secret_token.rb +8 -0
  33. data/spec/dummy/config/initializers/session_store.rb +8 -0
  34. data/spec/dummy/config/locales/en.yml +5 -0
  35. data/spec/dummy/config/routes.rb +58 -0
  36. data/spec/dummy/public/404.html +26 -0
  37. data/spec/dummy/public/422.html +26 -0
  38. data/spec/dummy/public/500.html +26 -0
  39. data/spec/dummy/public/favicon.ico +0 -0
  40. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  41. data/spec/dummy/script/rails +6 -0
  42. data/spec/lib/washout_builder/dispatcher_spec.rb +51 -0
  43. data/spec/lib/washout_builder/document/complex_type_spec.rb +0 -0
  44. data/spec/lib/washout_builder/document/generator_spec.rb +0 -0
  45. data/spec/lib/washout_builder/document/virtus_model_spec.rb +0 -0
  46. data/spec/lib/washout_builder/engine_spec.rb +6 -0
  47. data/spec/lib/washout_builder/soap_spec.rb +15 -0
  48. data/spec/lib/washout_builder/type_spec.rb +21 -0
  49. data/spec/lib/washout_builder_spec.rb +697 -0
  50. data/spec/spec_helper.rb +2 -0
  51. metadata +74 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Mzk1MTAyYzkzMjllNWU3Mjk5NTMxOTAyZTUwMDI0M2IzN2Y2NDNlMg==
4
+ MmE2OGFhZGZhMjA3NzMzZDRiNjU0MmM0MGZjYmZiZmViMTEzYzNhOA==
5
5
  data.tar.gz: !binary |-
6
- NzdmNzEwNGMzZTY4YTMzMDBiMjZlZTU2ZWE1MGE3YTQyMDk2NmJhZQ==
6
+ MzA0NGQ4MmQ5YjY2N2VlZmYxMjc4ZmZmYjBjZmQ4ZjdkMjg4ZDc5ZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTE0ZjE0OTQzNjBhNGM2MmMxZDQzZTUzMzZhMjYxZWRiZDU2MWFkYzkzNzcy
10
- OGQ4YzEwMjg1MTE3MjgwYTdhM2ZlZDYwOWYzZTBjYjA0MGQ3YWQ4ZDBmZTRm
11
- N2ZjNTk4OTc1ZThjMDEyNTYwYjhmZDc0ZmJlYWNlY2YxM2U3NDk=
9
+ ZjRlMmVlNzhlOTcwM2RmZWI1NDdiMWNiM2NmZTVhODg4ZjliZjNlYTU2OWY5
10
+ MzhkOTMwODZmZDRmNjAxODk5MTgwNjczYjRiMTU3MmQwNDlkMTJjZGM3YzZj
11
+ MmMwOTkxYTVmNTQ4MGZjYjgyMzkzNGI5YmQwN2FhYTYwNzBkMmU=
12
12
  data.tar.gz: !binary |-
13
- ZDg0ZjJmNThlM2E2YjhmMGY3NDdmMDYxNDVkOWMwMTMxZDY4YTZmNTdhNThh
14
- NTkwNWM5MWU5Y2I2NmMxMTY3OTA5ODJhYWVkYjc2YWE2NDJkZjM5NTIwMDZk
15
- YmE5ZmI0ODA0MmY1ZTc0Yjg4N2E4YmU5MDQ0YTNlMTRlN2JkM2Y=
13
+ YTA2MDI1NWNjYmYyNDMyZDI2ZDlhYjMwZTgzYmQ3N2Q5YWFhYjgxNTYwMzQ5
14
+ OTNlNWE4ZjAwYzY4ZTgxZjc4MGFmYWMxMDBjNWIzNmZkMDg1M2VkZjk3NTRh
15
+ YmM0NmNmZGMxMjRlZDQ1YTdmNDE4N2YyMDEyMTNlNWQzMjFiOWI=
@@ -6,3 +6,9 @@ rvm:
6
6
  - 1.9.3
7
7
  - jruby-19mode
8
8
  - 2.0.0
9
+ env:
10
+ - RAILS_ENV=test RACK_ENV=test
11
+ branches:
12
+ only:
13
+ - master
14
+ - develop
data/Gemfile CHANGED
@@ -18,4 +18,15 @@ gem 'tzinfo'
18
18
  gem 'pry'
19
19
  gem 'simplecov'
20
20
  gem 'simplecov-summary'
21
+ gem 'nori'
22
+ gem 'nokogiri'
23
+ gem 'capybara', '1.1.4'
24
+ gem 'selenium-webdriver', '~> 2.37.0'
25
+ gem 'headless'
26
+ gem 'capybara-firebug'
27
+ gem 'mocha', '~> 0.13.3', :require => false
28
+ gem 'factory_girl_rails'
29
+ gem 'forgery'
30
+ gem 'webmock'
31
+ gem 'rspec-instafail'
21
32
 
@@ -111,7 +111,8 @@ You can also specify complex types like this:
111
111
 
112
112
  end
113
113
 
114
- <b>The class MyCustomModel must include +Virtus.model+ if you want it to show up in the documentation!</b>
114
+ <b>The class MyCustomModel must include +Virtus.model+ or +Virtus.value_object+ or it must include at least one module that includes +Virtus.module+ if you want it to show up in the documentation!
115
+ Please checkout {Virtus Gem}[https://github.com/solnic/virtus] for further documentation!</b>
115
116
 
116
117
  You can also use aggregation with another fault class exception like this:
117
118
 
data/Rakefile CHANGED
@@ -3,7 +3,9 @@ require 'bundler/gem_tasks'
3
3
  require 'appraisal'
4
4
  require 'rspec/core/rake_task'
5
5
 
6
- RSpec::Core::RakeTask.new(:spec)
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ # spec.rspec_opts = ['--backtrace ']
8
+ end
7
9
 
8
10
  desc "Default: run the unit tests."
9
11
  task :default => [:all]
@@ -1,167 +1,5 @@
1
1
  module WashoutBuilderHelper
2
2
 
3
- def get_complex_class_name(p, defined = [])
4
- complex_class = p.struct? ? p.basic_type : nil
5
- complex_class = complex_class.include?(".") ? complex_class.gsub(".","/").camelize : complex_class.to_s.classify unless complex_class.nil?
6
-
7
- unless complex_class.nil? || defined.blank?
8
-
9
- complex_obj_found = defined.detect {|hash| hash[:class] == complex_class}
10
-
11
- if !complex_obj_found.nil? && p.struct? && !p.classified? && p.source_class_name.blank?
12
- raise RuntimeError, "Duplicate use of `#{p.basic_type}` type name. Consider using classified types."
13
- end
14
- end
15
-
16
- return complex_class
17
- end
18
-
19
-
20
- def get_param_structure(param)
21
- param.map.inject({}) {|h,element| h[element.name] = element.type;h }
22
- end
23
-
24
-
25
- def remove_type_inheritable_elements(param, keys)
26
- param.map.delete_if{|element| keys.include?(element.name) }
27
- end
28
-
29
-
30
- def same_structure_as_ancestor?(param, ancestor)
31
- param_structure = get_param_structure(param)
32
- ancestor_structure = get_param_structure(ancestor)
33
- if param_structure.keys == ancestor_structure.keys
34
- return true
35
- else
36
- remove_type_inheritable_elements(param, ancestor_structure.keys)
37
- return false
38
- end
39
- end
40
-
41
-
42
-
43
-
44
- def get_class_ancestors(param,class_name, defined)
45
- bool_the_same = false
46
- param_class = class_name.is_a?(Class) ? class_name : class_name.constantize rescue nil
47
- unless param_class.nil?
48
- ancestors = (param_class.ancestors - param_class.included_modules).delete_if{ |x| x.to_s.downcase == class_name.to_s.downcase || x.to_s == "ActiveRecord::Base" || x.to_s == "Object" || x.to_s =="BasicObject" || x.to_s == "WashOut::Type" }
49
- unless ancestors.blank?
50
- ancestor_structure = { ancestors[0].to_s.downcase => ancestors[0].columns_hash.inject({}) {|h, (k,v)| h["#{k}"]="#{v.type}".to_sym; h } }
51
- ancestor_object = WashOut::Param.parse_def(@soap_config,ancestor_structure)[0]
52
- bool_the_same = same_structure_as_ancestor?(param, ancestor_object)
53
- unless bool_the_same
54
- top_ancestors = get_class_ancestors(ancestor_object,ancestors[0], defined)
55
- defined << {:class =>ancestors[0], :obj =>ancestor_object , :ancestors => top_ancestors }
56
- end
57
- end
58
- ancestors unless bool_the_same
59
- end
60
- end
61
-
62
-
63
- def fix_descendant_wash_out_type(param, complex_class)
64
- param_class = complex_class.is_a?(Class) ? complex_class : complex_class.constantize rescue nil
65
- if !param_class.nil? && param_class.ancestors.include?(WashOut::Type) && !param.map[0].nil?
66
- descendant = WashOut::Param.parse_def(@soap_config, param_class.wash_out_param_map)[0]
67
- param.name = descendant.name
68
- param.map = descendant.map
69
- end
70
- end
71
-
72
- def get_nested_complex_types(param, defined)
73
- defined = [] if defined.blank?
74
- complex_class = get_complex_class_name(param, defined)
75
- fix_descendant_wash_out_type(param, complex_class)
76
- defined << {:class =>complex_class, :obj => param, :ancestors => param.classified? ? get_class_ancestors(param, complex_class, defined) : nil } unless complex_class.nil?
77
- if param.struct?
78
- c_names = []
79
- param.map.each { |obj| c_names.concat(get_nested_complex_types(obj, defined)) }
80
- defined.concat(c_names)
81
- end
82
- defined.sort_by { |hash| hash[:class].downcase }.uniq unless defined.blank?
83
- end
84
-
85
-
86
- def get_complex_types(map)
87
- defined = []
88
- map.each do |operation, formats|
89
- (formats[:in] + formats[:out]).each do |p|
90
- defined.concat(get_nested_complex_types(p, defined))
91
- end
92
- end
93
- defined.sort_by { |hash| hash[:class].downcase }.uniq unless defined.blank?
94
- end
95
-
96
-
97
- def remove_fault_type_inheritable_elements(param, keys)
98
- get_virtus_model_structure(param).delete_if{|key,value| keys.include?(key) }
99
- end
100
-
101
-
102
-
103
-
104
-
105
- def get_fault_class_ancestors(fault, defined, debug = false)
106
- bool_the_same = false
107
- unless fault.nil?
108
- ancestors = (fault.ancestors - fault.included_modules).delete_if{ |x| x.to_s.downcase == fault.to_s.downcase || x.to_s == "ActiveRecord::Base" || x.to_s == "Object" || x.to_s =="BasicObject" || x.to_s == "Exception" }
109
- if ancestors.blank?
110
- defined << {:fault => fault,:structure =>get_virtus_model_structure(fault) ,:ancestors => [] }
111
- else
112
- fault_structure = remove_fault_type_inheritable_elements(fault, get_virtus_model_structure(ancestors[0]).keys)
113
- defined << {:fault => fault,:structure =>fault_structure ,:ancestors => ancestors }
114
- get_fault_class_ancestors(ancestors[0], defined)
115
- end
116
- ancestors unless bool_the_same
117
- end
118
- end
119
-
120
- def get_virtus_model_structure(fault)
121
- fault.attribute_set.inject({}) {|h, elem| h["#{elem.name}"]= { :primitive => "#{elem.primitive}", :options => elem.options }; h }
122
- end
123
-
124
-
125
- def get_fault_types(map)
126
- defined = map.select{|operation, formats| !formats[:raises].blank? }
127
- defined = defined.collect {|operation, formats| formats[:raises].is_a?(Array) ? formats[:raises] : [formats[:raises]] }.flatten.select { |x| x.is_a?(Class) && x.ancestors.include?(WashOut::SOAPError) } unless defined.blank?
128
- fault_types = []
129
- if defined.blank?
130
- defined = [WashOut::SOAPError]
131
- else
132
- defined << WashOut::SOAPError
133
- end
134
- defined.each{ |item| get_fault_class_ancestors(item, fault_types, true)} unless defined.blank?
135
-
136
- complex_types = []
137
- fault_types.each do |hash|
138
- hash[:structure].each do |attribute, attr_details|
139
- if attr_details[:primitive].to_s.downcase == "array" && !WashoutBuilder::Type::BASIC_TYPES.include?(attr_details[:options][:member_type].primitive.to_s.downcase)
140
- complex_class = attr_details[:options][:member_type].primitive
141
- elsif attr_details[:primitive].to_s.downcase != "array" && !WashoutBuilder::Type::BASIC_TYPES.include?(attr_details[:primitive].to_s.downcase)
142
- complex_class = attr_details[:primitive]
143
- end
144
-
145
- param_class = complex_class.is_a?(Class) ? complex_class : complex_class.constantize rescue nil
146
- if !param_class.nil? && param_class.ancestors.include?(Virtus::Model::Core)
147
- get_fault_class_ancestors(param_class, complex_types)
148
- elsif !param_class.nil? && !param_class.ancestors.include?(Virtus::Model::Core)
149
- raise RuntimeError, "Non-existent use of `#{param_class}` type name or this class does not use Virtus.model. Consider using classified types that include Virtus.mode for exception atribute types."
150
- end
151
-
152
- end
153
- end
154
- complex_types.delete_if{ |hash| fault_types << hash if hash[:fault].ancestors.include?(WashOut::SOAPError) } unless complex_types.blank?
155
- fault_types = fault_types.sort_by { |hash| hash[:fault].to_s.downcase }.uniq unless fault_types.blank?
156
- complex_types = complex_types.sort_by { |hash| hash[:fault].to_s.downcase }.uniq unless complex_types.blank?
157
- [fault_types, complex_types]
158
- end
159
-
160
- def get_soap_action_names(map)
161
- map.map{|operation, formats| operation.to_s }.sort_by { |name| name.downcase }.uniq unless map.blank?
162
- end
163
-
164
-
165
3
  def create_html_complex_types(xml, types)
166
4
  types.each { |hash| create_complex_type_html(xml, hash[:obj], hash[:class], hash[:ancestors]) }
167
5
  end
@@ -181,9 +19,10 @@ module WashoutBuilderHelper
181
19
  # raise YAML::dump(element) if class_name.include?("ype") and element.name == "members"
182
20
  xml.li { |pre|
183
21
  if WashoutBuilder::Type::BASIC_TYPES.include?(element.type)
22
+ element.type = "integer" if element.type == "int"
184
23
  pre << "<span class='blue'>#{element.type}</span>&nbsp;<span class='bold'>#{element.name}</span>"
185
24
  else
186
- complex_class = get_complex_class_name(element)
25
+ complex_class = element.get_complex_class_name
187
26
  unless complex_class.nil?
188
27
  if element.multiplied == false
189
28
  pre << "<a href='##{complex_class}'><span class='lightBlue'>#{complex_class}</span></a>&nbsp;<span class='bold'>#{element.name}</span>"
@@ -228,9 +67,8 @@ module WashoutBuilderHelper
228
67
 
229
68
  else
230
69
  if attr_details[:primitive].to_s.downcase == "array"
231
- attr_primitive = attr_details[:options][:member_type].primitive.to_s
232
70
 
233
- attr_primitive = WashoutBuilder::Type::BASIC_TYPES.include?(attr_primitive.downcase) ? attr_primitive.downcase : attr_primitive
71
+ attr_primitive = WashoutBuilder::Type::BASIC_TYPES.include?(attr_details[:member_type].to_s.downcase) ? attr_details[:member_type].to_s.downcase : attr_details[:member_type]
234
72
  pre << "<a href='##{attr_primitive}'><span class='lightBlue'>Array of #{attr_primitive}</span></a>&nbsp;<span class='bold'>#{attribute}</span>"
235
73
  else
236
74
  pre << "<a href='##{attr_details[:primitive] }'><span class='lightBlue'>#{attr_details[:primitive]}</span></a>&nbsp;<span class='bold'>#{attribute}</span>"
@@ -259,7 +97,7 @@ module WashoutBuilderHelper
259
97
 
260
98
  xml.p("class" => "pre"){ |pre|
261
99
  unless formats[:out].nil?
262
- complex_class = get_complex_class_name(formats[:out][0])
100
+ complex_class = formats[:out][0].get_complex_class_name
263
101
  if WashoutBuilder::Type::BASIC_TYPES.include?(formats[:out][0].type)
264
102
  xml.span("class" => "blue") { |y| y<< "#{formats[:out][0].type}" }
265
103
  else
@@ -274,7 +112,7 @@ module WashoutBuilderHelper
274
112
  else
275
113
  pre << "void"
276
114
  end
277
-
115
+
278
116
  xml.span("class" => "bold") {|y| y << "#{operation} (" }
279
117
  mlen = formats[:in].size
280
118
  xml.br if mlen > 1
@@ -283,7 +121,7 @@ module WashoutBuilderHelper
283
121
  j=0
284
122
  while j<mlen
285
123
  param = formats[:in][j]
286
- complex_class = get_complex_class_name(param)
124
+ complex_class = param.get_complex_class_name
287
125
  use_spacer = mlen > 1 ? true : false
288
126
  if WashoutBuilder::Type::BASIC_TYPES.include?(param.type)
289
127
  pre << "#{use_spacer ? spacer: ''}<span class='blue'>#{param.type}</span>&nbsp;<span class='bold'>#{param.name}</span>"
@@ -321,7 +159,7 @@ module WashoutBuilderHelper
321
159
  mlen = formats[:in].size
322
160
  while j<mlen
323
161
  param = formats[:in][j]
324
- complex_class = get_complex_class_name(param)
162
+ complex_class = param.get_complex_class_name
325
163
  xml.li("class" => "pre") { |pre|
326
164
  if WashoutBuilder::Type::BASIC_TYPES.include?(param.type)
327
165
  pre << "<span class='blue'>#{param.type}</span>&nbsp;<span class='bold'>#{param.name}</span>"
@@ -5,7 +5,7 @@ xml.html( "xmlns" => "http://www.w3.org/1999/xhtml" ) {
5
5
 
6
6
  xml.head {
7
7
 
8
- xml.title "#{@service} interface description"
8
+ xml.title "#{@document.service} interface description"
9
9
 
10
10
  xml.style( "type"=>"text/css" ,"media" => "all" ) { xml.text! "
11
11
  body{font-family:Calibri,Arial;background-color:#fefefe;}
@@ -31,27 +31,27 @@ xml.html( "xmlns" => "http://www.w3.org/1999/xhtml" ) {
31
31
 
32
32
  xml.body {
33
33
 
34
- xml.h1 "#{ @service} Soap WebService interface description"
34
+ xml.h1 "#{ @document.service} Soap WebService interface description"
35
35
 
36
36
  xml.p{ |y| y << "Endpoint URI:";
37
- xml.span( "class" => "pre") { |y| y << "#{@endpoint}"};
37
+ xml.span( "class" => "pre") { |y| y << "#{@document.endpoint}"};
38
38
  }
39
39
 
40
40
  xml.p{ |y| y << "WSDL URI:";
41
41
  xml.span( "class" => "pre") {
42
- xml.a( "href" => "#{@namespace}") { |y| y << "#{@namespace}" }
42
+ xml.a( "href" => "#{@document.namespace}") { |y| y << "#{@document.namespace}" }
43
43
  };}
44
44
 
45
- unless @soap_config.description.blank?
46
- xml.h1 "#{@service}"
47
- xml.p "#{@soap_config.description}"
45
+ unless @document.service_description.blank?
46
+ xml.h1 "#{@document.service}"
47
+ xml.p "#{@document.service_description}"
48
48
  end
49
49
 
50
50
  xml.div("class" => "noprint") {
51
51
 
52
52
  xml.h2 "Index "
53
- @complex_types = get_complex_types(@map)
54
- @fault_types, @fault_complex_types = get_fault_types(@map)
53
+ @complex_types = @document.complex_types
54
+ @fault_types, @fault_complex_types = @document.fault_types
55
55
  unless @complex_types.blank?
56
56
  xml.p "Complex Types: "
57
57
 
@@ -78,7 +78,7 @@ xml.html( "xmlns" => "http://www.w3.org/1999/xhtml" ) {
78
78
  end
79
79
  end
80
80
 
81
- @methods = get_soap_action_names(@map)
81
+ @methods = @document.get_soap_action_names
82
82
  unless @methods.blank?
83
83
  xml.p "Public Methods:"
84
84
 
@@ -104,7 +104,7 @@ xml.html( "xmlns" => "http://www.w3.org/1999/xhtml" ) {
104
104
  end
105
105
  unless @methods.blank?
106
106
  xml.h2 "Public methods:"
107
- create_html_public_methods(xml, @map)
107
+ create_html_public_methods(xml, @document.soap_actions)
108
108
  end
109
109
 
110
110
  if @complex_types.blank? && @fault_types.blank? && @methods.blank?
@@ -2,8 +2,12 @@ require 'wash_out'
2
2
  require 'virtus'
3
3
  require 'washout_builder/soap'
4
4
  require 'washout_builder/engine'
5
+ require 'washout_builder/document/complex_type'
6
+ require 'washout_builder/document/virtus_model'
7
+ require 'washout_builder/document/generator'
5
8
  require 'washout_builder/dispatcher'
6
9
  require 'washout_builder/type'
10
+ require 'washout_builder/version'
7
11
 
8
12
 
9
13
  module ActionDispatch::Routing
@@ -23,17 +27,32 @@ module ActionDispatch::Routing
23
27
  end
24
28
  end
25
29
 
30
+ Virtus::InstanceMethods::Constructor.class_eval do
31
+ alias_method :original_initialize,:initialize
32
+ def initialize(attributes = nil)
33
+ if self.class.ancestors.include?(WashOut::SOAPError) || self.is_a?(WashOut::SOAPError)
34
+ attributes = {:message => attributes} unless attributes.is_a?(Hash)
35
+ end
36
+ original_initialize(attributes)
37
+ end
38
+ end
26
39
 
27
40
 
41
+ WashOut::Param.send :include, WashoutBuilder::Document::ComplexType
28
42
 
29
- WashOut::SOAPError.class_eval do
30
- include Virtus.model
31
- attribute :code, Integer
32
- attribute :message, String
33
- attribute :backtrace, String
43
+ [WashOut::SOAPError, SOAPError].each do |exception_class|
44
+ exception_class.class_eval do
45
+ extend WashoutBuilder::Document::VirtusModel
46
+ include Virtus.model
47
+ attribute :code, Integer
48
+ attribute :message, String
49
+ attribute :backtrace, String
50
+ end
34
51
  end
35
52
 
36
53
 
54
+
55
+
37
56
  ActionController::Base.class_eval do
38
57
 
39
58
  # Define a SOAP service. The function has no required +options+:
@@ -6,13 +6,12 @@ module WashoutBuilder
6
6
  module Dispatcher
7
7
 
8
8
  def _generate_doc
9
- @map = self.class.soap_actions
10
- @namespace = soap_config.namespace
11
- @name = controller_path.gsub('/', '_')
12
- @service = self.class.name.underscore.gsub("_controller", "").camelize
13
- @endpoint = @namespace.gsub("/wsdl", "/action")
14
- @soap_config = soap_config
15
-
9
+ @document = WashoutBuilder::Document::Generator.new(
10
+ :config => soap_config,
11
+ :service_class => self.class,
12
+ :soap_actions => self.class.soap_actions
13
+ )
14
+
16
15
  render :template => "wash_with_html/doc", :layout => false,
17
16
  :content_type => 'text/html'
18
17
  end
@@ -0,0 +1,102 @@
1
+ module WashoutBuilder
2
+ module Document
3
+ module ComplexType
4
+ extend ActiveSupport::Concern
5
+
6
+
7
+ def get_complex_class_name(defined = [])
8
+ complex_class = struct? ? basic_type : nil
9
+ complex_class = complex_class.include?(".") ? complex_class.gsub(".","/").camelize : complex_class.classify unless complex_class.nil?
10
+
11
+ unless complex_class.nil? || defined.blank?
12
+
13
+ complex_obj_found = defined.detect {|hash| hash[:class] == complex_class}
14
+
15
+ if !complex_obj_found.nil? && struct? && !classified?
16
+ raise RuntimeError, "Duplicate use of `#{basic_type}` type name. Consider using classified types."
17
+ end
18
+ end
19
+
20
+ return complex_class
21
+ end
22
+
23
+ def get_param_structure
24
+ map.inject({}) {|h,element| h[element.name] = element.type;h }
25
+ end
26
+
27
+
28
+ def remove_type_inheritable_elements( keys)
29
+ self.map = self.map.delete_if{|element| keys.include?(element.name) }
30
+ end
31
+
32
+ # def get_ancestor_structure
33
+ # {self.class.to_s.downcase => self.class.columns_hash.inject({}) {|h, (k,v)| h["#{k}"]="#{v.type}".to_sym; h } }
34
+ # end
35
+
36
+
37
+ def fix_descendant_wash_out_type(config, complex_class)
38
+ param_class = complex_class.is_a?(Class) ? complex_class : complex_class.constantize rescue nil
39
+ if !param_class.nil? && param_class.ancestors.include?(WashOut::Type) && !map[0].nil?
40
+ descendant = WashOut::Param.parse_def(config, param_class.wash_out_param_map)[0]
41
+ self.name = descendant.name
42
+ self.map = descendant.map
43
+ end
44
+ end
45
+
46
+
47
+ def same_structure_as_ancestor?(ancestor)
48
+ param_structure = get_param_structure
49
+ ancestor_structure = ancestor.get_param_structure
50
+ if param_structure.keys == ancestor_structure.keys
51
+ return true
52
+ else
53
+ remove_type_inheritable_elements( ancestor_structure.keys)
54
+ return false
55
+ end
56
+ end
57
+
58
+
59
+ def get_ancestors(class_name)
60
+ param_class = class_name.is_a?(Class) ? class_name : class_name.constantize rescue nil
61
+ if param_class.nil?
62
+ return nil
63
+ else
64
+ (param_class.ancestors - param_class.included_modules).delete_if{ |x| x.to_s.downcase == class_name.to_s.downcase || x.to_s == "ActiveRecord::Base" || x.to_s == "Object" || x.to_s =="BasicObject" || x.to_s == "WashOut::Type" }
65
+ end
66
+ end
67
+
68
+
69
+
70
+ def get_nested_complex_types(config,defined)
71
+ defined = [] if defined.blank?
72
+ complex_class = get_complex_class_name( defined)
73
+ fix_descendant_wash_out_type( config, complex_class)
74
+ defined << {:class =>complex_class, :obj => self, :ancestors => classified? ? get_class_ancestors(config, complex_class, defined) : nil } unless complex_class.nil?
75
+ if struct?
76
+ c_names = []
77
+ map.each { |obj| c_names.concat(obj.get_nested_complex_types(config, defined)) }
78
+ defined.concat(c_names)
79
+ end
80
+ defined.sort_by { |hash| hash[:class].to_s.downcase }.uniq unless defined.blank?
81
+ end
82
+
83
+
84
+ def get_class_ancestors( config, class_name, defined)
85
+ bool_the_same = false
86
+ ancestors = get_ancestors(class_name)
87
+ unless ancestors.blank?
88
+ ancestor_structure = { ancestors[0].to_s.downcase => ancestors[0].wash_out_param_map }
89
+ ancestor_object = WashOut::Param.parse_def(config,ancestor_structure)[0]
90
+ bool_the_same = same_structure_as_ancestor?( ancestor_object)
91
+ unless bool_the_same
92
+ top_ancestors = get_class_ancestors(config, ancestors[0], defined)
93
+ defined << {:class =>ancestors[0], :obj =>ancestor_object , :ancestors => top_ancestors }
94
+ end
95
+ ancestors unless bool_the_same
96
+ end
97
+ end
98
+
99
+
100
+ end
101
+ end
102
+ end