Class: DBD4::DBD4ModelFile
- Inherits:
-
Object
- Object
- DBD4::DBD4ModelFile
- Defined in:
- lib/dbd4/dbd4_model_file.rb
Instance Attribute Summary collapse
-
#dbmodelxml ⇒ Object
readonly
Returns the value of attribute dbmodelxml.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#generalDatatypes ⇒ Object
readonly
Returns the value of attribute generalDatatypes.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#relations ⇒ Object
readonly
Returns the value of attribute relations.
-
#tables ⇒ Object
readonly
Returns the value of attribute tables.
Instance Method Summary collapse
- #generateModelFiles ⇒ Object
-
#initialize(file) ⇒ DBD4ModelFile
constructor
A new instance of DBD4ModelFile.
- #to_str ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(file) ⇒ DBD4ModelFile
Returns a new instance of DBD4ModelFile.
40 41 42 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 |
# File 'lib/dbd4/dbd4_model_file.rb', line 40 def initialize(file) @messages = { :errors => [], :warnings => [], :info => [] } @file = file @dbmodelxml = REXML::Document.new(File.open(file)) @allObjects = { :tables => Tables.new, :relations => Relations.new, :datatypeDefinitions => DatatypeDefinitions.new } dbmodelxml.elements.each("//*[@ID]") do |e| case e.name when "DATATYPE" @allObjects[:datatypeDefinitions] << DatatypeDefinition.new(e) when "TABLE" @allObjects[:tables] << Table.new(e) when "COLUMN" @allObjects[:tables].last.addColumnFromXml(e) when "RELATION_START" @allObjects[:tables].last.addStartRelation(RelationID.new(e)) when "RELATION_END" @allObjects[:tables].last.addEndRelation(RelationID.new(e)) when "RELATION" @allObjects[:relations] << Relation.new(e) end end @allObjects[:relations].resolve(@allObjects) @allObjects[:tables].resolve(@allObjects) @tables = @allObjects[:tables] validate raise DBD4Error, [:errors].join("\n") if @messages[:errors].size > 0 end |
Instance Attribute Details
#dbmodelxml ⇒ Object (readonly)
Returns the value of attribute dbmodelxml.
38 39 40 |
# File 'lib/dbd4/dbd4_model_file.rb', line 38 def dbmodelxml @dbmodelxml end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
38 39 40 |
# File 'lib/dbd4/dbd4_model_file.rb', line 38 def file @file end |
#generalDatatypes ⇒ Object (readonly)
Returns the value of attribute generalDatatypes.
38 39 40 |
# File 'lib/dbd4/dbd4_model_file.rb', line 38 def generalDatatypes @generalDatatypes end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
38 39 40 |
# File 'lib/dbd4/dbd4_model_file.rb', line 38 def @messages end |
#relations ⇒ Object (readonly)
Returns the value of attribute relations.
38 39 40 |
# File 'lib/dbd4/dbd4_model_file.rb', line 38 def relations @relations end |
#tables ⇒ Object (readonly)
Returns the value of attribute tables.
38 39 40 |
# File 'lib/dbd4/dbd4_model_file.rb', line 38 def tables @tables end |
Instance Method Details
#generateModelFiles ⇒ Object
77 78 79 |
# File 'lib/dbd4/dbd4_model_file.rb', line 77 def generateModelFiles @tables.generateModelFiles end |
#to_str ⇒ Object
81 82 83 |
# File 'lib/dbd4/dbd4_model_file.rb', line 81 def to_str "DBModelFile(file=#{File.basename(file)})\n" + @tables.to_str + "\n" end |
#validate ⇒ Object
73 74 75 |
# File 'lib/dbd4/dbd4_model_file.rb', line 73 def validate @tables.each_value { |t| t.validate(@messages) } end |