Class: XSD::CodeGen::ModuleDef
Instance Attribute Summary collapse
Attributes included from CommentDef
#comment
Instance Method Summary
collapse
Methods included from GenSupport
capitalize, constant?, #format, keyword?, safeconstname, safeconstname?, safemethodname, safemethodname?, safevarname, safevarname?, uncapitalize
Constructor Details
#initialize(name) ⇒ ModuleDef
Returns a new instance of ModuleDef.
26
27
28
29
30
31
32
33
34
|
# File 'lib/xsd/codegen/moduledef.rb', line 26
def initialize(name)
@name = name
@comment = nil
@const = []
@code = []
@requirepath = []
@methoddef = []
@innermodule = []
end
|
Instance Attribute Details
#innermodule ⇒ Object
Returns the value of attribute innermodule.
24
25
26
|
# File 'lib/xsd/codegen/moduledef.rb', line 24
def innermodule
@innermodule
end
|
Returns the value of attribute name.
23
24
25
|
# File 'lib/xsd/codegen/moduledef.rb', line 23
def name
@name
end
|
Instance Method Details
#add_method(m, visibility = :public) ⇒ Object
65
66
67
|
# File 'lib/xsd/codegen/moduledef.rb', line 65
def add_method(m, visibility = :public)
@methoddef << [visibility, m]
end
|
#def_code(code) ⇒ Object
47
48
49
|
# File 'lib/xsd/codegen/moduledef.rb', line 47
def def_code(code)
@code << code
end
|
#def_const(const, value) ⇒ Object
40
41
42
43
44
45
|
# File 'lib/xsd/codegen/moduledef.rb', line 40
def def_const(const, value)
unless safeconstname?(const)
raise ArgumentError.new("#{const} seems to be unsafe")
end
@const << [const, value]
end
|
#def_method(name, *params) ⇒ Object
Also known as:
def_publicmethod
51
52
53
|
# File 'lib/xsd/codegen/moduledef.rb', line 51
def def_method(name, *params)
add_method(MethodDef.new(name, *params) { yield if block_given? }, :public)
end
|
#def_privatemethod(name, *params) ⇒ Object
61
62
63
|
# File 'lib/xsd/codegen/moduledef.rb', line 61
def def_privatemethod(name, *params)
add_method(MethodDef.new(name, *params) { yield if block_given? }, :private)
end
|
#def_protectedmethod(name, *params) ⇒ Object
56
57
58
59
|
# File 'lib/xsd/codegen/moduledef.rb', line 56
def def_protectedmethod(name, *params)
add_method(MethodDef.new(name, *params) { yield if block_given? },
:protected)
end
|
#def_require(path) ⇒ Object
36
37
38
|
# File 'lib/xsd/codegen/moduledef.rb', line 36
def def_require(path)
@requirepath << path
end
|
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/xsd/codegen/moduledef.rb', line 69
def dump
buf = ""
unless @requirepath.empty?
buf << dump_requirepath
end
buf << dump_emptyline unless buf.empty?
package = @name.split(/::/)[0..-2]
buf << dump_package_def(package) unless package.empty?
buf << if @comment
buf << dump_module_def
spacer = false
unless @const.empty?
buf << dump_emptyline if spacer
spacer = true
buf << dump_const
end
unless @innermodule.empty?
buf << dump_emptyline spacer = true
buf << dump_innermodule
end
unless @code.empty?
buf << dump_emptyline if spacer
spacer = true
buf << dump_code
end
unless @methoddef.empty?
buf << dump_emptyline if spacer
spacer = true
buf << dump_methods
end
buf << dump_module_def_end
buf << dump_package_def_end(package) unless package.empty?
buf.gsub(/^\s+$/, '')
end
|