Class: SybaseDefinitions::Table
- Inherits:
-
Object
- Object
- SybaseDefinitions::Table
- Defined in:
- lib/marjoree/sybase_definitions.rb
Instance Method Summary collapse
- #contains_columns?(list_of_expected_columns_definitions) ⇒ Boolean
- #contains_data?(map) ⇒ Boolean
- #does_not_contain_data?(map) ⇒ Boolean
- #exists? ⇒ Boolean
- #has_dropped_index?(column_name) ⇒ Boolean
- #has_index?(index_name) ⇒ Boolean
- #has_primary_key_on?(column_name) ⇒ Boolean
- #has_row_count?(expected_count) ⇒ Boolean
-
#initialize(table_name) ⇒ Table
constructor
A new instance of Table.
- #is_referenced_by_foreign_key?(referring_table, column_name) ⇒ Boolean
Constructor Details
#initialize(table_name) ⇒ Table
Returns a new instance of Table.
49 50 51 52 |
# File 'lib/marjoree/sybase_definitions.rb', line 49 def initialize( table_name ) @table_name = table_name #puts $connection.columns( @table_name ).columns.each_hash{ |key,value| puts "Key: #{key}, value: #{value}"} end |
Instance Method Details
#contains_columns?(list_of_expected_columns_definitions) ⇒ Boolean
74 75 76 77 78 |
# File 'lib/marjoree/sybase_definitions.rb', line 74 def contains_columns?( list_of_expected_columns_definitions ) list_of_expected_columns_definitions.each do |expected_column| contains_column?( expected_column.to_hash ) end end |
#contains_data?(map) ⇒ Boolean
58 59 60 61 62 63 64 |
# File 'lib/marjoree/sybase_definitions.rb', line 58 def contains_data?( map ) if( count( @table_name, map ) == 0 ) fail( "#{@table_name} does not contain data" ) end return true end |
#does_not_contain_data?(map) ⇒ Boolean
66 67 68 69 70 71 72 |
# File 'lib/marjoree/sybase_definitions.rb', line 66 def does_not_contain_data?( map ) if( count( @table_name, map ) != 0 ) fail( "#{@table_name} does contain data" ) end return true end |
#exists? ⇒ Boolean
54 55 56 |
# File 'lib/marjoree/sybase_definitions.rb', line 54 def exists? fail( "Table #{@table_name} does not exist" ) unless get_user_tables.include? @table_name end |
#has_dropped_index?(column_name) ⇒ Boolean
88 89 90 91 92 93 94 |
# File 'lib/marjoree/sybase_definitions.rb', line 88 def has_dropped_index?( column_name ) $db.indexes( @table_name ).each_hash do |map,value| fail "#{@table_name} does contain index '#{column_name}'" if map["INDEX_NAME"].eql?( column_name ) end return true end |
#has_index?(index_name) ⇒ Boolean
80 81 82 83 84 85 86 |
# File 'lib/marjoree/sybase_definitions.rb', line 80 def has_index?( index_name ) $db.indexes( @table_name ).each_hash do |map,value| return true if map["INDEX_NAME"].eql?( index_name ) end fail "#{@table_name} does not have index '#{index_name}'" end |
#has_primary_key_on?(column_name) ⇒ Boolean
96 97 98 99 100 101 102 |
# File 'lib/marjoree/sybase_definitions.rb', line 96 def has_primary_key_on?( column_name ) $db.primary_keys( @table_name ).each_hash do |map,value| return true if map["COLUMN_NAME"].eql?( column_name ) end fail "#{@table_name} does not have a primary key on '#{column_name}'" end |
#has_row_count?(expected_count) ⇒ Boolean
113 114 115 116 117 118 119 120 |
# File 'lib/marjoree/sybase_definitions.rb', line 113 def has_row_count?( expected_count ) actual_count = count( @table_name ) if( expected_count != count( @table_name ) ) fail( "Number of colums are not equal,\nExpected: #{expected_count}\nActual: #{actual_count}") end return self end |
#is_referenced_by_foreign_key?(referring_table, column_name) ⇒ Boolean
104 105 106 107 108 109 110 111 |
# File 'lib/marjoree/sybase_definitions.rb', line 104 def is_referenced_by_foreign_key?( referring_table, column_name ) $db.foreign_keys( @table_name ).each_hash do |map,value| #p map return true if (map["FKCOLUMN_NAME"].eql?( column_name ) && map["FKTABLE_NAME"].eql?( referring_table ) ) end fail "#{@table_name} does not have a foreign key on '#{column_name}'" end |