Skip to content

Instantly share code, notes, and snippets.

@nevinera
Created March 27, 2012 14:37
Show Gist options
  • Select an option

  • Save nevinera/2216473 to your computer and use it in GitHub Desktop.

Select an option

Save nevinera/2216473 to your computer and use it in GitHub Desktop.
import-demo
#!/usr/bin/ruby
RAILS_ENV = 'production'
`ln -sf database.yml.demo config/database.yml`
require File.expand_path('../config/boot', __FILE__)
require File.expand_path('../config/environment', __FILE__)
require 'highline/import'
history = ARGF
projects = Project.all(:order => :name)
companies = Company.all(:order => :name)
project_id = choose do |menu|
menu.header = 'Choose a product'
menu.prompt = "Choice: "
projects.each do |project|
menu.choice(project.name) { project.id }
end
menu.choice('New Product') { nil }
end
unless project_id
name = ask('New product name:')
user_ids = []
company_id = choose do |menu|
menu.header = 'Choose a company for this product'
menu.prompt = 'Choice: '
companies.each do |company|
menu.choice(company.name) { company.id }
end
end
say 'Creating product...'
p = Project.new(:name => name)
p.company_id = company_id
p.save!
project_id = p.id
say 'Done.'
end
say 'Uploading file...'
p = Project.find(project_id)
h = p.histories.build
h.file = open(ARGF.path)
h.save!
say 'Done.'
say 'Importing into Patterns'
h.import!
say 'Done.'
say 'Importing into Patterns API...'
key = `env RACK_ENV=production BUNDLE_GEMFILE=../patterns-api/Gemfile ../patterns-api/script/import -s 4 -t 1 '#{ARGF.path}' 2>/dev/null`.chomp
puts "API key: #{key}"
h.recommend_key = key.sub(/^patterns-/, '')
h.save!
say 'Done.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment