Class: Delphin::RelationsFile
- Inherits:
-
Hash
- Object
- Hash
- Delphin::RelationsFile
- Defined in:
- lib/delphin.rb
Overview
A file that contains a set of database schema tables.
This object is a hash of ProfileTableSchema objects indexed by table name.
Instance Method Summary collapse
-
#initialize(file) ⇒ RelationsFile
constructor
A new instance of RelationsFile.
-
#to_s ⇒ Object
Print out a relations file.
Constructor Details
#initialize(file) ⇒ RelationsFile
Returns a new instance of RelationsFile.
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/delphin.rb', line 337 def initialize(file) super() state = :outside_table table_name = nil file.each_with_index do |line,i| # Remove comments and surrounding whitespace. line.sub!(/#.*/, "") line.strip! case state when :inside_table if line.empty? state = :outside_table elsif line =~ /^(\S+)\s+:(\w+)(\s+:key)?(\s+:partial)?$/ # E.g. parse-id :integer :key field, type = line.split self[table_name].add_field($1, $2, !$3.nil?, !$4.nil?) else raise InvalidRelationsFile.new(filename, i+1, line) end when :outside_table next if line.empty? if line =~ /(\S+):/ # E.g. item: table_name = $1 self[table_name] = ProfileTableSchema.new(table_name) state = :inside_table else raise InvalidRelationsFile.new(filename, i+1, line) end end end # each_with_index end |
Instance Method Details
#to_s ⇒ Object
Print out a relations file
371 372 373 |
# File 'lib/delphin.rb', line 371 def to_s values.map {|t| t.to_s}.join("\n\n") end |