Class: DBD4::DBD4ModelFile

Inherits:
Object
  • Object
show all
Defined in:
lib/dbd4/dbd4_model_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ DBD4ModelFile

Returns a new instance of DBD4ModelFile.

Raises:



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, messages[:errors].join("\n") if @messages[:errors].size > 0
end

Instance Attribute Details

#dbmodelxmlObject (readonly)

Returns the value of attribute dbmodelxml.



38
39
40
# File 'lib/dbd4/dbd4_model_file.rb', line 38

def dbmodelxml
  @dbmodelxml
end

#fileObject (readonly)

Returns the value of attribute file.



38
39
40
# File 'lib/dbd4/dbd4_model_file.rb', line 38

def file
  @file
end

#generalDatatypesObject (readonly)

Returns the value of attribute generalDatatypes.



38
39
40
# File 'lib/dbd4/dbd4_model_file.rb', line 38

def generalDatatypes
  @generalDatatypes
end

#messagesObject (readonly)

Returns the value of attribute messages.



38
39
40
# File 'lib/dbd4/dbd4_model_file.rb', line 38

def messages
  @messages
end

#relationsObject (readonly)

Returns the value of attribute relations.



38
39
40
# File 'lib/dbd4/dbd4_model_file.rb', line 38

def relations
  @relations
end

#tablesObject (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

#generateModelFilesObject



77
78
79
# File 'lib/dbd4/dbd4_model_file.rb', line 77

def generateModelFiles
  @tables.generateModelFiles
end

#to_strObject



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

#validateObject



73
74
75
# File 'lib/dbd4/dbd4_model_file.rb', line 73

def validate
  @tables.each_value { |t| t.validate(@messages) }
end