Class: FlattenDB::MySQL

Inherits:
Base
  • Object
show all
Defined in:
lib/flattendb/types/mysql.rb

Constant Summary collapse

JOIN_KEY =
:@key

Constants inherited from Base

Base::BUILDER_OPTIONS, Base::ELEMENT_CHARS, Base::ELEMENT_START

Instance Attribute Summary collapse

Attributes inherited from Base

#config, #input, #output, #root

Instance Method Summary collapse

Methods inherited from Base

[], to_flat!, types

Constructor Details

#initialize(options) ⇒ MySQL

Returns a new instance of MySQL.



43
44
45
46
47
48
# File 'lib/flattendb/types/mysql.rb', line 43

def initialize(options)
  super

  @type = options[:type] || :xml
  @name, @tables = parse
end

Instance Attribute Details

#builderObject (readonly)

Returns the value of attribute builder.



41
42
43
# File 'lib/flattendb/types/mysql.rb', line 41

def builder
  @builder
end

#nameObject (readonly)

Returns the value of attribute name.



41
42
43
# File 'lib/flattendb/types/mysql.rb', line 41

def name
  @name
end

#tablesObject (readonly)

Returns the value of attribute tables.



41
42
43
# File 'lib/flattendb/types/mysql.rb', line 41

def tables
  @tables
end

#typeObject (readonly)

Returns the value of attribute type.



41
42
43
# File 'lib/flattendb/types/mysql.rb', line 41

def type
  @type
end

Instance Method Details

#flatten!(options = {}) ⇒ Object



54
55
56
57
# File 'lib/flattendb/types/mysql.rb', line 54

def flatten!(options = {})
  flatten_tables!(tables, root, config)
  self
end

#parse(tables = {}) ⇒ Object



50
51
52
# File 'lib/flattendb/types/mysql.rb', line 50

def parse(tables = {})
  [send("parse_#{type}", tables) || 'root', tables]
end

#to_xml(output = output, builder_options = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/flattendb/types/mysql.rb', line 59

def to_xml(output = output, builder_options = {})
  initialize_builder(:xml, output, builder_options)

  builder.instruct!

  if tables.size > 1
    builder.tag!(name) {
      tables.sort.each { |table, rows| table_to_xml(table, rows, builder) }
    }
  else
    table_to_xml(name, tables.values.first, builder)
  end

  self
end