soybean 2.1.5 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source "http://rubygems.org"
3
3
  gem 'thor'
4
4
  gem 'activesupport', '~> 3.1'
5
5
  gem 'i18n'
6
+ #gem "soap4r-middleware-192", "~> 0.8.2", :require => "soap4r-middleware"
6
7
 
7
8
  # Add dependencies to develop your gem here.
8
9
  # Include everything needed to run rake, tests, features, etc.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.5
1
+ 2.2.0
data/bin/soybean CHANGED
@@ -1,54 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- $:.unshift File.expand_path('../vendor', File.dirname(__FILE__))
3
- $:.unshift File.expand_path('../vendor/soap4r', File.dirname(__FILE__))
4
- $:.unshift File.expand_path('../lib', File.dirname(__FILE__))
5
- require 'thor'
6
- require 'thor/actions'
7
- require 'soybean'
8
-
9
-
10
- class Soybean::CLI < Thor
11
- include Thor::Actions
12
- class_options :quiet => :boolean, :force => :boolean, :pretend => :boolean
13
- class_option :remove, :type => :boolean, :aliases => [:undo]
14
-
15
- desc "types [PATH_TO_XSD]", "Generate Ruby classes for xsd-schema from file_path.xsd"
16
- def types(location, destination = '.')
17
- Soybean::Generators::TypesGenerator.new(URI.parse(location)).generate do |filename, content|
18
- if options[:remove]
19
- remove_file File.join(destination, filename), options
20
- else
21
- create_file File.join(destination, filename), content, options
22
- end
23
- end
24
- end
25
2
 
26
- desc "service [PATH_TO_WSDL] [DESTINATION_DIR]", "Generate classes for WebService from WSDL"
27
- def service(wsdl, dir)
28
- Soybean::Generators::ServiceGenerator.new(dir, wsdl, spec_dir(dir)).generate do |filename, content|
29
- if options[:remove]
30
- remove_file filename, options
31
- else
32
- create_file filename, content, options
33
- end
34
- end
35
- end
36
-
37
- desc "version", "Show current version"
38
- def version
39
- puts File.read File.expand_path('../../VERSION', __FILE__)
40
- end
41
-
42
- no_tasks do
43
- def spec_dir(dir)
44
- default_spec_dir = "spec/#{dir}/models"
45
- if options[:force]
46
- default_spec_dir
47
- else
48
- ask("Spec directory: '#{default_spec_dir}'? ").presence || default_spec_dir
49
- end
50
- end
51
- end
3
+ if File.exists?(File.join(File.expand_path('../..', __FILE__), '.git'))
4
+ $:.unshift File.expand_path('../lib', File.dirname(__FILE__))
52
5
  end
53
6
 
7
+ require 'soybean'
8
+ require 'soybean/cli'
9
+
54
10
  Soybean::CLI.start
@@ -0,0 +1,52 @@
1
+ require 'thor'
2
+ require 'thor/actions'
3
+
4
+ class Soybean::CLI < Thor
5
+ include Thor::Actions
6
+ class_options :quiet => :boolean, :force => :boolean, :pretend => :boolean
7
+ class_option :remove, :type => :boolean, :aliases => [:undo]
8
+
9
+ map "-v" => :version
10
+
11
+
12
+ desc "types [PATH_TO_XSD]", "Generate Ruby classes for xsd-schema from file_path.xsd"
13
+
14
+ def types(location, destination = '.')
15
+ Soybean::Generators::TypesGenerator.new(URI.parse(location)).generate do |filename, content|
16
+ if options[:remove]
17
+ remove_file File.join(destination, filename), options
18
+ else
19
+ create_file File.join(destination, filename), content, options
20
+ end
21
+ end
22
+ end
23
+
24
+ desc "service [PATH_TO_WSDL] [DESTINATION_DIR]", "Generate classes for WebService from WSDL"
25
+
26
+ def service(wsdl, dir)
27
+ Soybean::Generators::ServiceGenerator.new(dir, wsdl, spec_dir(dir)).generate do |filename, content|
28
+ if options[:remove]
29
+ remove_file filename, options
30
+ else
31
+ create_file filename, content, options
32
+ end
33
+ end
34
+ end
35
+
36
+ desc "version", "Show current version"
37
+
38
+ def version
39
+ puts Soybean::VERSION
40
+ end
41
+
42
+ no_tasks do
43
+ def spec_dir(dir)
44
+ default_spec_dir = "spec/#{dir}/models"
45
+ if options[:force]
46
+ default_spec_dir
47
+ else
48
+ ask("Spec directory: '#{default_spec_dir}'? ").presence || default_spec_dir
49
+ end
50
+ end
51
+ end
52
+ end
@@ -9,9 +9,10 @@ module Soybean
9
9
 
10
10
  attr_reader :name
11
11
 
12
- def initialize(schema)
12
+ def initialize(schema, wsdl)
13
13
  @schema = schema
14
- @name = name_from_namespace(schema.targetnamespace)
14
+ @wsdl = wsdl
15
+ @name = namespace.underscore
15
16
  @name_creator = WSDL::SOAP::ClassNameCreator.new
16
17
  @defined_const = {}
17
18
  end
@@ -34,7 +35,13 @@ module Soybean
34
35
  end
35
36
 
36
37
  registry = ModuleDef.new("Mappings", [m])
37
- registry.def_require("soap/mapping")
38
+
39
+ @schema.importedschema.values.map(&:targetnamespace).map do |ns|
40
+ registry.def_require('mappings/'+URI.parse(ns).path[1..-2].underscore)
41
+ end
42
+
43
+ registry.def_require(type_path)
44
+
38
45
  registry.def_code('EncodedRegistry ||= ::SOAP::Mapping::EncodedRegistry.new')
39
46
  registry.def_code('LiteralRegistry ||= ::SOAP::Mapping::LiteralRegistry.new')
40
47
 
@@ -46,11 +53,11 @@ module Soybean
46
53
  end
47
54
 
48
55
  def literal_creator
49
- LiteralMappingRegistryCreator.new(@schema, @name_creator, 'Types', @defined_const, mapping_cache[:literal])
56
+ LiteralMappingRegistryCreator.new(@schema, @name_creator, module_name, @defined_const, mapping_cache[:literal])
50
57
  end
51
58
 
52
59
  def encoded_creator
53
- EncodedMappingRegistryCreator.new(@schema, @name_creator, 'Types', @defined_const, mapping_cache[:encoded])
60
+ EncodedMappingRegistryCreator.new(@schema, @name_creator, module_name, @defined_const, mapping_cache[:encoded])
54
61
  end
55
62
 
56
63
  def name_from_namespace(ns)
@@ -58,6 +65,18 @@ module Soybean
58
65
  (name || 'base').underscore.gsub(/_service$/, '')
59
66
  end
60
67
 
68
+ def namespace
69
+ URI.parse(@schema.targetnamespace).path[1..-2]
70
+ end
71
+
72
+ def type_path
73
+ "types/" + namespace.underscore
74
+ end
75
+
76
+ def module_name
77
+ "::" + namespace.camelize
78
+ end
79
+
61
80
  class ModuleDef < XSD::CodeGen::ModuleDef
62
81
  def initialize(name, modules = [])
63
82
  super(name)
@@ -100,6 +119,40 @@ module Soybean
100
119
  buf.gsub(/^\s+$/, '')
101
120
  end
102
121
  end
122
+
123
+ class MethodDefCreator < WSDL::SOAP::MethodDefCreator
124
+ private
125
+ def dump_method(mdef)
126
+ style = mdef.style
127
+ inputuse = mdef.inputuse
128
+ outputuse = mdef.outputuse
129
+ paramstr = param2str(mdef.parameters)
130
+ if paramstr.empty?
131
+ paramstr = '[]'
132
+ else
133
+ paramstr = "[ " << paramstr.split(/\r?\n/).join("\n ") << " ]"
134
+ end
135
+ definitions = <<__EOD__
136
+ #{ndq(mdef.soapaction)},
137
+ #{dq(mdef.name).underscore},
138
+ #{paramstr},
139
+ { :request_style => #{nsym(style)}, :request_use => #{nsym(inputuse)},
140
+ :response_style => #{nsym(style)}, :response_use => #{nsym(outputuse)},
141
+ :faults => #{mdef.faults.inspect} }
142
+ __EOD__
143
+ if style == :rpc
144
+ assign_const(mdef.qname.namespace, 'Ns')
145
+ return <<__EOD__
146
+ [ #{dqname(mdef.qname)},
147
+ #{definitions}]
148
+ __EOD__
149
+ else
150
+ return <<__EOD__
151
+ [ #{definitions}]
152
+ __EOD__
153
+ end
154
+ end
155
+ end
103
156
  end
104
157
  end
105
158
  end
@@ -0,0 +1,37 @@
1
+ module Soybean
2
+ module Generators
3
+ class MiddlewareGenerator
4
+ include BaseGenerator
5
+
6
+ attr_reader :name, :model
7
+
8
+ delegate :wsdl, :to => :model
9
+ delegate :class_name, :interface_name, :to => :model, :prefix => true
10
+
11
+ def initialize(model)
12
+ @model = model
13
+ @name = (wsdl.name.name.underscore.gsub(/service$/, '') rescue 'base') + 'middleware'
14
+ end
15
+
16
+ def dir
17
+ 'middlewares'
18
+ end
19
+
20
+ def generate
21
+ source = File.expand_path("../templates/middleware.rb", __FILE__)
22
+ context = instance_eval('binding')
23
+ content = ERB.new(::File.binread(source), nil, '-').result(context)
24
+ content
25
+ end
26
+
27
+ def class_name
28
+ @name.camelize
29
+ end
30
+
31
+ def endpoint_path
32
+ model_class_name
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -7,14 +7,17 @@ module Soybean
7
7
 
8
8
  def initialize(wsdl)
9
9
  @wsdl = wsdl
10
- @name = (wsdl.name.name.underscore.gsub(/service$/,'') rescue 'base') + 'service'
10
+ @name = (wsdl.name.name.underscore.gsub(/service$/, '') rescue 'base') + 'service'
11
11
  end
12
12
 
13
13
  def dir
14
- 'models'
14
+ ''
15
15
  end
16
16
 
17
17
  def generate
18
+ @wsdl.importedschema.map do |uri, schema|
19
+ "require 'mappings/#{URI.parse(schema.targetnamespace).path[1..-2].underscore}'\n"
20
+ end.join +
18
21
  "class #{class_name} < #{interface_name}\nend"
19
22
  end
20
23
 
@@ -23,7 +26,7 @@ module Soybean
23
26
  end
24
27
 
25
28
  def interface_name
26
- @name.camelize.gsub(/Service$/,'Interface')
29
+ @name.camelize.gsub(/Service$/, 'Interface')
27
30
  end
28
31
  end
29
32
  end
@@ -15,13 +15,13 @@ module Soybean
15
15
  end
16
16
 
17
17
  def generate
18
- (schemes + mappings + interface + model + specs).map do |generator|
18
+ (schemes + mappings + interface + model + specs + middleware).map do |generator|
19
19
  yield generator.fullpath(path), generator.generate
20
20
  end
21
21
  end
22
22
 
23
23
  def mappings
24
- @mappings ||= schemes.map { |gen| MappingGenerator.new(gen.xsd) }
24
+ @mappings ||= schemes.map { |gen| MappingGenerator.new(gen.xsd, @wsdl) }
25
25
  end
26
26
 
27
27
  def interface
@@ -32,6 +32,10 @@ module Soybean
32
32
  @model ||= [ModelGenerator.new(@wsdl)]
33
33
  end
34
34
 
35
+ def middleware
36
+ @middleware ||= model.map { |m| MiddlewareGenerator.new(m) }
37
+ end
38
+
35
39
  def specs
36
40
  @specs ||= model.map { |m| ModelSpecGenerator.new(m, @spec_dir) }
37
41
  end
@@ -0,0 +1,39 @@
1
+ module Middlewares
2
+ class <%= class_name %> < Soap4r::Middleware::Base
3
+ setup do
4
+ self.endpoint = %r(^/<%= model_class_name %>)
5
+ service = <%= model_class_name %>.new
6
+ <%= model_interface_name %>::Methods.each do |definitions|
7
+ opt = definitions.last
8
+ if opt[:request_style] == :document
9
+ self.router.add_document_operation(service, *definitions)
10
+ else
11
+ self.router.add_rpc_operation(service, *definitions)
12
+ end
13
+ end
14
+ self.mapping_registry = Mappings::EncodedRegistry
15
+ self.literal_mapping_registry = Mappings::LiteralRegistry
16
+ end
17
+
18
+ def call(env)
19
+ begin
20
+ if env['PATH_INFO'].match(self.class.endpoint)
21
+ handle(env)
22
+ else
23
+ # we can act as both a middleware and an app
24
+ @app ?
25
+ @app.call(env) :
26
+ [404, {"Content-Type" => "text/plain"}, ["404 - Not Found"]]
27
+ end
28
+ rescue => e
29
+ puts e.message
30
+ xml = Nokogiri::XML(e.message)
31
+
32
+ #xml.search('faultactor, detail, ivars, item').each { |elem| elem.remove }
33
+
34
+ [200, {'Allow' => 'POST',
35
+ 'Content-Type' => 'text/xml'}, [xml.to_s]]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -8,9 +8,9 @@ module Soybean
8
8
  attr_reader :name
9
9
 
10
10
  def initialize(url)
11
- @name = xsd_name(url.path)
12
11
  @definitions = import_scheme(url)
13
- super(@definitions, WSDL::SOAP::ClassNameCreator.new, 'Types')
12
+ @name = type_path
13
+ super(@definitions, WSDL::SOAP::ClassNameCreator.new, module_name)
14
14
  end
15
15
 
16
16
  def xsd
@@ -49,14 +49,6 @@ module Soybean
49
49
 
50
50
  protected
51
51
 
52
- def import_scheme(url)
53
- WSDL::XMLSchema::Importer.import(url.path)
54
- end
55
-
56
- def xsd_name(path)
57
- Pathname.new(path).basename('.*').to_s.underscore.gsub(/_service$/, '')
58
- end
59
-
60
52
  def with_cache
61
53
  result = yield
62
54
  if !classes_cache.key?(result.name) && result
@@ -62,8 +62,6 @@ module Soybean
62
62
  def dump_porttype
63
63
  class_name = mapped_class_basename(@porttype.name, @modulepath)
64
64
  c = XSD::CodeGen::ClassDef.new(class_name, 'Soybean::Interface')
65
- methoddef = MethodDefCreator.new(@definitions, @name_creator, @modulepath, {}).dump(@porttype.name)
66
- c.def_code %Q{Methods = [\n#{methoddef.gsub(/^/, " ")}\n]}
67
65
 
68
66
  element_definitions = @definitions.collect_elements
69
67
  actions.each do |method_name, params, operation|
@@ -77,6 +75,9 @@ module Soybean
77
75
  c.add_method(m)
78
76
  end
79
77
 
78
+ methoddef = MethodDefCreator.new(@definitions, @name_creator, @modulepath, {}).dump(@porttype.name)
79
+ c.def_code %Q{Methods = [\n#{methoddef.gsub(/^/, " ")}\n]}
80
+
80
81
  c.dump
81
82
  end
82
83
 
data/lib/soybean.rb CHANGED
@@ -5,10 +5,14 @@ require 'active_support/core_ext/array/grouping'
5
5
  require 'active_support/deprecation'
6
6
  require 'active_support/dependencies'
7
7
  require 'active_support/dependencies/autoload'
8
+ require 'active_support/core_ext/module/delegation'
9
+
10
+ $:.unshift File.absolute_path(File.join(File.dirname(__FILE__), '..', 'vendor/soap4r'))
8
11
 
9
12
  ActiveSupport::Dependencies.autoload_paths << File.absolute_path(File.join(File.dirname(__FILE__), '..', 'vendor/soap4r'))
10
13
  ActiveSupport::Dependencies.autoload_paths << File.absolute_path(File.join(File.dirname(__FILE__), '..', 'lib'))
11
14
 
12
15
  module Soybean
13
16
  extend ActiveSupport::Autoload
17
+ VERSION = File.read(File.expand_path('../../VERSION', __FILE__))
14
18
  end
data/soybean.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{soybean}
8
- s.version = "2.1.5"
8
+ s.version = "2.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Anton Sozontov"]
12
- s.date = %q{2011-09-30}
12
+ s.date = %q{2011-10-07}
13
13
  s.default_executable = %q{soybean}
14
14
  s.description = %q{Generate soap web-services from you wsdl. Generate: all classes from xsd, and other.}
15
15
  s.email = %q{a.sozontov@gmail.com}
@@ -29,15 +29,18 @@ Gem::Specification.new do |s|
29
29
  "VERSION",
30
30
  "bin/soybean",
31
31
  "lib/soybean.rb",
32
+ "lib/soybean/cli.rb",
32
33
  "lib/soybean/complex_type.rb",
33
34
  "lib/soybean/encoded_mapping_registry_creator.rb",
34
35
  "lib/soybean/generators/base_generator.rb",
35
36
  "lib/soybean/generators/class_generator.rb",
36
37
  "lib/soybean/generators/interface_generator.rb",
37
38
  "lib/soybean/generators/mapping_generator.rb",
39
+ "lib/soybean/generators/middleware_generator.rb",
38
40
  "lib/soybean/generators/model_generator.rb",
39
41
  "lib/soybean/generators/model_spec_generator.rb",
40
42
  "lib/soybean/generators/service_generator.rb",
43
+ "lib/soybean/generators/templates/middleware.rb",
41
44
  "lib/soybean/generators/templates/model_spec.rb",
42
45
  "lib/soybean/generators/types_generator.rb",
43
46
  "lib/soybean/interface.rb",
@@ -42,42 +42,76 @@ module WSDL
42
42
  @defined_const = {}
43
43
  end
44
44
 
45
+ def padding
46
+ @padding ||= " " * modulepath_split(@modulepath).size
47
+ end
48
+
49
+ def require_imported_types
50
+ @definitions.importedschema.values.map(&:targetnamespace).map do |ns|
51
+ "require 'types/#{type_path(ns)}'\n"
52
+ end.join
53
+ end
54
+
55
+ def include_imported_types
56
+ @definitions.importedschema.values.map(&:targetnamespace).map do |ns|
57
+ "include ::#{module_name(ns)}\n"
58
+ end.join
59
+ end
60
+
61
+ def import_scheme(url)
62
+ WSDL::XMLSchema::Importer.import(url.path)
63
+ end
64
+
65
+ def namespace(ns=@definitions.targetnamespace)
66
+ URI.parse(ns).path[1..-2]
67
+ end
68
+
69
+ def type_path(ns=@definitions.targetnamespace)
70
+ namespace(ns).underscore
71
+ end
72
+
73
+ def module_name(ns=@definitions.targetnamespace)
74
+ namespace(ns).camelize
75
+ end
76
+
45
77
  def dump(type = nil)
46
78
  result = "require 'xsd/qname'\n"
79
+
47
80
  # cannot use @modulepath because of multiple classes
48
81
  if @modulepath
49
82
  result << "\n"
50
- result << modulepath_split(@modulepath).collect { |ele| "module #{ele}" }.join("; ")
83
+ result << modulepath_split(@modulepath).each_with_index.collect { |ele, i| (" " * i) + "module #{ele}" }.join("\n")
51
84
  result << "\n\n"
52
85
  end
86
+ result << padding + include_imported_types
53
87
  str = dump_group(type)
54
88
  unless str.empty?
55
89
  result << "\n" unless result.empty?
56
- result << str
90
+ result << str.gsub("\n", "\n#{padding}")
57
91
  end
58
92
  str = dump_complextype(type)
59
93
  unless str.empty?
60
94
  result << "\n" unless result.empty?
61
- result << str
95
+ result << padding + str.gsub("\n", "\n#{padding}")
62
96
  end
63
- str = dump_simpletype(type)
97
+ str = dump_simpletype(type).gsub("\n", "\n#{padding}")
64
98
  unless str.empty?
65
99
  result << "\n" unless result.empty?
66
- result << str
100
+ result << padding + str.gsub("\n", "\n#{padding}")
67
101
  end
68
- str = dump_element(type)
102
+ str = dump_element(type).gsub("\n", "\n#{padding}")
69
103
  unless str.empty?
70
104
  result << "\n" unless result.empty?
71
- result << str
105
+ result << padding + str.gsub("\n", "\n#{padding}")
72
106
  end
73
- str = dump_attribute(type)
107
+ str = dump_attribute(type).gsub("\n", "\n#{padding}")
74
108
  unless str.empty?
75
109
  result << "\n" unless result.empty?
76
- result << str
110
+ result << padding + str.gsub("\n", "\n#{padding}")
77
111
  end
78
112
  if @modulepath
79
113
  result << "\n\n"
80
- result << modulepath_split(@modulepath).collect { |ele| "end" }.join("; ")
114
+ result << modulepath_split(@modulepath).each_with_index.collect { |ele, i| (" " * i) + "end" }.reverse.join("\n")
81
115
  result << "\n"
82
116
  end
83
117
  result
@@ -90,7 +90,7 @@ private
90
90
  @web_client = HTTPAccess2::Client
91
91
  rescue LoadError
92
92
  warn("Loading http-access2 failed. Net/http is used.") if $DEBUG
93
- require 'soap/netHttpClient'
93
+ require 'soap/net_http_client'
94
94
  @web_client = ::SOAP::NetHttpClient
95
95
  end
96
96
  end
@@ -13,173 +13,178 @@ require 'xsd/codegen/commentdef'
13
13
 
14
14
 
15
15
  module XSD
16
- module CodeGen
16
+ module CodeGen
17
17
 
18
18
 
19
- class ModuleDef
20
- include GenSupport
21
- include CommentDef
19
+ class ModuleDef
20
+ include GenSupport
21
+ include CommentDef
22
22
 
23
- attr_reader :name
24
- attr_reader :innermodule
23
+ attr_reader :name
24
+ attr_reader :innermodule
25
25
 
26
- def initialize(name)
27
- @name = name
28
- @comment = nil
29
- @const = []
30
- @code = []
31
- @requirepath = []
32
- @methoddef = []
33
- @innermodule = []
34
- end
26
+ def initialize(name)
27
+ @name = name
28
+ @comment = nil
29
+ @const = []
30
+ @code = []
31
+ @requirepath = []
32
+ @methoddef = []
33
+ @innermodule = []
34
+ end
35
35
 
36
- def def_require(path)
37
- @requirepath << path
38
- end
36
+ def def_require(path)
37
+ @requirepath << path
38
+ end
39
39
 
40
- def def_const(const, value)
41
- unless safeconstname?(const)
42
- raise ArgumentError.new("#{const} seems to be unsafe")
43
- end
44
- @const << [const, value]
45
- end
40
+ def def_const(const, value)
41
+ unless safeconstname?(const)
42
+ raise ArgumentError.new("#{const} seems to be unsafe")
43
+ end
44
+ @const << [const, value]
45
+ end
46
46
 
47
- def def_code(code)
48
- @code << code
49
- end
47
+ def def_code(code)
48
+ @code << code
49
+ end
50
50
 
51
- def def_method(name, *params)
52
- add_method(MethodDef.new(name, *params) { yield if block_given? }, :public)
53
- end
54
- alias def_publicmethod def_method
51
+ def def_method(name, *params)
52
+ add_method(MethodDef.new(name, *params) { yield if block_given? }, :public)
53
+ end
55
54
 
56
- def def_protectedmethod(name, *params)
57
- add_method(MethodDef.new(name, *params) { yield if block_given? },
58
- :protected)
59
- end
55
+ alias def_publicmethod def_method
60
56
 
61
- def def_privatemethod(name, *params)
62
- add_method(MethodDef.new(name, *params) { yield if block_given? }, :private)
63
- end
57
+ def def_protectedmethod(name, *params)
58
+ add_method(MethodDef.new(name, *params) { yield if block_given? },
59
+ :protected)
60
+ end
64
61
 
65
- def add_method(m, visibility = :public)
66
- @methoddef << [visibility, m]
67
- end
62
+ def def_privatemethod(name, *params)
63
+ add_method(MethodDef.new(name, *params) { yield if block_given? }, :private)
64
+ end
68
65
 
69
- def dump
70
- buf = ""
71
- unless @requirepath.empty?
72
- buf << dump_requirepath
73
- end
74
- buf << dump_emptyline unless buf.empty?
75
- package = @name.split(/::/)[0..-2]
76
- buf << dump_package_def(package) unless package.empty?
77
- buf << dump_comment if @comment
78
- buf << dump_module_def
79
- spacer = false
80
- unless @const.empty?
81
- buf << dump_emptyline if spacer
82
- spacer = true
83
- buf << dump_const
84
- end
85
- unless @innermodule.empty?
86
- buf << dump_emptyline # always add 1 empty line
87
- spacer = true
88
- buf << dump_innermodule
89
- end
90
- unless @code.empty?
91
- buf << dump_emptyline if spacer
92
- spacer = true
93
- buf << dump_code
94
- end
95
- unless @methoddef.empty?
96
- buf << dump_emptyline if spacer
97
- spacer = true
98
- buf << dump_methods
99
- end
100
- buf << dump_module_def_end
101
- buf << dump_package_def_end(package) unless package.empty?
102
- buf.gsub(/^\s+$/, '')
103
- end
66
+ def add_method(m, visibility = :public)
67
+ @methoddef << [visibility, m]
68
+ end
104
69
 
105
- private
70
+ def dump
71
+ buf = ""
72
+ unless @requirepath.empty?
73
+ buf << dump_requirepath
74
+ end
75
+ buf << dump_emptyline unless buf.empty?
76
+ package = @name.split(/::/)[0..-2]
77
+ buf << dump_package_def(package) unless package.empty?
78
+ buf << dump_comment if @comment
79
+ buf << dump_module_def
80
+ spacer = false
81
+ unless @const.empty?
82
+ buf << dump_emptyline if spacer
83
+ spacer = true
84
+ buf << dump_const
85
+ end
86
+ unless @innermodule.empty?
87
+ buf << dump_emptyline # always add 1 empty line
88
+ spacer = true
89
+ buf << dump_innermodule
90
+ end
91
+ unless @code.empty?
92
+ buf << dump_emptyline if spacer
93
+ spacer = true
94
+ buf << dump_code
95
+ end
96
+ unless @methoddef.empty?
97
+ buf << dump_emptyline if spacer
98
+ spacer = true
99
+ buf << dump_methods
100
+ end
101
+ buf << dump_module_def_end
102
+ buf << dump_package_def_end(package) unless package.empty?
103
+ buf.gsub(/^\s+$/, '')
104
+ end
106
105
 
107
- def dump_requirepath
108
- format(
109
- @requirepath.collect { |path|
110
- %Q(require '#{path}')
111
- }.join("\n")
112
- )
113
- end
106
+ private
114
107
 
115
- def dump_const
116
- dump_static(
117
- @const.sort.collect { |var, value|
118
- %Q(#{var} = #{dump_value(value)})
119
- }.join("\n")
120
- )
121
- end
108
+ def dump_requirepath
109
+ format(
110
+ @requirepath.collect { |path|
111
+ %Q(require '#{path}')
112
+ }.join("\n")
113
+ )
114
+ end
122
115
 
123
- def dump_innermodule
124
- dump_static(
125
- @innermodule.collect { |moduledef|
126
- moduledef.dump
127
- }.join("\n")
128
- )
129
- end
116
+ def dump_const
117
+ dump_static(
118
+ @const.sort.collect { |var, value|
119
+ %Q(#{var} = #{dump_value(value)})
120
+ }.join("\n")
121
+ )
122
+ end
130
123
 
131
- def dump_code
132
- dump_static(@code.join("\n"))
133
- end
124
+ def dump_innermodule
125
+ dump_static(
126
+ @innermodule.collect { |moduledef|
127
+ moduledef.dump
128
+ }.join("\n")
129
+ )
130
+ end
134
131
 
135
- def dump_static(str)
136
- format(str, 2)
137
- end
132
+ def dump_code
133
+ dump_static(@code.join("\n"))
134
+ end
138
135
 
139
- def dump_methods
140
- methods = {}
141
- @methoddef.each do |visibility, method|
142
- (methods[visibility] ||= []) << method
143
- end
144
- str = ""
145
- [:public, :protected, :private].each do |visibility|
146
- if methods[visibility]
147
- str << "\n" unless str.empty?
148
- str << visibility.to_s << "\n\n" unless visibility == :public
149
- str << methods[visibility].collect { |m| format(m.dump, 2) }.join("\n")
136
+ def dump_static(str)
137
+ format(str, 2)
150
138
  end
151
- end
152
- str
153
- end
154
139
 
155
- def dump_value(value)
156
- if value.respond_to?(:to_src)
157
- value.to_src
158
- else
159
- value
160
- end
161
- end
140
+ def dump_methods
141
+ methods = {}
142
+ @methoddef.each do |visibility, method|
143
+ (methods[visibility] ||= []) << method
144
+ end
145
+ str = ""
146
+ [:public, :protected, :private].each do |visibility|
147
+ if methods[visibility]
148
+ str << "\n" unless str.empty?
149
+ str << visibility.to_s << "\n\n" unless visibility == :public
150
+ str << methods[visibility].collect { |m| format(m.dump, 2) }.join("\n")
151
+ end
152
+ end
153
+ str
154
+ end
162
155
 
163
- def dump_package_def(package)
164
- format(package.collect { |ele| "module #{ele}" }.join("; ")) + "\n\n"
165
- end
156
+ def dump_value(value)
157
+ if value.respond_to?(:to_src)
158
+ value.to_src
159
+ else
160
+ value
161
+ end
162
+ end
166
163
 
167
- def dump_package_def_end(package)
168
- "\n\n" + format(package.collect { |ele| "end" }.join("; "))
169
- end
164
+ def padding(package)
165
+ @padding ||= " " * package.size
166
+ end
170
167
 
171
- def dump_module_def
172
- name = @name.to_s.split(/::/)
173
- format("module #{name.last}")
174
- end
168
+ def dump_package_def(package)
169
+ format package.each_with_index.collect { |ele, i| (" " * i) + "module #{ele}" }.join("\n")
170
+ end
175
171
 
176
- def dump_module_def_end
177
- format("end")
178
- end
179
- end
172
+ def dump_package_def_end(package)
173
+ format package.each_with_index.collect { |_, i| (" " * i) + "end" }.reverse.join("\n")
174
+ end
180
175
 
176
+ def dump_module_def
177
+ name = @name.to_s.split(/::/)
178
+ format("module #{name.last}")
179
+ end
181
180
 
182
- end
181
+ def dump_module_def_end
182
+ format("end")
183
+ end
184
+ end
185
+
186
+
187
+ end
183
188
  end
184
189
 
185
190
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soybean
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 2.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-30 00:00:00.000000000 +04:00
12
+ date: 2011-10-07 00:00:00.000000000 +04:00
13
13
  default_executable: soybean
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thor
17
- requirement: &19607540 !ruby/object:Gem::Requirement
17
+ requirement: &11455800 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *19607540
25
+ version_requirements: *11455800
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
- requirement: &19606400 !ruby/object:Gem::Requirement
28
+ requirement: &11454320 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '3.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *19606400
36
+ version_requirements: *11454320
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: i18n
39
- requirement: &19604300 !ruby/object:Gem::Requirement
39
+ requirement: &11449680 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *19604300
47
+ version_requirements: *11449680
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rspec
50
- requirement: &19602840 !ruby/object:Gem::Requirement
50
+ requirement: &11448500 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 2.3.0
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *19602840
58
+ version_requirements: *11448500
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: yard
61
- requirement: &19601780 !ruby/object:Gem::Requirement
61
+ requirement: &11443520 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 0.6.0
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *19601780
69
+ version_requirements: *11443520
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: bundler
72
- requirement: &19600900 !ruby/object:Gem::Requirement
72
+ requirement: &11442440 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: 1.0.0
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *19600900
80
+ version_requirements: *11442440
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: jeweler
83
- requirement: &19599740 !ruby/object:Gem::Requirement
83
+ requirement: &11441320 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ~>
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: 1.6.4
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *19599740
91
+ version_requirements: *11441320
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: rcov
94
- requirement: &19599100 !ruby/object:Gem::Requirement
94
+ requirement: &11440340 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,7 +99,7 @@ dependencies:
99
99
  version: '0'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *19599100
102
+ version_requirements: *11440340
103
103
  description: ! 'Generate soap web-services from you wsdl. Generate: all classes from
104
104
  xsd, and other.'
105
105
  email: a.sozontov@gmail.com
@@ -120,15 +120,18 @@ files:
120
120
  - VERSION
121
121
  - bin/soybean
122
122
  - lib/soybean.rb
123
+ - lib/soybean/cli.rb
123
124
  - lib/soybean/complex_type.rb
124
125
  - lib/soybean/encoded_mapping_registry_creator.rb
125
126
  - lib/soybean/generators/base_generator.rb
126
127
  - lib/soybean/generators/class_generator.rb
127
128
  - lib/soybean/generators/interface_generator.rb
128
129
  - lib/soybean/generators/mapping_generator.rb
130
+ - lib/soybean/generators/middleware_generator.rb
129
131
  - lib/soybean/generators/model_generator.rb
130
132
  - lib/soybean/generators/model_spec_generator.rb
131
133
  - lib/soybean/generators/service_generator.rb
134
+ - lib/soybean/generators/templates/middleware.rb
132
135
  - lib/soybean/generators/templates/model_spec.rb
133
136
  - lib/soybean/generators/types_generator.rb
134
137
  - lib/soybean/interface.rb
@@ -312,7 +315,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
312
315
  version: '0'
313
316
  segments:
314
317
  - 0
315
- hash: -3755334220841527446
318
+ hash: -1482793293416004037
316
319
  required_rubygems_version: !ruby/object:Gem::Requirement
317
320
  none: false
318
321
  requirements: