stdin/stdout as mounted Carrierwave uploader

This commit is contained in:
Marcin Kulik 2011-11-23 22:44:00 +01:00
parent f35902ad31
commit 73b2c07e1b
4 changed files with 66 additions and 1 deletions

View File

@ -1,3 +1,8 @@
class Asciicast < ActiveRecord::Base
validates :terminal_columns, :terminal_lines, :duration, :presence => true
mount_uploader :stdin, BasicUploader
mount_uploader :stdin_timing, BasicUploader
mount_uploader :stdout, BasicUploader
mount_uploader :stdout_timing, BasicUploader
end

View File

@ -0,0 +1,48 @@
# encoding: utf-8
class BasicUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
# process :scale => [200, 300]
#
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files:
# version :thumb do
# process :scale => [50, 50]
# end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
# def extension_white_list
# %w(jpg jpeg gif png)
# end
# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
end

View File

@ -0,0 +1,8 @@
class AddStdinStderrToAsciicast < ActiveRecord::Migration
def change
add_column :asciicasts, :stdin, :string
add_column :asciicasts, :stdin_timing, :string
add_column :asciicasts, :stdout, :string
add_column :asciicasts, :stdout_timing, :string
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20111123210607) do
ActiveRecord::Schema.define(:version => 20111123214033) do
create_table "asciicasts", :force => true do |t|
t.integer "user_id"
@ -26,6 +26,10 @@ ActiveRecord::Schema.define(:version => 20111123210607) do
t.string "uname"
t.datetime "created_at"
t.datetime "updated_at"
t.string "stdin"
t.string "stdin_timing"
t.string "stdout"
t.string "stdout_timing"
end
add_index "asciicasts", ["created_at"], :name => "index_asciicasts_on_created_at"