Class: MySQLExpectations::Table
- Inherits:
-
Object
- Object
- MySQLExpectations::Table
show all
- Defined in:
- lib/mysql_expectations/table.rb
Overview
Allows assertions on a table
Instance Method Summary
collapse
Constructor Details
#initialize(table_element) ⇒ Table
Returns a new instance of Table.
12
13
14
|
# File 'lib/mysql_expectations/table.rb', line 12
def initialize(table_element)
@table_element = table_element
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
90
91
92
93
94
95
96
|
# 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
|
Instance Method Details
#collation ⇒ Object
63
64
65
66
|
# File 'lib/mysql_expectations/table.rb', line 63
def collation
options = @table_element.elements['options']
options.attributes['Collation'] if options
end
|
#collation?(expected_collation) ⇒ Boolean
Also known as:
has_collation?
68
69
70
|
# File 'lib/mysql_expectations/table.rb', line 68
def collation?(expected_collation)
collation == expected_collation
end
|
#engine_type ⇒ Object
52
53
54
55
|
# 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) ⇒ Boolean
Also known as:
has_engine_type?
57
58
59
|
# File 'lib/mysql_expectations/table.rb', line 57
def engine_type?(expected_engine_type)
engine_type == expected_engine_type
end
|
#field(name) ⇒ Object
27
28
29
30
31
|
# 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) ⇒ Boolean
Also known as:
has_field?
20
21
22
23
|
# File 'lib/mysql_expectations/table.rb', line 20
def field?(expected_field)
query = "field[@Field='#{expected_field}']"
!@table_element.elements[query].nil?
end
|
#fields ⇒ Object
33
34
35
36
37
38
39
40
|
# 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) ⇒ Object
82
83
84
|
# File 'lib/mysql_expectations/table.rb', line 82
def key(key_name)
Key.load_key(@table_element, key_name)
end
|
#key?(key_name) ⇒ Boolean
74
75
76
|
# File 'lib/mysql_expectations/table.rb', line 74
def key?(key_name)
Key.key?(@table_element, key_name)
end
|
#keys ⇒ Object
86
87
88
|
# File 'lib/mysql_expectations/table.rb', line 86
def keys
Key.load_all_keys(@table_element)
end
|
#name ⇒ Object
16
17
18
|
# File 'lib/mysql_expectations/table.rb', line 16
def name
@table_element.attributes['name']
end
|
#option?(expected_options) ⇒ Boolean
Also known as:
has_option?
42
43
44
45
46
47
48
|
# 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
|
#primary_key? ⇒ Boolean
78
79
80
|
# File 'lib/mysql_expectations/table.rb', line 78
def primary_key?
key?('PRIMARY')
end
|
#respond_to_missing?(method) ⇒ Boolean
98
99
100
|
# File 'lib/mysql_expectations/table.rb', line 98
def respond_to_missing?(method, *)
field?(method.to_s) || super
end
|