Class: XSD::CodeGen::ClassDef
Instance Attribute Summary
Attributes inherited from ModuleDef
#innermodule, #name
Attributes included from CommentDef
#comment
Instance Method Summary
collapse
Methods included from GenSupport
capitalize, constant?, #format, keyword?, safeconstname, safeconstname?, safemethodname, safemethodname?, safevarname, safevarname?, uncapitalize
Methods inherited from ModuleDef
#add_method, #def_code, #def_const, #def_method, #def_privatemethod, #def_protectedmethod, #def_require
Constructor Details
#initialize(name, baseclass = nil) ⇒ ClassDef
Returns a new instance of ClassDef.
22
23
24
25
26
27
28
|
# File 'lib/xsd/codegen/classdef.rb', line 22
def initialize(name, baseclass = nil)
super(name)
@baseclass = baseclass
@classvar = []
@attrdef = []
@included_files = []
end
|
Instance Method Details
#def_attr(attrname, writable = true, varname = nil) ⇒ Object
38
39
40
41
42
43
|
# File 'lib/xsd/codegen/classdef.rb', line 38
def def_attr(attrname, writable = true, varname = nil)
unless safevarname?(varname || attrname)
raise ArgumentError.new("#{varname || attrname} seems to be unsafe")
end
@attrdef << [attrname, writable, varname]
end
|
#def_classvar(var, value) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/xsd/codegen/classdef.rb', line 30
def def_classvar(var, value)
var = var.sub(/\A@@/, "")
unless safevarname?(var)
raise ArgumentError.new("#{var} seems to be unsafe")
end
@classvar << [var, value]
end
|
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
|
# File 'lib/xsd/codegen/classdef.rb', line 51
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_class_def
spacer = false
unless @classvar.empty?
spacer = true
buf << dump_classvar
end
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 @included_files.empty?
buf << dump_emptyline if spacer
spacer = true
buf << dump_include_file
end
unless @attrdef.empty?
buf << dump_emptyline if spacer
spacer = true
buf << dump_attributes
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_class_def_end
buf << dump_package_def_end(package) unless package.empty?
buf.gsub(/^\s+$/, '')
end
|
#include_files_in_class(files) ⇒ Object
45
46
47
|
# File 'lib/xsd/codegen/classdef.rb', line 45
def include_files_in_class(files)
@included_files << files
end
|