Want more features on Pastebin? Sign Up, it's FREE!
Guest

stuffforstackoverflow

By: a guest on Jun 14th, 2012  |  syntax: Ruby  |  size: 2.29 KB  |  views: 30  |  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. # gemfile
  2.  
  3. source 'http://rubygems.org'
  4.  
  5. gem 'thin'
  6. gem 'pg'
  7. gem 'json'
  8. gem 'yajl-ruby'
  9. gem 'activerecord'
  10. gem 'rufus-scheduler'
  11. gem 'rake'
  12. gem 'activerecord', :require => 'active_record'
  13. gem 'net-sftp'
  14. gem 'net-ssh'
  15. gem 'jeweler'
  16. group :test do
  17.   gem 'rspec'
  18.   gem 'rack-test'
  19.   gem 'net-http-spy'
  20. end
  21. ~                                                                                                    
  22. ~          
  23.  
  24. #pw_data_extract.rb
  25. require_relative 'import.rb'
  26. require 'rubygems'
  27. require 'json'
  28. require 'active_record'
  29. Dir.glob('models/*').each { |r| require r }
  30. require 'uri'
  31. require 'net/http'
  32. require 'net/ssh'
  33. require 'net/sftp'
  34. include Net
  35.  
  36. module PWDataExtract
  37.  
  38.   def self.included(base)
  39.     base.extend ClassMethods
  40.   end
  41.  
  42.   def ensure_unique(name)
  43.     begin
  44.       self[name] = yield
  45.     end while self.class.exists?(name => self[name])
  46.   end
  47.  
  48.   def PWDataExtract.load_data
  49.     ActiveRecord::Base.establish_connection(YAML.load(File.read(File.join('config','database.yml')))[ENV['ENV'] ? ENV['ENV'] : 'development'])
  50.  
  51.     # Run immediately first
  52.     download_files
  53.     import_files
  54.  
  55.   end
  56.  
  57.   module ClassMethods
  58.  
  59.   end
  60.  
  61.   end
  62.  
  63.  
  64.  
  65. #Rakefile
  66.  
  67. $LOAD_PATH.unshift(Dir.getwd)
  68. require 'rubygems'
  69. require 'rake'
  70. require 'jeweler'
  71. #require 'echoe'
  72. require 'bundler'
  73. Bundler.require
  74.  
  75. namespace :db do
  76.   task :migrate do
  77.     ActiveRecord::Base.establish_connection(YAML.load(File.read(File.join('config','database.yml')))[ENV['ENV'] ? ENV['ENV'] : 'development'])
  78.     ActiveRecord::Migrator.migrate("db/migrate/")
  79.   end
  80.  
  81.   task :seed do
  82.     seed_file = "./db/seeds.rb"
  83.     puts "Seeding database from: #{seed_file}"
  84.     load(seed_file) if File.exist?(seed_file)
  85.   end
  86.  
  87. end
  88.  
  89.  
  90. Jeweler::Tasks.new do |gem|
  91.    #gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
  92.    gem.name = "pw_data_extract"
  93.   # gem.add_dependency 'activesupport','=3.2.6'
  94.   # gem.add_dependency 'net-ssh'
  95.    gem.summary = %Q{Dun dun dun}
  96.    gem.description = %Q{Populating dbs because Max is gone}
  97.    gem.email = "jordanmprince@gmail.com"
  98.    gem.homepage = "http://github.com/bhgames/pw_data_extract"
  99.    gem.authors = ["Jordan Prince"]
  100. end
  101. Jeweler::RubygemsDotOrgTasks.new
  102. ~
clone this paste RAW Paste Data