Line | |
---|
1 | # XSD4R - Generating method definition code
|
---|
2 | # Copyright (C) 2004 NAKAMURA, Hiroshi <[email protected]>.
|
---|
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 | unless safemethodname?(name)
|
---|
25 | raise ArgumentError.new("name '#{name}' seems to be unsafe")
|
---|
26 | end
|
---|
27 | @name = name
|
---|
28 | @params = params
|
---|
29 | @comment = nil
|
---|
30 | @definition = yield if block_given?
|
---|
31 | end
|
---|
32 |
|
---|
33 | def dump
|
---|
34 | buf = ""
|
---|
35 | buf << dump_comment if @comment
|
---|
36 | buf << dump_method_def
|
---|
37 | buf << dump_definition if @definition and [email protected]?
|
---|
38 | buf << dump_method_def_end
|
---|
39 | buf
|
---|
40 | end
|
---|
41 |
|
---|
42 | private
|
---|
43 |
|
---|
44 | def dump_method_def
|
---|
45 | if @params.empty?
|
---|
46 | format("def #{@name}")
|
---|
47 | else
|
---|
48 | format("def #{@name}(#{@params.join(", ")})")
|
---|
49 | end
|
---|
50 | end
|
---|
51 |
|
---|
52 | def dump_method_def_end
|
---|
53 | format("end")
|
---|
54 | end
|
---|
55 |
|
---|
56 | def dump_definition
|
---|
57 | format(@definition, 2)
|
---|
58 | end
|
---|
59 | end
|
---|
60 |
|
---|
61 |
|
---|
62 | end
|
---|
63 | end
|
---|
Note:
See
TracBrowser
for help on using the repository browser.