Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 0.91 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.   class LinkGraph
  2.     attr_accessor :crawler_id, :crawl_date    
  3.    
  4.     LOCAL_DB = {:adapter => "postgresql", :host => "localhost", :database => "development234", :username => "hello", :password => "howdy" }    
  5.    
  6.    
  7.     def table_name
  8.       "#{crawler_id}__#{crawl_date.gsub("/","_")}__linkgraph"
  9.     end
  10.    
  11.     def initialize_activerecord
  12.       ActiveRecord::Base.establish_connection(LOCAL_DB)
  13.     end
  14.    
  15.     def create_table
  16.       if @crawler_id.blank? || @crawl_date.blank?
  17.         puts "Need Crawler ID and Crawl Date to use temporary tables. "
  18.         return false
  19.       end
  20.       ActiveRecord::Base.connection.execute(
  21.         "CREATE TABLE #{table_name}
  22.         (page_url text,
  23.         page_id integer,
  24.         destination_url text,
  25.         destination_code integer,
  26.         destination char(50));"
  27.       )
  28.     end
  29.    
  30.     class LinkGraphchild < ActiveRecord::Base
  31.       set_table_name table_name
  32.     end