Guest User

Untitled

a guest
Feb 18th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  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
Add Comment
Please, Sign In to add comment