Class: Squirm::Migrator::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/squirm/migrator/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Table

Returns a new instance of Table.



9
10
11
12
# File 'lib/squirm/migrator/table.rb', line 9

def initialize(name)
  @name    = name
  @columns = []
end

Instance Attribute Details

#columnsObject (readonly)

Returns the value of attribute columns.



7
8
9
# File 'lib/squirm/migrator/table.rb', line 7

def columns
  @columns
end

Instance Method Details

#add_column(*names) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/squirm/migrator/table.rb', line 18

def add_column(*names)
  names.each do |name|
    column = Column.new(name)
    column.templates.map {|t| t.table = self}
    @columns << column
  end
  self
end

#apiObject



27
28
29
30
31
32
33
# File 'lib/squirm/migrator/table.rb', line 27

def api
  templates = ["schema", "api/get", "api/create", "api/update", "api/delete"]
  templates.map do |template|
    erb = File.read File.expand_path("../templates/sql/#{template}.sql.erb", __FILE__)
    Template.new erb, :table => self
  end
end

#quoted_nameObject



14
15
16
# File 'lib/squirm/migrator/table.rb', line 14

def quoted_name
  Squirm.quote_ident name
end

#templateObject



35
36
37
38
# File 'lib/squirm/migrator/table.rb', line 35

def template
  erb = File.read File.expand_path("../templates/sql/table.sql.erb", __FILE__)
  Template.new erb, :table => self, :column_padding => column_padding
end