Module: Tabl::Dsl::ClassMethods
- Defined in:
- lib/tabl/dsl.rb
Overview
Defines a dsl to create tables.
Instance Method Summary collapse
- #column(name, args = {}, &block) ⇒ Object
- #columns ⇒ Object
-
#include_columns(mod, args = {}) ⇒ Object
Includes column definitions.
-
#table(name, args = {}, &block) ⇒ Object
Define a new table.
- #tables ⇒ Object
Instance Method Details
#column(name, args = {}, &block) ⇒ Object
10 11 12 13 14 |
# 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 ⇒ Object
16 17 18 |
# File 'lib/tabl/dsl.rb', line 16 def columns columns_hash.values end |
#include_columns(mod, args = {}) ⇒ Object
48 49 50 51 52 53 |
# 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) ⇒ Object
29 30 31 32 33 34 |
# 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 ⇒ Object
36 37 38 |
# File 'lib/tabl/dsl.rb', line 36 def tables @tables ||= [] end |