module Tabl::Dsl::ClassMethods

Defines a dsl to create tables.

Public Instance Methods

column(name, args = {}, &block) click to toggle source
# File lib/tabl/dsl.rb, line 10
def column(name, args = {}, &block)
  columns_hash[name] = column = Column.new(name, args, &block)
  self.send(:define_method, name) { return column }
  singleton_class.send(:define_method, name) { return column }
end
columns() click to toggle source
# File lib/tabl/dsl.rb, line 16
def columns
  columns_hash.values
end
include_columns(mod, args = {}) click to toggle source

Includes column definitions. These column definitions will be available to any tables defined in the module.

module UserTables
  include Tabl::Dsl

  include_columns(UserColumns)
end
# File lib/tabl/dsl.rb, line 48
def include_columns(mod, args = {})
  mod.columns.each do |column|
    column = args[:record] ? DerefColumn.new(column, args[:record]) : column
    columns_hash[column.name] = column
  end
end
table(name, args = {}, &block) click to toggle source

Define a new table.

module UserTables
  include Tabl::Dsl

  table :users, [:name, :email, :phone]
end

MyTables.foo
  # => <Table name:foo>
# File lib/tabl/dsl.rb, line 29
def table(name, args = {}, &block)
  args[:base_columns] ||= columns
  table = Table.new(args, &block)
  tables << table
  singleton_class.send(:define_method, name) { return table }
end
tables() click to toggle source
# File lib/tabl/dsl.rb, line 36
def tables
  @tables ||= []
end

Private Instance Methods

columns_hash() click to toggle source
# File lib/tabl/dsl.rb, line 57
def columns_hash
  @columns_hash ||= {}
end