class DSLParser
Constants
- NULL
Attributes
commands[RW]
Public Class Methods
new()
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 24 def initialize @tables = {} @tree_nodes = [ExpectationTreeNode.new('->')] @files_loaded = Set.new @commands = [] end
Public Instance Methods
expectation_tree()
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 31 def expectation_tree @tree_nodes.first end
parse(script)
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 35 def parse(script) instance_eval(script) end
tables()
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 39 def tables @tables.values end
Protected Instance Methods
__add_rows(table, row_method, row_columns, rows)
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 92 def __add_rows(table, row_method, row_columns, rows) rows.collect do |row_values| wrapped = row_values.map {|v| wrap(v) } table.send(row_method,Hash[ row_columns.zip(wrapped)]) end end
__set_defaults(table, method, columns)
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 78 def __set_defaults(table, method, columns) columns.each do |col, value| table.send(method, col, wrap(value)) end end
all_tables(col_values)
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 99 def all_tables(col_values) col_values.each do |col,value| @tables.each {|x,t| t.set_default(col, wrap(value)) } end end
defaults_for(table, columns)
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 70 def defaults_for(table, columns) __set_defaults(table,:set_default,columns) end
describe(description,&block)
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 63 def describe(description,&block) new_node = @tree_nodes.last.create_child(description) @tree_nodes << new_node instance_eval(&block) @tree_nodes.pop end
dirty(table)
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 55 def dirty(table) table.dirty = true end
etl_run_command(command)
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 51 def etl_run_command(command) @commands << command end
expect_rows(table, row_columns, rows)
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 88 def expect_rows(table, row_columns, rows) @tree_nodes.last.add __add_rows(table, :add_expected_row, row_columns, rows) end
expect_total_rows(table, count)
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 59 def expect_total_rows(table, count) @tree_nodes.last.add([table.row_count_check(count)]) end
expected_defaults(table, columns)
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 74 def expected_defaults(table, columns) __set_defaults(table,:set_expected_default,columns) end
insert_into(table,row_columns,rows)
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 84 def insert_into(table,row_columns,rows) __add_rows(table, :add_fixture_row, row_columns, rows) end
null()
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 110 def null; DbNull.new; end
requires(file)
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 44 def requires(file) unless @files_loaded.include?(file) instance_eval(File.read(file)) end @files_loaded << file end
table(db_name,schema,tablename)
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 105 def table(db_name,schema,tablename) @tables[db_name.to_s + schema.to_s + tablename.to_s] ||= Table.new(db_name,schema,tablename) end
wrap(val)
click to toggle source
# File lib/dbexpect/d_s_l_parser.rb, line 112 def wrap(val) case val when DbSequence val when DbNull val when nil NULL else DbString.new(val) end end