Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

root/trunk/lib/xsd/codegen/methoddef.rb

Revision 1824, 1.4 kB (checked in by nahi, 2 years ago)
  • Copyright notice updated. add '2000-2007' uniformly.
  • Property svn:eol-style set to native
  • Property svn:keywords set to author date id revision
Line 
1 # XSD4R - Generating method definition code
2 # Copyright (C) 2000-2007  NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
3
4 # This program is copyrighted free software by NAKAMURA, Hiroshi.  You can
5 # redistribute it and/or modify it under the same terms of Ruby's license;
6 # either the dual license version in 2003, or any later version.
7
8
9 require 'xsd/codegen/gensupport'
10 require 'xsd/codegen/commentdef'
11
12
13 module XSD
14 module CodeGen
15
16
17 class MethodDef
18   include GenSupport
19   include CommentDef
20
21   attr_accessor :definition
22
23   def initialize(name, *params)
24     klass, mname = name.split('.', 2)
25     if mname.nil?
26       mname, klass = klass, mname
27     end
28     unless safemethodname?(mname)
29       raise ArgumentError.new("name '#{name}' seems to be unsafe")
30     end
31     if klass and klass != 'self' and !safeconstname(klass)
32       raise ArgumentError.new("name '#{name}' seems to be unsafe")
33     end
34     @name = name
35     @params = params
36     @comment = nil
37     @definition = yield if block_given?
38   end
39
40   def dump
41     buf = ""
42     buf << dump_comment if @comment
43     buf << dump_method_def
44     buf << dump_definition if @definition and !@definition.empty?
45     buf << dump_method_def_end
46     buf
47   end
48
49 private
50
51   def dump_method_def
52     if @params.empty?
53       format("def #{@name}")
54     else
55       format("def #{@name}(#{@params.join(", ")})")
56     end
57   end
58
59   def dump_method_def_end
60     format("end")
61   end
62
63   def dump_definition
64     format(@definition, 2)
65   end
66 end
67
68
69 end
70 end
Note: See TracBrowser for help on using the browser.