Sha256: 899b681bfdac58a36fc71e8244922c7800421c163ff5c09ad0989c427619ff19

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

class Both
  include FromHash
  fattr(:objs) { [] }
  def method_missing(sym,*args,&b)
    objs.each { |x| x.send(sym,*args,&b) }
  end
end

class TableLoaderDSL
  fattr(:table_name) { loader.table_name }
  fattr(:loader) { TableLoader.new }
  fattr(:manager) { TableManager.new }
  fattr(:both) { Both.new(:objs => [loader,manager]) }
  def master
    MasterLoader.instance
  end
  def initialize(&b)
    @blk = b
    instance_eval(&@blk)
    master.add(self)
  end
  def column(name,type,&blk)
    blk ||= lambda { |x| x.send(name) }
    loader.columns << Column.new(:target_name => name, :blk => blk)
  end
  def method_missing(sym,*args,&b)
    if [:string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean].include?(sym)
      args.flatten.each { |x| column(x,sym,&b) }
    else
      super(sym,*args,&b)
    end
  end
  def source(file)
    loader.source_filename = file
  end
  def table(name)
    both.table_name = name
  end
  def run!
    manager.delete_rows! if @delete_existing_rows
    loader.load!
  end
  def delimiter(x)
    loader.delimiter = x
  end
end

def table_dataload(&b)
  handle_errors do
    TableLoaderDSL.new(&b)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
GFunk911-dataload-0.8.5 lib/dataload/dsl/table_loader_dsl.rb
GFunk911-dataload-0.9.0 lib/dataload/dsl/table_loader_dsl.rb