Class: MySQLExpectations::MySQL
- Inherits:
-
Object
- Object
- MySQLExpectations::MySQL
show all
- Defined in:
- lib/mysql_expectations/mysql.rb
Overview
The database_structure_file should be an XML file resulting from the mysqldump command:
mysqldump –xml –no-data –all-databases \
--host=#{env.host} --port=#{env.port} \
--user=#{env.username}
Instance Method Summary
collapse
Constructor Details
#initialize(source) ⇒ MySQL
Returns a new instance of MySQL.
17
18
19
|
# File 'lib/mysql_expectations/mysql.rb', line 17
def initialize(source)
@doc = REXML::Document.new(source)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *arguments, &block) ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/mysql_expectations/mysql.rb', line 43
def method_missing(method_sym, *arguments, &block)
if arguments.empty? && block.nil?
database_name = method_sym.to_s
return database(database_name) if database?(database_name)
end
super
end
|
Instance Method Details
#database(name) ⇒ Object
28
29
30
31
32
|
# File 'lib/mysql_expectations/mysql.rb', line 28
def database(name)
query = "mysqldump/database[@name='#{name}']"
database_element = @doc.elements[query]
Database.new database_element if database_element
end
|
#database?(name) ⇒ Boolean
Also known as:
has_database?
21
22
23
24
|
# File 'lib/mysql_expectations/mysql.rb', line 21
def database?(name)
query = "mysqldump/database[@name='#{name}']"
!@doc.elements[query].nil?
end
|
#databases ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/mysql_expectations/mysql.rb', line 34
def databases
query = 'mysqldump/database'
databases = []
@doc.elements.each(query) do |database_element|
databases << Database.new(database_element)
end
databases
end
|
#respond_to_missing?(method) ⇒ Boolean
51
52
53
|
# File 'lib/mysql_expectations/mysql.rb', line 51
def respond_to_missing?(method, *)
database?(method.to_s) || super
end
|