washout_builder 0.9.12 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,114 @@
1
+ module WashoutBuilder
2
+ module Document
3
+ class Generator
4
+
5
+ @attrs = [:soap_actions, :config, :service_class]
6
+
7
+ attr_reader *@attrs
8
+ attr_accessor *@attrs
9
+
10
+ def initialize(attrs = {})
11
+ self.config = attrs[:config]
12
+ self.service_class = attrs[:service_class]
13
+ self.soap_actions = attrs[:soap_actions]
14
+ end
15
+
16
+ def namespace
17
+ config.namespace
18
+ end
19
+
20
+
21
+ def endpoint
22
+ namespace.gsub("/wsdl", "/action")
23
+ end
24
+
25
+ def service
26
+ service_class.name.underscore.gsub("_controller", "").camelize
27
+ end
28
+
29
+ def service_description
30
+ config.description
31
+ end
32
+
33
+ def operations
34
+ soap_actions.map { |operation, formats| operation }
35
+ end
36
+
37
+
38
+ def input_types
39
+ types = []
40
+ soap_actions.each do |operation, formats|
41
+ (formats[:in]).each do |p|
42
+ types << p
43
+ end
44
+ end
45
+ types
46
+ end
47
+
48
+ def output_types
49
+ types = []
50
+ soap_actions.each do |operation, formats|
51
+ (formats[:out]).each do |p|
52
+ types << p
53
+ end
54
+ end
55
+ types
56
+ end
57
+
58
+ def get_soap_action_names
59
+ operations.map(&:to_s).sort_by { |name| name.downcase }.uniq unless soap_actions.blank?
60
+ end
61
+
62
+
63
+ def complex_types
64
+ defined = []
65
+ (input_types + output_types).each do |p|
66
+ defined.concat(p.get_nested_complex_types(config, defined))
67
+ end
68
+ defined.sort_by { |hash| hash[:class].to_s.downcase }.uniq unless defined.blank?
69
+ end
70
+
71
+
72
+ def fault_types
73
+ defined = soap_actions.select{|operation, formats| !formats[:raises].blank? }
74
+ 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?
75
+ fault_types = []
76
+ if defined.blank?
77
+ defined = [WashOut::SOAPError]
78
+ else
79
+ defined << WashOut::SOAPError
80
+ end
81
+ defined.each{ |exception_class| exception_class.get_fault_class_ancestors( fault_types, true)} unless defined.blank?
82
+ complex_types = extract_nested_complex_types_from_exceptions(fault_types)
83
+ complex_types.delete_if{ |hash| fault_types << hash if hash[:fault].ancestors.include?(WashOut::SOAPError) } unless complex_types.blank?
84
+ fault_types = fault_types.sort_by { |hash| hash[:fault].to_s.downcase }.uniq unless fault_types.blank?
85
+ complex_types = complex_types.sort_by { |hash| hash[:fault].to_s.downcase }.uniq unless complex_types.blank?
86
+ [fault_types, complex_types]
87
+ end
88
+
89
+ def extract_nested_complex_types_from_exceptions(fault_types)
90
+ complex_types = []
91
+ fault_types.each do |hash|
92
+ hash[:structure].each do |attribute, attr_details|
93
+ complex_class = hash[:fault].get_virtus_member_type_primitive(attr_details)
94
+ unless complex_class.nil?
95
+ param_class = complex_class.is_a?(Class) ? complex_class : complex_class.constantize rescue nil
96
+ if !param_class.nil? && param_class.ancestors.include?(Virtus::Model::Core)
97
+ param_class.send :extend, WashoutBuilder::Document::VirtusModel
98
+ param_class.get_fault_class_ancestors( complex_types)
99
+ elsif !param_class.nil? && !param_class.ancestors.include?(Virtus::Model::Core)
100
+ 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."
101
+ end
102
+ end
103
+ end
104
+ end
105
+ complex_types
106
+ end
107
+
108
+
109
+
110
+
111
+
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,45 @@
1
+ module WashoutBuilder
2
+ module Document
3
+ module VirtusModel
4
+ extend ActiveSupport::Concern
5
+
6
+ def get_fault_class_ancestors( defined, debug = false)
7
+ bool_the_same = false
8
+ ancestors = (self.ancestors - self.included_modules).delete_if{ |x| x.to_s.downcase == self.to_s.downcase || x.to_s == "ActiveRecord::Base" || x.to_s == "Object" || x.to_s =="BasicObject" || x.to_s == "Exception" }
9
+ if ancestors.blank?
10
+ defined << {:fault => self,:structure =>get_virtus_model_structure ,:ancestors => [] }
11
+ else
12
+ fault_structure = remove_fault_type_inheritable_elements( ancestors[0].get_virtus_model_structure.keys)
13
+ defined << {:fault => self,:structure =>fault_structure ,:ancestors => ancestors }
14
+ ancestors[0].get_fault_class_ancestors( defined)
15
+ end
16
+ ancestors unless bool_the_same
17
+ end
18
+
19
+
20
+ def remove_fault_type_inheritable_elements( keys)
21
+ get_virtus_model_structure.delete_if{|key,value| keys.include?(key) }
22
+ end
23
+
24
+
25
+
26
+
27
+ def get_virtus_member_type_primitive(attr_details)
28
+ complex_class = nil
29
+ if attr_details[:primitive].to_s.downcase == "array" && !WashoutBuilder::Type::BASIC_TYPES.include?(attr_details[:member_type].to_s.downcase)
30
+ complex_class = attr_details[:member_type]
31
+ elsif attr_details[:primitive].to_s.downcase != "array" && !WashoutBuilder::Type::BASIC_TYPES.include?(attr_details[:primitive].to_s.downcase)
32
+ complex_class = attr_details[:primitive]
33
+ end
34
+ complex_class
35
+ end
36
+
37
+
38
+ def get_virtus_model_structure
39
+ attribute_set.inject({}) {|h, elem| h["#{elem.name}"]= { :primitive => "#{elem.primitive}", :member_type => elem.options[:member_type].nil? ? nil: elem.options[:member_type].primitive }; h }
40
+ end
41
+
42
+
43
+ end
44
+ end
45
+ end
@@ -9,7 +9,8 @@ module WashoutBuilder
9
9
  "date",
10
10
  "datetime",
11
11
  "float",
12
- "time"
12
+ "time",
13
+ "int"
13
14
  ]
14
15
 
15
16
  end
@@ -1,3 +1,3 @@
1
1
  module WashoutBuilder
2
- VERSION = "0.9.12"
2
+ VERSION = "0.10.1"
3
3
  end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe WashoutBuilderController do
4
+
5
+
6
+
7
+
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe WashoutBuilderHelper do
4
+
5
+
6
+
7
+
8
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ feature "All Services" do
4
+
5
+
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ feature "Service" do
4
+
5
+
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Dummy::Application
@@ -0,0 +1,51 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "action_controller/railtie"
4
+ require "rails/test_unit/railtie"
5
+
6
+ if Rails::VERSION::MAJOR >= 4
7
+ # Ugly hack to make Rails 4 JRuby-compatible to escape Travis errors
8
+ Rails::Engine.class_eval do
9
+ def railties
10
+ @railties ||= self.class.const_get(:Railties).new
11
+ end
12
+ end
13
+ end
14
+
15
+ Bundler.require
16
+ require "wash_out"
17
+
18
+ module Dummy
19
+ class Application < Rails::Application
20
+ # Settings in config/environments/* take precedence over those specified here.
21
+ # Application configuration should go into files in config/initializers
22
+ # -- all .rb files in that directory are automatically loaded.
23
+
24
+ # Custom directories with classes and modules you want to be autoloadable.
25
+ # config.autoload_paths += %W(#{config.root}/extras)
26
+
27
+ # Only load the plugins named here, in the order given (default is alphabetical).
28
+ # :all can be used as a placeholder for all plugins not explicitly named.
29
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
30
+
31
+ # Activate observers that should always be running.
32
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
33
+
34
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
35
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
36
+ # config.time_zone = 'Central Time (US & Canada)'
37
+
38
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
39
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
40
+ # config.i18n.default_locale = :de
41
+
42
+ # JavaScript files you want as :defaults (application.js is always included).
43
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
44
+
45
+ # Configure the default encoding used in templates for Ruby 1.9.
46
+ config.encoding = "utf-8"
47
+
48
+ # Configure sensitive parameters which will be filtered from the log file.
49
+ config.filter_parameters += [:password]
50
+ end
51
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
9
+
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ Dummy::Application.initialize!
@@ -0,0 +1,23 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the webserver when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_view.debug_rjs = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Print deprecation notices to the Rails logger
18
+ config.active_support.deprecation = :log
19
+
20
+ # Only use best-standards-support built into browsers
21
+ config.action_dispatch.best_standards_support = :builtin
22
+ end
23
+
@@ -0,0 +1,29 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The test environment is used exclusively to run your application's
5
+ # test suite. You never need to work with it otherwise. Remember that
6
+ # your test database is "scratch space" for the test suite and is wiped
7
+ # and recreated between test runs. Don't rely on the data there!
8
+ config.cache_classes = true
9
+
10
+ config.eager_load = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Raise exceptions instead of rendering exception templates
17
+ config.action_dispatch.show_exceptions = false
18
+
19
+ # Disable request forgery protection in test environment
20
+ config.action_controller.allow_forgery_protection = false
21
+
22
+ # Use SQL instead of Active Record's schema dumper when creating the test database.
23
+ # This is necessary if your schema can't be completely dumped by the schema dumper,
24
+ # like if you have constraints or database-specific column types
25
+ # config.active_record.schema_format = :sql
26
+
27
+ # Print deprecation notices to the stderr
28
+ config.active_support.deprecation = :stderr
29
+ end
@@ -0,0 +1,7 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4
+ # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5
+
6
+ # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7
+ # Rails.backtrace_cleaner.remove_silencers!
@@ -0,0 +1,10 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new inflection rules using the following format
4
+ # (all these examples are active by default):
5
+ # ActiveSupport::Inflector.inflections do |inflect|
6
+ # inflect.plural /^(ox)$/i, '\1en'
7
+ # inflect.singular /^(ox)en/i, '\1'
8
+ # inflect.irregular 'person', 'people'
9
+ # inflect.uncountable %w( fish sheep )
10
+ # end
@@ -0,0 +1,5 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Add new mime types for use in respond_to blocks:
4
+ # Mime::Type.register "text/richtext", :rtf
5
+ # Mime::Type.register_alias "text/html", :iphone
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ # Your secret key for verifying the integrity of signed cookies.
4
+ # If you change this key, all old signed cookies will become invalid!
5
+ # Make sure the secret is at least 30 characters and all random,
6
+ # no regular words or you'll be exposed to dictionary attacks.
7
+ Dummy::Application.config.secret_token = 'b8d5d5687c012c2ef1a7a6e8006172402c48a3dcccca67c076eaad81c4712ad236ca2717c3706df7b286468c749d223f22acb0d96c27bdf33bbdbb9684ad46e5'
8
+ Dummy::Application.config.secret_key_base = 'ed27a919186a27649accc93ad8c2750a022ef255780e8a15a439658e9f8c520ed70ea071e596b2d23ed41163cf36c21ff5afcd31d19439bb1e4c420f2a57bce6'
@@ -0,0 +1,8 @@
1
+ # Be sure to restart your server when you modify this file.
2
+
3
+ Dummy::Application.config.session_store :cookie_store, :key => '_dummy_session'
4
+
5
+ # Use the database for sessions instead of the cookie-based default,
6
+ # which shouldn't be used to store highly confidential information
7
+ # (create the session table with "rails generate session_migration")
8
+ # Dummy::Application.config.session_store :active_record_store
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
@@ -0,0 +1,58 @@
1
+ Dummy::Application.routes.draw do
2
+ # The priority is based upon order of creation:
3
+ # first created -> highest priority.
4
+
5
+ # Sample of regular route:
6
+ # match 'products/:id' => 'catalog#view'
7
+ # Keep in mind you can assign values other than :controller and :action
8
+
9
+ # Sample of named route:
10
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
+ # This route can be invoked with purchase_url(:id => product.id)
12
+
13
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
14
+ # resources :products
15
+
16
+ # Sample resource route with options:
17
+ # resources :products do
18
+ # member do
19
+ # get 'short'
20
+ # post 'toggle'
21
+ # end
22
+ #
23
+ # collection do
24
+ # get 'sold'
25
+ # end
26
+ # end
27
+
28
+ # Sample resource route with sub-resources:
29
+ # resources :products do
30
+ # resources :comments, :sales
31
+ # resource :seller
32
+ # end
33
+
34
+ # Sample resource route with more complex sub-resources
35
+ # resources :products do
36
+ # resources :comments
37
+ # resources :sales do
38
+ # get 'recent', :on => :collection
39
+ # end
40
+ # end
41
+
42
+ # Sample resource route within a namespace:
43
+ # namespace :admin do
44
+ # # Directs /admin/products/* to Admin::ProductsController
45
+ # # (app/controllers/admin/products_controller.rb)
46
+ # resources :products
47
+ # end
48
+
49
+ # You can have the root of your site routed with "root"
50
+ # just remember to delete public/index.html.
51
+ # root :to => "welcome#index"
52
+
53
+ # See how all your routes lay out with "rake routes"
54
+
55
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
56
+ # Note: This route will make all actions in every controller accessible via GET requests.
57
+ # match ':controller(/:action(/:id(.:format)))'
58
+ end