Class: XSD::CodeGen::ClassDef

Inherits:
ModuleDef show all
Includes:
GenSupport
Defined in:
lib/xsd/codegen/classdef.rb

Instance Attribute Summary

Attributes included from CommentDef

#comment

Instance Method Summary collapse

Methods included from GenSupport

#capitalize, #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.



21
22
23
24
25
26
# File 'lib/xsd/codegen/classdef.rb', line 21

def initialize(name, baseclass = nil)
  super(name)
  @baseclass = baseclass
  @classvar = []
  @attrdef = []
end

Instance Method Details

#def_attr(attrname, writable = true, varname = nil) ⇒ Object



36
37
38
39
40
41
# File 'lib/xsd/codegen/classdef.rb', line 36

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



28
29
30
31
32
33
34
# File 'lib/xsd/codegen/classdef.rb', line 28

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

#dumpObject



43
44
45
46
47
48
49
50
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
# File 'lib/xsd/codegen/classdef.rb', line 43

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 << dump_comment 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 @code.empty?
    buf << dump_emptyline if spacer
    spacer = true
    buf << dump_code
  end
  unless @attrdef.empty?
    buf << dump_emptyline if spacer
    spacer = true
    buf << dump_attributes
  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