Class: Lafcadio::ClassDefinitionXmlParser
- Inherits:
-
Object
- Object
- Lafcadio::ClassDefinitionXmlParser
show all
- Defined in:
- lib/lafcadio/domain.rb
Overview
Defined Under Namespace
Classes: FieldAttribute, InvalidDataError
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ClassDefinitionXmlParser.
60
61
62
63
64
|
# File 'lib/lafcadio/domain.rb', line 60
def initialize( domainClass, xml )
@domainClass = domainClass
@xmlDocRoot = REXML::Document.new( xml ).root
@namesProcessed = {}
end
|
Instance Method Details
#get_class_field(fieldElt) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/lafcadio/domain.rb', line 66
def get_class_field( fieldElt )
className = fieldElt.attributes['class'].to_s
name = fieldElt.attributes['name']
begin
fieldClass = Class.getClass( 'Lafcadio::' + className )
register_name( name )
field = fieldClass.instantiateFromXml( @domainClass, fieldElt )
possibleFieldAttributes.each { |fieldAttr|
fieldAttr.maybeSetFieldAttr( field, fieldElt )
}
rescue MissingError
msg = "Couldn't find field class '#{ className }' for field " +
"'#{ name }'"
raise( MissingError, msg, caller )
end
field
end
|
#getClassFields ⇒ Object
84
85
86
87
88
89
90
91
|
# File 'lib/lafcadio/domain.rb', line 84
def getClassFields
namesProcessed = {}
fields = []
@xmlDocRoot.elements.each('field') { |fieldElt|
fields << get_class_field( fieldElt )
}
fields
end
|
#possibleFieldAttributes ⇒ Object
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/lafcadio/domain.rb', line 106
def possibleFieldAttributes
fieldAttr = []
fieldAttr << FieldAttribute.new( 'size', FieldAttribute::INTEGER )
fieldAttr << FieldAttribute.new( 'unique', FieldAttribute::BOOLEAN )
fieldAttr << FieldAttribute.new( 'notNull', FieldAttribute::BOOLEAN )
fieldAttr << FieldAttribute.new( 'enumType', FieldAttribute::ENUM,
BooleanField )
fieldAttr << FieldAttribute.new( 'enums', FieldAttribute::HASH )
fieldAttr << FieldAttribute.new( 'range', FieldAttribute::ENUM,
DateField )
fieldAttr << FieldAttribute.new( 'large', FieldAttribute::BOOLEAN )
end
|
#register_name(name) ⇒ Object
93
94
95
96
|
# File 'lib/lafcadio/domain.rb', line 93
def register_name( name )
raise InvalidDataError if @namesProcessed[name]
@namesProcessed[name] = true
end
|
#sqlPrimaryKeyName ⇒ Object
98
99
100
|
# File 'lib/lafcadio/domain.rb', line 98
def sqlPrimaryKeyName
@xmlDocRoot.attributes['sqlPrimaryKeyName']
end
|
#tableName ⇒ Object
102
103
104
|
# File 'lib/lafcadio/domain.rb', line 102
def tableName
@xmlDocRoot.attributes['tableName']
end
|