Class: DBD4::Datatype
- Inherits:
-
Object
- Object
- DBD4::Datatype
- Defined in:
- lib/dbd4/dbd4_model_file.rb
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#non_standard_type ⇒ Object
readonly
Returns the value of attribute non_standard_type.
-
#notnull ⇒ Object
readonly
Returns the value of attribute notnull.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(datatype, column) ⇒ Datatype
constructor
A new instance of Datatype.
- #resolve(allObjects) ⇒ Object
- #to_str ⇒ Object
- #validate(messages) ⇒ Object
Constructor Details
#initialize(datatype, column) ⇒ Datatype
Returns a new instance of Datatype.
363 364 365 366 367 368 369 370 371 372 |
# File 'lib/dbd4/dbd4_model_file.rb', line 363 def initialize(datatype, column) @column = column @params = Hash.new() @id = datatype.attributes['idDatatype'] @param_values = datatype.attributes['DatatypeParams'].delete("()").split(/[,]/) @params = Hash.new() @type = nil @notnull = datatype.attributes['NotNull'] @non_standard_type = false end |
Instance Attribute Details
#column ⇒ Object (readonly)
Returns the value of attribute column.
361 362 363 |
# File 'lib/dbd4/dbd4_model_file.rb', line 361 def column @column end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
361 362 363 |
# File 'lib/dbd4/dbd4_model_file.rb', line 361 def id @id end |
#non_standard_type ⇒ Object (readonly)
Returns the value of attribute non_standard_type.
361 362 363 |
# File 'lib/dbd4/dbd4_model_file.rb', line 361 def non_standard_type @non_standard_type end |
#notnull ⇒ Object (readonly)
Returns the value of attribute notnull.
361 362 363 |
# File 'lib/dbd4/dbd4_model_file.rb', line 361 def notnull @notnull end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
361 362 363 |
# File 'lib/dbd4/dbd4_model_file.rb', line 361 def params @params end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
361 362 363 |
# File 'lib/dbd4/dbd4_model_file.rb', line 361 def type @type end |
Instance Method Details
#resolve(allObjects) ⇒ Object
374 375 376 377 378 379 |
# File 'lib/dbd4/dbd4_model_file.rb', line 374 def resolve(allObjects) dd = allObjects[:datatypeDefinitions][@id] # Create a Hash from 2 arrays by zipping them together @params = Hash[*dd.zip(@param_values).flatten] if ! @param_values.empty? @type = dd.type end |
#to_str ⇒ Object
443 444 445 |
# File 'lib/dbd4/dbd4_model_file.rb', line 443 def to_str "Datatype(type=#{type}, non_standard=#{non_standard_type}, notnull=#{notnull}" + params.keys.collect { |k| ", #{k}=#{params[k]}" }.join("") + ")" end |
#validate(messages) ⇒ Object
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/dbd4/dbd4_model_file.rb', line 381 def validate() case @type when 'BOOL' if @params.size != 0 [:warnings] << "Warning : table #{column.table.name} column #{column.name}, #{type} cannot take any parameters" @non_standard_type = true end when 'TEXT' if @params.size != 0 [:warnings] << "Warning : table #{column.table.name} column #{column.name}, #{type} cannot take any parameters" @non_standard_type = true end when 'VARCHAR' @params.each_key do |k| if k != 'length' [:warnings] << "Warning : table #{column.table.name} column #{column.name}, #{type} can only take length as parameter" @non_standard_type = true end end when 'FLOAT' if @params.size != 0 [:warnings] << "Warning : table #{column.table.name} column #{column.name}, #{type} cannot take any parameters" @non_standard_type = true end when 'DATETIME' if @params.size != 0 [:warnings] << "Warning : table #{column.table.name} column #{column.name}, #{type} cannot take any parameters" @non_standard_type = true end when 'DATE' if @params.size != 0 [:warnings] << "Warning : table #{column.table.name} column #{column.name}, #{type} cannot take any parameters" @non_standard_type = true end when 'INTEGER' @params.each_key do |k| if k != 'length' [:warnings] << "Warning : table #{column.table.name} column #{column.name}, #{type} can only take length as parameter" @non_standard_type = true end end when 'DECIMAL' if @params.size != 2 or not @params['length'] or not @params['decimals'] [:warnings] << "Warning : table #{column.table.name} column #{column.name}, #{type} takes 2 params, length and decimals" @non_standard_type = true end when 'BINARY' if @params.size != 0 [:warnings] << "Warning : table #{column.table.name} column #{column.name}, #{type} does not take any parameters" @non_standard_type = true end when 'BLOB' if @params.size != 0 [:warnings] << "Warning : table #{column.table.name} column #{column.name}, #{type} does not take any parameters" @non_standard_type = true end else [:warnings] << "Warning : table #{column.table.name} column #{column.name}, #{type} is not a valid type" @non_standard_type = true end end |