Skip to content
This repository has been archived by the owner on Oct 30, 2019. It is now read-only.

Commit

Permalink
Major update again, works.. barely
Browse files Browse the repository at this point in the history
  • Loading branch information
flexd committed Oct 23, 2010
1 parent 81e6dbe commit 3c9c7a2
Show file tree
Hide file tree
Showing 79 changed files with 95,297 additions and 37 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ gem "rspec"
gem "data_mapper"
gem "rack-test"
gem "dm-core"
#gem "dm-postgres-adapter"
gem "dm-sqlite-adapter"
gem "dm-timestamps"
gem "dm-validations"
Expand All @@ -19,4 +20,5 @@ gem "sunshowers"
gem "rack-flash"
gem "sinatra-redirect-with-flash"
gem "resque"
gem "rake"
gem "rake"
gem "carrierwave"
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ GEM
arel (1.0.1)
activesupport (~> 3.0.0)
builder (2.1.2)
carrierwave (0.5.0)
activesupport (~> 3.0.0)
data_mapper (1.0.2)
dm-aggregates (= 1.0.2)
dm-constraints (= 1.0.2)
Expand Down Expand Up @@ -127,6 +129,7 @@ PLATFORMS

DEPENDENCIES
activesupport
carrierwave
data_mapper
dm-aggregates
dm-core
Expand Down
23 changes: 15 additions & 8 deletions application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,23 @@ def make_paperclip_mash(file_hash)
# add your helpers here
end
post '/upload' do
redirect '/', :error => "File seems to be empty" unless params[:file][:tempfile].size > 0
@resource = Resource.new(:file => make_paperclip_mash(params[:file]))
redirect '/', :error => "There were some errors processing your request...\n#{@resource.errors.inspect}" unless @resource.save
@resource.async_generate_replay

haml :processing
@replay = Replay.new
begin
@replay.original = params[:file]
rescue CarrierWave::IntegrityError
puts "wrong file silly"
end
@replay.description = params[:description]
p @replay.errors.full_messages
redirect '/', :error => "Something went wrong with saving the record: #{@replay.errors.inspect}" unless @replay.save
@replay.async_parse
#@resource.async_generate_replay
redirect "/replay/#{@replay.id}"

end
get '/upload' do
redirect '/', :notice => "Upload something!"
get '/replay/:id' do
@replay = Replay.get(params[:id])
haml :replay
end
get '/' do
haml :index
Expand Down
14 changes: 10 additions & 4 deletions environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
require 'sinatra' unless defined?(Sinatra)
require 'sinatra/redirect_with_flash'
require 'resque'
require 'zlib'
require 'carrierwave'
require 'carrierwave/orm/datamapper'
require 'tempfile'

APP_ROOT = File.expand_path(File.dirname(__FILE__))
Expand All @@ -23,12 +24,17 @@
:url_base => 'http://localhost:4567/'
)

# load workers
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/workers")
Dir.glob("#{File.dirname(__FILE__)}/workers/*.rb") { |lib| require File.basename(lib, '.*') }
# load uploaders
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/uploaders")
Dir.glob("#{File.dirname(__FILE__)}/uploaders/*.rb") { |lib| require File.basename(lib, '.*') }
# load models
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/lib")
Dir.glob("#{File.dirname(__FILE__)}/lib/*.rb") { |lib| require File.basename(lib, '.*') }
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/workers")
Dir.glob("#{File.dirname(__FILE__)}/workers/*.rb") { |lib| require File.basename(lib, '.*') }


#DataMapper.setup(:defaut, "postgres://localhost/civ5replay_#{Sinatra::Base.environment}")
DataMapper.setup(:default, (ENV["DATABASE_URL"] || "sqlite3:///#{File.expand_path(File.dirname(__FILE__))}/#{Sinatra::Base.environment}.db"))
use Rack::Flash
enable :sessions
Expand Down
21 changes: 21 additions & 0 deletions lib/replay.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#require 'carrierwave/orm/datamapper'

class Replay
include DataMapper::Resource
property :id, Serial
property :name, String
property :description, Text, :required => true, :length => 0..150
property :original_file, String, :auto_validation => false
property :replay_file, String, :auto_validation => false
mount_uploader :original, OriginalUploader, :mount_on => :original_file
# mount_uploader :replay, ReplayUploader, :mount_on => :replay_file

before :create, :generate_name

def async_parse
Resque.enqueue(ParseReplay, self.id)
end
def generate_name
self.name = rand(32**8).to_s(32)
end
end
2 changes: 2 additions & 0 deletions logfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 8103) running in data directory "/Users/Kristoffer/Developer/var/postgres"?
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 3c9c7a2

Please sign in to comment.