Extract public_filepath and public_url from Clipping into LocalStore module.

This commit is contained in:
Martyn Loughran 2008-10-07 17:05:43 +01:00
Родитель bd0fb9f0d5
Коммит 32ad89fbf2
4 изменённых файлов: 35 добавлений и 13 удалений

Просмотреть файл

@ -1,9 +1,9 @@
# Clipping for a given encoding.
#
# Does it make sense for a parent video?
# Clipping for a given encoding or parent video.
#
class Clipping
include LocalStore
def initialize(video)
@video = video
end
@ -24,8 +24,8 @@ class Clipping
end
# URL on the panda instance (before it has been uploaded)
def tmp_url(size)
Panda::Config[:public_tmp_url] + args.map { |e| e.to_s }.join('_')
def tmp_url(size, position)
public_url(@video.filename, size, position, '.jpg')
end
# Position (as percentage) within the video
@ -37,7 +37,7 @@ class Clipping
raise RuntimeError, "Video must exist to call capture" unless File.exists?(@video.tmp_filepath)
t = RVideo::Inspector.new(:file => @video.tmp_filepath)
t.capture_frame("#{position_chosen}%", public_filepath(@video.filename, :screenshot, position_chosen))
t.capture_frame("#{position_chosen}%", tmp_path(:screenshot, position_chosen))
end
def resize(position_chosen = position())
@ -47,18 +47,18 @@ class Clipping
width = (@video.width.to_f/@video.height.to_f) * height
GDResize.new.resize \
public_filepath(@video.filename, :screenshot, position_chosen),
public_filepath(@video.filename, :thumbnail, position_chosen),
tmp_path(:screenshot, position_chosen),
tmp_path(:thumbnail, position_chosen),
[width.to_i, height.to_i]
end
def upload_to_store
Store.set \
filename(:screenshot),
public_filepath(@video.filename, :screenshot, position)
tmp_path(:screenshot, self.position)
Store.set \
filename(:thumbnail),
public_filepath(@video.filename, :thumbnail, position)
tmp_path(:thumbnail, self.position)
end
private
@ -67,9 +67,8 @@ class Clipping
@video.parent_video
end
# This path can be accessible from the web
def public_filepath(*args)
Panda::Config[:public_tmp_path] / args.map { |e| e.to_s }.join('_')
def tmp_path(size, position)
public_filepath(@video.filename, size, position, '.jpg')
end
end

Просмотреть файл

@ -23,6 +23,7 @@ require "config" / "panda_init"
dependencies 'merb-assets', 'merb-mailer', 'merb_helpers', 'uuid', 'to_simple_xml', 'rog', 'amazon_sdb', 'simple_db', 'retryable', 'activesupport', 'rvideo', 'panda', 'gd_resize', 'map_to_hash', 'spec_eql_hash', 'error_sender'
dependencies 'abstract_store', 's3_Store', 'file_store'
dependencies 'local_store'
# Not sure why dependencies won't load AWS::S3
require 'aws/s3'

15
lib/local_store.rb Normal file
Просмотреть файл

@ -0,0 +1,15 @@
module LocalStore
private
# This path can be accessible from the web
def public_filepath(*args)
Panda::Config[:public_tmp_path] / args.map { |e| e.to_s }.join('_')
end
# URL on the panda instance (before it has been uploaded)
def public_url(*args)
Panda::Config[:public_tmp_url] + '/' + args.map { |e| e.to_s }.join('_')
end
end

Просмотреть файл

@ -52,6 +52,13 @@ describe Clipping do
end
describe "tmp_url" do
it "should use public_url to generate url" do
@clipping.should_receive(:public_url).with(@video.filename, :thumbnail, 40, '.jpg')
@clipping.tmp_url(:thumbnail, 40)
end
end
describe "position" do
it "should read thumbnail_position from the parent video" do
@parent_video.stub!(:thumbnail_position).and_return(99)