soybean 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.1.0
data/bin/soybean CHANGED
@@ -9,22 +9,32 @@ require 'soybean'
9
9
 
10
10
  class Soybean::CLI < Thor
11
11
  include Thor::Actions
12
+ class_options :quiet => :boolean, :force => :boolean, :pretend => :boolean
12
13
 
13
- desc "types file_path.xsd", "Generate Ruby classes for xsd-schema from file_path.xsd"
14
- method_options :quiet => :boolean, :force => :boolean
14
+ desc "types [PATH_TO_XSD]", "Generate Ruby classes for xsd-schema from file_path.xsd"
15
15
  def types(location, destination = '.')
16
16
  Soybean::Generators::TypesGenerator.new(URI.parse(location)).generate do |filename, content|
17
17
  create_file File.join(destination, filename), content, options
18
18
  end
19
19
  end
20
20
 
21
- desc "service [PATH_TO_WSDL] [DESTINATION_DIR]", "Generate Ruby classes from WSDL"
22
- method_options :quiet => :boolean, :force => :boolean
23
- def service(wsdl, destination_dir)
24
- Soybean::Generators::ServiceGenerator.new(destination_dir, wsdl).generate do |filename, content|
21
+ desc "service [PATH_TO_WSDL] [DESTINATION_DIR]", "Generate classes for WebService from WSDL"
22
+ def service(wsdl, dir)
23
+ Soybean::Generators::ServiceGenerator.new(dir, wsdl, spec_dir(dir)).generate do |filename, content|
25
24
  create_file filename, content, options
26
25
  end
27
26
  end
27
+
28
+ no_tasks do
29
+ def spec_dir(dir)
30
+ default_spec_dir = "spec/#{dir}/models"
31
+ if options[:force]
32
+ default_spec_dir
33
+ else
34
+ ask("Spec directory: '#{default_spec_dir}'? ").presence || default_spec_dir
35
+ end
36
+ end
37
+ end
28
38
  end
29
39
 
30
40
  Soybean::CLI.start
@@ -2,6 +2,10 @@ module Soybean
2
2
  module Generators
3
3
  module BaseGenerator
4
4
 
5
+ def fullpath(basedir)
6
+ File.join(basedir, dir, filename)
7
+ end
8
+
5
9
  def filename
6
10
  "#{name}.rb"
7
11
  end
@@ -3,12 +3,6 @@ require 'wsdl/soap/servant_skelton_creator'
3
3
  module Soybean
4
4
  module Generators
5
5
  class InterfaceGenerator
6
- class InterfaceCreator < WSDL::SOAP::ServantSkeltonCreator
7
- def mapped_class_basename(*)
8
- (@definitions.name.name.gsub(/Service$/, 'Interface') rescue 'BaseInterface')
9
- end
10
- end
11
-
12
6
  include BaseGenerator
13
7
 
14
8
  attr_reader :name
@@ -23,7 +17,7 @@ module Soybean
23
17
  end
24
18
 
25
19
  def generate
26
- InterfaceCreator.new(@wsdl, WSDL::SOAP::ClassNameCreator.new).dump
20
+ InterfaceBuilder.new(@wsdl, WSDL::SOAP::ClassNameCreator.new).dump
27
21
  end
28
22
 
29
23
  end
@@ -15,9 +15,16 @@ module Soybean
15
15
  end
16
16
 
17
17
  def generate
18
- "class %s < %sInterface\nend" % [@name.camelize, @name.camelize.gsub(/Service$/,'')]
18
+ "class #{class_name} < #{interface_name}\nend"
19
19
  end
20
20
 
21
+ def class_name
22
+ @name.camelize
23
+ end
24
+
25
+ def interface_name
26
+ @name.camelize.gsub(/Service$/,'Interface')
27
+ end
21
28
  end
22
29
  end
23
30
  end
@@ -0,0 +1,39 @@
1
+ module Soybean
2
+ module Generators
3
+ class ModelSpecGenerator
4
+ include BaseGenerator
5
+
6
+ attr_reader :name
7
+
8
+ # @param model [ModelGenerator]
9
+ def initialize(model, spec_dir)
10
+ @model, @spec_dir = model, spec_dir
11
+ @name = model.name
12
+ end
13
+
14
+ def fullpath(basedir)
15
+ File.join(dir, filename)
16
+ end
17
+
18
+ def dir
19
+ @spec_dir
20
+ end
21
+
22
+ def generate
23
+ source = File.expand_path("../templates/model_spec.rb", __FILE__)
24
+ context = instance_eval('binding')
25
+ content = ERB.new(::File.binread(source), nil, '-').result(context)
26
+ content
27
+ end
28
+
29
+ def class_name
30
+ @model.class_name
31
+ end
32
+
33
+ def interface_name
34
+ @model.interface_name
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -3,9 +3,10 @@ module Soybean
3
3
  class ServiceGenerator
4
4
  attr_reader :path, :wsdl_location, :wsdl
5
5
 
6
- def initialize(path, wsdl)
7
- @path, @wsdl_location = Pathname.new(path), wsdl
6
+ def initialize(path, wsdl, spec_dir)
7
+ @path, @wsdl_location = path, wsdl
8
8
  @wsdl = import_wsdl
9
+ @spec_dir = spec_dir
9
10
  @schemes = @wsdl.importedschema.keys
10
11
  end
11
12
 
@@ -14,21 +15,25 @@ module Soybean
14
15
  end
15
16
 
16
17
  def generate
17
- (schemes + mappings + interface + model).map do |generator|
18
- yield path.join(generator.dir, generator.filename), generator.generate
18
+ (schemes + mappings + interface + model + specs).map do |generator|
19
+ yield generator.fullpath(path), generator.generate
19
20
  end
20
21
  end
21
22
 
22
23
  def mappings
23
- schemes.map { |gen| MappingGenerator.new(gen.xsd) }
24
+ @mappings ||= schemes.map { |gen| MappingGenerator.new(gen.xsd) }
24
25
  end
25
26
 
26
27
  def interface
27
- [InterfaceGenerator.new(@wsdl)]
28
+ @interface ||= [InterfaceGenerator.new(@wsdl)]
28
29
  end
29
30
 
30
31
  def model
31
- [ModelGenerator.new(@wsdl)]
32
+ @model ||= [ModelGenerator.new(@wsdl)]
33
+ end
34
+
35
+ def specs
36
+ @specs ||= model.map { |m| ModelSpecGenerator.new(m, @spec_dir) }
32
37
  end
33
38
 
34
39
  protected
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe <%= class_name %> do
5
+
6
+ it 'should be subclass of <%= interface_name %>' do
7
+ <%= class_name %>.should < <%= interface_name %>
8
+ end
9
+
10
+ it 'should overload all interface methods (actions)' do
11
+ <%= class_name %>.actions.should eql <%= interface_name %>.actions
12
+ end
13
+
14
+ end
@@ -0,0 +1,14 @@
1
+ module Soybean
2
+ class Interface
3
+ class_attribute :interfaces, :instance_reader => false, :instance_writer => false
4
+
5
+ def self.inherited(subclass)
6
+ self.interfaces ||= []
7
+ self.interfaces << subclass if subclass.superclass == Soybean::Interface
8
+ end
9
+
10
+ def self.actions
11
+ self.instance_methods - Object.instance_methods
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,74 @@
1
+ module Soybean
2
+ class InterfaceBuilder
3
+ include WSDL::SOAP::ClassDefCreatorSupport
4
+ include XSD::CodeGen::GenSupport
5
+
6
+ attr_reader :definitions
7
+
8
+ def initialize(definitions, name_creator, modulepath = nil)
9
+ @definitions = definitions
10
+ @name_creator = name_creator
11
+ @modulepath = modulepath
12
+ end
13
+
14
+ def dump(porttype = nil)
15
+ result = ""
16
+ if @modulepath
17
+ result << "\n"
18
+ modulepath = @modulepath.respond_to?(:lines) ? @modulepath.lines : @modulepath # RubyJedi: compatible with Ruby 1.8.6 and above
19
+ result << modulepath.collect { |ele| "module #{ele}" }.join("; ")
20
+ result << "\n\n"
21
+ end
22
+ if porttype.nil?
23
+ @definitions.porttypes.each do |porttype|
24
+ result << dump_porttype(porttype)
25
+ result << "\n"
26
+ end
27
+ else
28
+ result << dump_porttype(porttype)
29
+ end
30
+ if @modulepath
31
+ result << "\n\n"
32
+ modulepath = @modulepath.respond_to?(:lines) ? @modulepath.lines : @modulepath # RubyJedi: compatible with Ruby 1.8.6 and above
33
+ result << modulepath.collect { |ele| "end" }.join("; ")
34
+ result << "\n"
35
+ end
36
+ result
37
+ end
38
+
39
+ private
40
+
41
+ def dump_porttype(porttype)
42
+ assigned_method = collect_assigned_method(@definitions, porttype.name, @modulepath)
43
+ class_name = mapped_class_basename(porttype.name, @modulepath)
44
+ c = XSD::CodeGen::ClassDef.new(class_name, 'Soybean::Interface')
45
+ element_definitions = @definitions.collect_elements
46
+ binding = porttype.find_binding
47
+ if binding
48
+ binding.operations.each do |op_bind|
49
+ operation = op_bind.find_operation
50
+ if operation.nil?
51
+ warn("operation not found for binding: #{op_bind}")
52
+ next
53
+ end
54
+ name = assigned_method[op_bind.boundid] || operation.name
55
+ methodname = safemethodname(name)
56
+ input = operation.input
57
+ params = input.find_message.parts.collect { |part|
58
+ safevarname(part.name)
59
+ }
60
+ m = XSD::CodeGen::MethodDef.new(methodname, params) do
61
+ <<-EOD
62
+ p [#{params.join(", ")}]
63
+ raise NotImplementedError.new
64
+ EOD
65
+ end
66
+ m.comment = dump_method_signature(methodname, operation, element_definitions)
67
+ c.add_method(m)
68
+ end
69
+ end
70
+ c.dump
71
+ end
72
+
73
+ end
74
+ 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.0.1"
8
+ s.version = "2.1.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-29}
12
+ s.date = %q{2011-09-30}
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}
@@ -36,17 +36,16 @@ Gem::Specification.new do |s|
36
36
  "lib/soybean/generators/interface_generator.rb",
37
37
  "lib/soybean/generators/mapping_generator.rb",
38
38
  "lib/soybean/generators/model_generator.rb",
39
+ "lib/soybean/generators/model_spec_generator.rb",
39
40
  "lib/soybean/generators/service_generator.rb",
41
+ "lib/soybean/generators/templates/model_spec.rb",
40
42
  "lib/soybean/generators/types_generator.rb",
43
+ "lib/soybean/interface.rb",
44
+ "lib/soybean/interface_builder.rb",
41
45
  "lib/soybean/literal_mapping_registry_creator.rb",
42
46
  "soybean.gemspec",
43
- "spec/services/interfaces/get_registrars_interface.rb",
44
- "spec/services/mappings/base.rb",
45
- "spec/services/mappings/get_registrars.rb",
46
- "spec/services/models/get_registrars_service.rb",
47
- "spec/services/types/get_registrars.rb",
48
- "spec/services/types/type.rb",
49
47
  "spec/soybean_spec.rb",
48
+ "spec/spec/services/models/get_registrars_service.rb",
50
49
  "spec/spec_helper.rb",
51
50
  "vendor/soap4r/soap/attachment.rb",
52
51
  "vendor/soap4r/soap/attrproxy.rb",
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe GetRegistrarsService do
5
+
6
+ it 'should be subclass of GetRegistrarsInterface' do
7
+ GetRegistrarsService.should < GetRegistrarsInterface
8
+ end
9
+
10
+ it 'should overload all interface methods (actions)' do
11
+ GetRegistrarsService.actions.should eql GetRegistrarsInterface.actions
12
+ end
13
+
14
+ end
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.0.1
4
+ version: 2.1.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-29 00:00:00.000000000 +04:00
12
+ date: 2011-09-30 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: &18303280 !ruby/object:Gem::Requirement
17
+ requirement: &12517640 !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: *18303280
25
+ version_requirements: *12517640
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
- requirement: &18295660 !ruby/object:Gem::Requirement
28
+ requirement: &12516520 !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: *18295660
36
+ version_requirements: *12516520
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: i18n
39
- requirement: &18241960 !ruby/object:Gem::Requirement
39
+ requirement: &12514240 !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: *18241960
47
+ version_requirements: *12514240
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rspec
50
- requirement: &18238220 !ruby/object:Gem::Requirement
50
+ requirement: &12512980 !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: *18238220
58
+ version_requirements: *12512980
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: yard
61
- requirement: &18227840 !ruby/object:Gem::Requirement
61
+ requirement: &12511420 !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: *18227840
69
+ version_requirements: *12511420
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: bundler
72
- requirement: &18226600 !ruby/object:Gem::Requirement
72
+ requirement: &12510600 !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: *18226600
80
+ version_requirements: *12510600
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: jeweler
83
- requirement: &18223680 !ruby/object:Gem::Requirement
83
+ requirement: &12509700 !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: *18223680
91
+ version_requirements: *12509700
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: rcov
94
- requirement: &18221380 !ruby/object:Gem::Requirement
94
+ requirement: &12508820 !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: *18221380
102
+ version_requirements: *12508820
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
@@ -127,17 +127,16 @@ files:
127
127
  - lib/soybean/generators/interface_generator.rb
128
128
  - lib/soybean/generators/mapping_generator.rb
129
129
  - lib/soybean/generators/model_generator.rb
130
+ - lib/soybean/generators/model_spec_generator.rb
130
131
  - lib/soybean/generators/service_generator.rb
132
+ - lib/soybean/generators/templates/model_spec.rb
131
133
  - lib/soybean/generators/types_generator.rb
134
+ - lib/soybean/interface.rb
135
+ - lib/soybean/interface_builder.rb
132
136
  - lib/soybean/literal_mapping_registry_creator.rb
133
137
  - soybean.gemspec
134
- - spec/services/interfaces/get_registrars_interface.rb
135
- - spec/services/mappings/base.rb
136
- - spec/services/mappings/get_registrars.rb
137
- - spec/services/models/get_registrars_service.rb
138
- - spec/services/types/get_registrars.rb
139
- - spec/services/types/type.rb
140
138
  - spec/soybean_spec.rb
139
+ - spec/spec/services/models/get_registrars_service.rb
141
140
  - spec/spec_helper.rb
142
141
  - vendor/soap4r/soap/attachment.rb
143
142
  - vendor/soap4r/soap/attrproxy.rb
@@ -314,7 +313,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
314
313
  version: '0'
315
314
  segments:
316
315
  - 0
317
- hash: 4352177832362837691
316
+ hash: -1435385047002182519
318
317
  required_rubygems_version: !ruby/object:Gem::Requirement
319
318
  none: false
320
319
  requirements: