troelskn-handsoap 0.2.8 → 0.2.9

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.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :patch: 8
3
2
  :major: 0
4
3
  :minor: 2
4
+ :patch: 9
@@ -13,29 +13,44 @@ class HandsoapGenerator < Rails::Generator::Base
13
13
  # Wsdl argument is required.
14
14
  usage if @args.empty?
15
15
  @wsdl_uri = @args.shift
16
+ @basename = @args.shift
16
17
  end
17
18
 
19
+ # def add_options!(opt)
20
+ # opt.on('--soap-actions') { |value| options[:soap_actions] = true }
21
+ # opt.on('--no-soap-actions') { |value| options[:soap_actions] = false }
22
+ # end
23
+
18
24
  def banner
19
- "Generates the scaffold for a Handsoap binding."+
25
+ "Generates the scaffold for a Handsoap binding." +
20
26
  "\n" + "You still have to fill in most of the meat, but this gives you a head start." +
21
- "\n" + "Usage: #{$0} #{spec.name} URI" +
22
- "\n" + " URI URI of the WSDL to generate from"
27
+ "\n" + "Usage: #{$0} #{spec.name} URI [BASENAME] [OPTIONS]" +
28
+ "\n" + " URI URI of the WSDL to generate from" +
29
+ "\n" + " BASENAME The basename to use for the service. If omitted, the name will be deducted from the URL." +
30
+ # "\n" +
31
+ # "\n" + "The following options are available:" +
32
+ # "\n" + " --soap-actions If set, stubs will be generated with soap-action parameters. (Default)" +
33
+ # "\n" + " --no-soap-actions If set, stubs will be generated without soap-action parameters." +
34
+ # "\n" + " --soap-version-1 If set, the generator will look for SOAP v 1.1 endpoints." +
35
+ # "\n" + " --soap-version-2 If set, the generator will look for SOAP v 1.2 endpoints." +
36
+ ""
23
37
  end
24
38
 
25
39
  def manifest
26
40
  wsdl = Handsoap::Parser::Wsdl.read(@wsdl_uri)
41
+ compiler = Handsoap::Compiler.new(wsdl, @basename)
27
42
  protocol = wsdl.preferred_protocol
28
- file_name = Handsoap::Compiler.service_basename(wsdl)
43
+ file_name = compiler.service_basename
29
44
  record do |m|
30
45
  m.directory "app"
31
46
  m.directory "app/models"
32
47
  m.file_contents "app/models/#{file_name}_service.rb" do |file|
33
- file.write Handsoap::Compiler.compile_service(wsdl, protocol, :soap_actions)
48
+ file.write compiler.compile_service(protocol, :soap_actions)
34
49
  end
35
50
  m.directory "test"
36
51
  m.directory "test/integration"
37
52
  m.file_contents "test/integration/#{file_name}_service_test.rb" do |file|
38
- file.write Handsoap::Compiler.compile_test(wsdl, protocol)
53
+ file.write compiler.compile_test(protocol)
39
54
  end
40
55
  # TODO
41
56
  # Ask user about which endpoints to use ?
@@ -45,7 +60,7 @@ class HandsoapGenerator < Rails::Generator::Base
45
60
  out.puts " You should copy these to the appropriate environment files."
46
61
  out.puts " (Eg. `config/environments/*.rb`)"
47
62
  out.puts "----"
48
- out.puts Handsoap::Compiler.compile_endpoints(wsdl, protocol)
63
+ out.puts compiler.compile_endpoints(protocol)
49
64
  out.puts "----"
50
65
  end
51
66
  end
@@ -1,6 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  module Handsoap
3
- module Compiler
4
3
  class CodeWriter
5
4
 
6
5
  def initialize
@@ -36,13 +35,25 @@ module Handsoap
36
35
  end
37
36
  end
38
37
 
39
- def self.write
38
+ class Compiler
39
+
40
+ def initialize(wsdl, basename = nil)
41
+ @wsdl = wsdl
42
+ if basename
43
+ @basename = basename.gsub(/[^a-zA-Z0-9]/, "_").gsub(/_+/, "_").gsub(/(^_+|_+$)/, '')
44
+ else
45
+ @basename = @wsdl.service
46
+ end
47
+ @basename = underscore(@basename).gsub(/_service$/, "")
48
+ end
49
+
50
+ def write
40
51
  writer = CodeWriter.new
41
52
  yield writer
42
53
  writer.to_s
43
54
  end
44
55
 
45
- def self.underscore(camel_cased_word)
56
+ def underscore(camel_cased_word)
46
57
  camel_cased_word.to_s.gsub(/::/, '/').
47
58
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
48
59
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
@@ -50,7 +61,7 @@ module Handsoap
50
61
  downcase
51
62
  end
52
63
 
53
- def self.camelize(lower_case_and_underscored_word)
64
+ def camelize(lower_case_and_underscored_word)
54
65
  lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) {
55
66
  "::" + $1.upcase
56
67
  }.gsub(/(^|_)(.)/) {
@@ -58,7 +69,7 @@ module Handsoap
58
69
  }
59
70
  end
60
71
 
61
- def self.method_name(operation)
72
+ def method_name(operation)
62
73
  if operation.name.match /^(get|find|select|fetch)/i
63
74
  "#{underscore(operation.name)}"
64
75
  else
@@ -66,19 +77,19 @@ module Handsoap
66
77
  end
67
78
  end
68
79
 
69
- def self.service_basename(wsdl)
70
- underscore(wsdl.service).gsub(/_service$/, "")
80
+ def service_basename
81
+ @basename
71
82
  end
72
83
 
73
- def self.service_name(wsdl)
74
- camelize(service_basename(wsdl)) + "Service"
84
+ def service_name
85
+ camelize(service_basename) + "Service"
75
86
  end
76
87
 
77
- def self.endpoint_name(wsdl)
78
- "#{service_basename(wsdl).upcase}_SERVICE_ENDPOINT"
88
+ def endpoint_name
89
+ "#{service_basename.upcase}_SERVICE_ENDPOINT"
79
90
  end
80
91
 
81
- def self.detect_protocol(wsdl)
92
+ def detect_protocol
82
93
  if endpoints.select { |endpoint| endpoint.protocol == :soap12 }.any?
83
94
  :soap12
84
95
  elsif endpoints.select { |endpoint| endpoint.protocol == :soap11 }.any?
@@ -88,12 +99,12 @@ module Handsoap
88
99
  end
89
100
  end
90
101
 
91
- def self.compile_endpoints(wsdl, protocol)
102
+ def compile_endpoints(protocol)
92
103
  version = protocol == :soap12 ? 2 : 1
93
- wsdl.endpoints.select { |endpoint| endpoint.protocol == protocol }.map do |endpoint|
104
+ @wsdl.endpoints.select { |endpoint| endpoint.protocol == protocol }.map do |endpoint|
94
105
  write do |w|
95
- w.puts "# wsdl: #{wsdl.url}"
96
- w.begin "#{endpoint_name(wsdl)} = {"
106
+ w.puts "# wsdl: #{@wsdl.url}"
107
+ w.begin "#{endpoint_name} = {"
97
108
  w.puts ":uri => '#{endpoint.url}',"
98
109
  w.puts ":version => #{version}"
99
110
  w.end "}"
@@ -101,21 +112,21 @@ module Handsoap
101
112
  end
102
113
  end
103
114
 
104
- def self.compile_service(wsdl, protocol, *options)
105
- binding = wsdl.bindings.find { |b| b.protocol == protocol }
115
+ def compile_service(protocol, *options)
116
+ binding = @wsdl.bindings.find { |b| b.protocol == protocol }
106
117
  raise "Can't find binding for requested protocol (#{protocol})" unless binding
107
118
  write do |w|
108
119
  w.puts "# -*- coding: utf-8 -*-"
109
120
  w.puts "require 'handsoap'"
110
121
  w.puts
111
- w.begin "class #{service_name(wsdl)} < Handsoap::Service"
112
- w.puts "endpoint #{endpoint_name(wsdl)}"
122
+ w.begin "class #{service_name} < Handsoap::Service"
123
+ w.puts "endpoint #{endpoint_name}"
113
124
  w.begin "on_create_document do |doc|"
114
- w.puts "doc.alias 'tns', '#{wsdl.target_ns}'"
125
+ w.puts "doc.alias 'tns', '#{@wsdl.target_ns}'"
115
126
  w.end
116
127
  w.puts
117
128
  w.puts "# public methods"
118
- wsdl.interface.operations.each do |operation|
129
+ @wsdl.interface.operations.each do |operation|
119
130
  action = binding.actions.find { |a| a.name == operation.name }
120
131
  raise "Can't find action for operation #{operation.name}" unless action
121
132
  w.puts
@@ -140,20 +151,20 @@ module Handsoap
140
151
  end
141
152
  end
142
153
 
143
- def self.compile_test(wsdl, protocol)
144
- binding = wsdl.bindings.find { |b| b.protocol == protocol }
154
+ def compile_test(protocol)
155
+ binding = @wsdl.bindings.find { |b| b.protocol == protocol }
145
156
  raise "Can't find binding for requested protocol (#{protocol})" unless binding
146
157
  write do |w|
147
158
  w.puts "# -*- coding: utf-8 -*-"
148
159
  w.puts "require 'test_helper'"
149
160
  w.puts
150
- w.puts "# #{service_name(wsdl)}.logger = $stdout"
161
+ w.puts "# #{service_name}.logger = $stdout"
151
162
  w.puts
152
- w.begin "class #{service_name(wsdl)}Test < Test::Unit::TestCase"
153
- wsdl.interface.operations.each do |operation|
163
+ w.begin "class #{service_name}Test < Test::Unit::TestCase"
164
+ @wsdl.interface.operations.each do |operation|
154
165
  w.puts
155
166
  w.begin "def test_#{underscore(operation.name)}"
156
- w.puts "result = #{service_name(wsdl)}.#{method_name(operation)}"
167
+ w.puts "result = #{service_name}.#{method_name(operation)}"
157
168
  w.end
158
169
  end
159
170
  w.end
@@ -25,6 +25,9 @@ module Nokogiri
25
25
  class Nodeset
26
26
  include Utf8StringPatch
27
27
  end
28
+ class Attr
29
+ include Utf8StringPatch
30
+ end
28
31
  end
29
32
  end
30
33
 
@@ -188,18 +191,21 @@ module Handsoap
188
191
  return if n.nil?
189
192
  n.to_utf8
190
193
  end
194
+ alias_method :xml_to_s, :xml_to_str
191
195
  # Helper to serialize a node into a ruby integer
192
196
  def xml_to_int(node, xquery = nil)
193
197
  n = xquery ? node.xpath(xquery, ns).first : node
194
198
  return if n.nil?
195
199
  n.to_s.to_i
196
200
  end
201
+ alias_method :xml_to_i, :xml_to_int
197
202
  # Helper to serialize a node into a ruby float
198
203
  def xml_to_float(node, xquery = nil)
199
204
  n = xquery ? node.xpath(xquery, ns).first : node
200
205
  return if n.nil?
201
206
  n.to_s.to_f
202
207
  end
208
+ alias_method :xml_to_f, :xml_to_float
203
209
  # Helper to serialize a node into a ruby boolean
204
210
  def xml_to_bool(node, xquery = nil)
205
211
  n = xquery ? node.xpath(xquery, ns).first : node
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: troelskn-handsoap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Troels Knak-Nielsen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-16 00:00:00 -07:00
12
+ date: 2009-06-17 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency