Class: Squirm::Migrator::Table
- Inherits:
-
Object
- Object
- Squirm::Migrator::Table
- Defined in:
- lib/squirm/migrator/table.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
Instance Method Summary collapse
- #add_column(*names) ⇒ Object
- #api ⇒ Object
-
#initialize(name) ⇒ Table
constructor
A new instance of Table.
- #quoted_name ⇒ Object
- #template ⇒ Object
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
#columns ⇒ Object (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 |
#api ⇒ Object
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.("../templates/sql/#{template}.sql.erb", __FILE__) Template.new erb, :table => self end end |
#quoted_name ⇒ Object
14 15 16 |
# File 'lib/squirm/migrator/table.rb', line 14 def quoted_name Squirm.quote_ident name end |