Class: SchemaPlus::Core::SchemaDump::Table

Inherits:
Struct
  • Object
show all
Defined in:
lib/schema_plus/core/schema_dump.rb

Defined Under Namespace

Classes: Column, Index

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Table

Returns a new instance of Table.



50
51
52
53
54
55
56
# File 'lib/schema_plus/core/schema_dump.rb', line 50

def initialize(*args)
  super
  self.columns ||= []
  self.indexes ||= []
  self.statements ||= []
  self.trailer ||= []
end

Instance Attribute Details

#altObject

Returns the value of attribute alt

Returns:

  • the current value of alt



48
49
50
# File 'lib/schema_plus/core/schema_dump.rb', line 48

def alt
  @alt
end

#columnsObject

Returns the value of attribute columns

Returns:

  • the current value of columns



48
49
50
# File 'lib/schema_plus/core/schema_dump.rb', line 48

def columns
  @columns
end

#indexesObject

Returns the value of attribute indexes

Returns:

  • the current value of indexes



48
49
50
# File 'lib/schema_plus/core/schema_dump.rb', line 48

def indexes
  @indexes
end

#nameObject

Returns the value of attribute name

Returns:

  • the current value of name



48
49
50
# File 'lib/schema_plus/core/schema_dump.rb', line 48

def name
  @name
end

#optionsObject

Returns the value of attribute options

Returns:

  • the current value of options



48
49
50
# File 'lib/schema_plus/core/schema_dump.rb', line 48

def options
  @options
end

#pnameObject

Returns the value of attribute pname

Returns:

  • the current value of pname



48
49
50
# File 'lib/schema_plus/core/schema_dump.rb', line 48

def pname
  @pname
end

#statementsObject

Returns the value of attribute statements

Returns:

  • the current value of statements



48
49
50
# File 'lib/schema_plus/core/schema_dump.rb', line 48

def statements
  @statements
end

#trailerObject

Returns the value of attribute trailer

Returns:

  • the current value of trailer



48
49
50
# File 'lib/schema_plus/core/schema_dump.rb', line 48

def trailer
  @trailer
end

Instance Method Details

#assemble(stream) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/schema_plus/core/schema_dump.rb', line 58

def assemble(stream)
  if pname.nil?
    stream.puts alt
    stream.puts ""
    return
  end
  stream.write "  create_table #{pname.inspect}"
  stream.write ", #{options}" unless options.blank?
  stream.puts " do |t|"
  typelen = columns.map{|col| col.type.length}.max
  namelen = columns.map{|col| col.name.length}.max
  indexes
  columns.each do |column|
    stream.write "    "
    column.assemble(stream, typelen, namelen)
    stream.puts ""
  end
  stream.puts "" unless indexes.empty?
  indexes.each do |index|
    stream.write "    t.index "
    index.assemble(stream)
    stream.puts ""
  end
  statements.each do |statement|
    stream.puts "    #{statement}"
  end
  stream.puts "  end"
  trailer.each do |statement|
    stream.puts "  #{statement}"
  end
  stream.puts ""
end