# File lib/mysql_expectations/table.rb, line 78 def primary_key? key?('PRIMARY') end
class MySQLExpectations::Table
Allows assertions on a table
Public Class Methods
new(table_element)
click to toggle source
# File lib/mysql_expectations/table.rb, line 12 def initialize(table_element) @table_element = table_element end
Public Instance Methods
collation()
click to toggle source
# File lib/mysql_expectations/table.rb, line 63 def collation options = @table_element.elements['options'] options.attributes['Collation'] if options end
collation?(expected_collation)
click to toggle source
# File lib/mysql_expectations/table.rb, line 68 def collation?(expected_collation) collation == expected_collation end
Also aliased as: has_collation?
engine_type()
click to toggle source
# File lib/mysql_expectations/table.rb, line 52 def engine_type options = @table_element.elements['options'] options.attributes['Engine'] if options end
engine_type?(expected_engine_type)
click to toggle source
# File lib/mysql_expectations/table.rb, line 57 def engine_type?(expected_engine_type) engine_type == expected_engine_type end
Also aliased as: has_engine_type?
field(name)
click to toggle source
# File lib/mysql_expectations/table.rb, line 27 def field(name) query = "field[@Field='#{name}']" field_element = @table_element.elements[query] Field.new field_element if field_element end
field?(expected_field)
click to toggle source
# File lib/mysql_expectations/table.rb, line 20 def field?(expected_field) query = "field[@Field='#{expected_field}']" !@table_element.elements[query].nil? end
Also aliased as: has_field?
fields()
click to toggle source
# File lib/mysql_expectations/table.rb, line 33 def fields query = 'field' fields = [] @table_element.elements.each(query) do |field_element| fields << Field.new(field_element) end fields end
key(key_name)
click to toggle source
# File lib/mysql_expectations/table.rb, line 82 def key(key_name) Key.load_key(@table_element, key_name) end
key?(key_name)
click to toggle source
# File lib/mysql_expectations/table.rb, line 74 def key?(key_name) Key.key?(@table_element, key_name) end
keys()
click to toggle source
# File lib/mysql_expectations/table.rb, line 86 def keys Key.load_all_keys(@table_element) end
method_missing(method, *arguments, &block)
click to toggle source
Calls superclass method
# File lib/mysql_expectations/table.rb, line 90 def method_missing(method, *arguments, &block) if arguments.empty? && block.nil? name = method.to_s return field(name) if field?(name) end super end
name()
click to toggle source
# File lib/mysql_expectations/table.rb, line 16 def name @table_element.attributes['name'] end
option?(expected_options)
click to toggle source
# File lib/mysql_expectations/table.rb, line 42 def option?(expected_options) options = @table_element.elements['options'] expected_options.each do |expected_key, expected_value| value = options.attributes[expected_key] return false if value.nil? || value != expected_value end end
Also aliased as: has_option?
primary_key?()
click to toggle source
respond_to_missing?(method, *)
click to toggle source
Calls superclass method
# File lib/mysql_expectations/table.rb, line 98 def respond_to_missing?(method, *) field?(method.to_s) || super end