paperclip-av-chainer 0.1.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/paperclip/av/chainer/version.rb +1 -1
- data/lib/paperclip/paperclip_processors/chainer.rb +17 -15
- data/paperclip-av-chainer.gemspec +1 -1
- data/spec/chainer/chainer_spec.rb +26 -8
- data/spec/schema.rb +8 -4
- data/spec/spec_helper.rb +14 -3
- data/spec/support/assets/audio.zip +0 -0
- data/spec/support/assets/image.png +0 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db7b12da41c54238ec0c0cac9a0ab34046a10726
|
4
|
+
data.tar.gz: 1e5586ca0d594be38c01c90fa666752790a03c42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b5c975ef11cafb7b1122d7210e1c5e47a584e2eca9b3ffedb59bd515d28da333b507b0666901bd94c74ffb16c5b0900b3f9bb42ecf67576d03b5aea046dceaf
|
7
|
+
data.tar.gz: 528cb3d89634c6ac85fe229a56c009d8f869d6ecb84eb9f5a5dd3d3af759a19fa5af88cb3ec2be4f52ff691f42a2b7bd916c311a3f48a97e9631afdf1402c5c3
|
@@ -3,21 +3,20 @@ require 'av'
|
|
3
3
|
|
4
4
|
module Paperclip
|
5
5
|
class Chainer < Processor
|
6
|
-
attr_accessor :whiny, :destination, :extension, :basename, :supported_formats
|
6
|
+
attr_accessor :file, :whiny, :destination, :extension, :basename, :supported_formats
|
7
7
|
|
8
8
|
def initialize file, options = {}, attachment = nil
|
9
|
-
Paperclip.log "[chainer] Got file #{file.path}"
|
10
|
-
@whiny = options[:whiny].nil? ? true : options[:whiny]
|
11
9
|
@file = file
|
10
|
+
@whiny = options[:whiny].nil? ? true : options[:whiny]
|
11
|
+
@destination = Pathname.new("#{Dir.tmpdir}/#{SecureRandom.uuid}")
|
12
12
|
@extension = File.extname(@file.path)
|
13
13
|
@basename = File.basename(@file.path, @extension)
|
14
14
|
@supported_formats = ['.zip']
|
15
|
-
@destination = Pathname.new("#{Dir.tmpdir}/#{SecureRandom.uuid}")
|
16
15
|
end
|
17
16
|
|
18
17
|
def make
|
19
18
|
if @supported_formats.include?(@extension)
|
20
|
-
Paperclip.log "[chainer]
|
19
|
+
Paperclip.log "[chainer] Received supported file #{@file.path}"
|
21
20
|
case @extension
|
22
21
|
when '.zip'
|
23
22
|
unzip
|
@@ -28,21 +27,24 @@ module Paperclip
|
|
28
27
|
# on the new file
|
29
28
|
return result
|
30
29
|
end
|
30
|
+
Paperclip.log "[chainer] Skipping file with unsupported format: #{@file.path}"
|
31
31
|
# If the file is not supported, just return it
|
32
32
|
@file
|
33
33
|
end
|
34
34
|
|
35
35
|
def unzip
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
36
|
+
if @supported_formats.include?(@extension)
|
37
|
+
Paperclip.log "[chainer] Extracting contents to #{@destination}"
|
38
|
+
Zip::File.open(File.expand_path(@file.path)) do |zip_file|
|
39
|
+
Paperclip.log "[chainer] Creating #{@destination}"
|
40
|
+
FileUtils.mkdir_p(@destination)
|
41
|
+
zip_file.each do |source|
|
42
|
+
# Extract to file/directory/symlink
|
43
|
+
Paperclip.log "[chainer] Extracting #{source.name}"
|
44
|
+
target_file = @destination.join(source.name)
|
45
|
+
@target_format = File.extname(source.name)
|
46
|
+
zip_file.extract(source, target_file) unless File.exists?(target_file)
|
47
|
+
end
|
46
48
|
end
|
47
49
|
end
|
48
50
|
end
|
@@ -1,17 +1,35 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Paperclip::Chainer do
|
4
|
-
let(:
|
5
|
-
let(:
|
6
|
-
let(:source) { File.new(File.expand_path('spec/support/assets/audio.zip')) }
|
4
|
+
let(:supported) { File.new(File.expand_path('spec/support/assets/audio.zip')) }
|
5
|
+
let(:unsupported) { File.new(File.expand_path('spec/support/assets/image.png')) }
|
7
6
|
|
8
|
-
|
7
|
+
describe "supported formats" do
|
8
|
+
let(:subject) { Paperclip::Chainer.new(supported) }
|
9
|
+
let(:document) { Document.create(audio: Rack::Test::UploadedFile.new(supported, 'application/zip')) }
|
10
|
+
|
11
|
+
it { expect(File.exists?(document.audio.path(:small))).to eq true }
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
+
describe ".unzip" do
|
14
|
+
before do
|
15
|
+
subject.unzip
|
16
|
+
end
|
17
|
+
|
18
|
+
it { expect(Dir["#{subject.destination}/*"].count).to eq 2 }
|
13
19
|
end
|
20
|
+
end
|
21
|
+
describe "unsupported formats" do
|
22
|
+
let(:subject) { Paperclip::Chainer.new(unsupported) }
|
23
|
+
let(:document) { Document.create(image: Rack::Test::UploadedFile.new(unsupported, 'image/png')) }
|
14
24
|
|
15
|
-
it { expect(
|
25
|
+
it { expect(File.exists?(document.image.path(:small))).to eq true }
|
26
|
+
|
27
|
+
describe ".unzip" do
|
28
|
+
before do
|
29
|
+
subject.unzip
|
30
|
+
end
|
31
|
+
|
32
|
+
it { expect(Dir["#{subject.destination}/*"].count).to eq 0 }
|
33
|
+
end
|
16
34
|
end
|
17
35
|
end
|
data/spec/schema.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
ActiveRecord::Schema.define version: 0 do
|
2
2
|
create_table "documents", force: true do |t|
|
3
3
|
t.string :owner
|
4
|
-
t.string :
|
5
|
-
t.string :
|
6
|
-
t.integer :
|
7
|
-
t.integer :
|
4
|
+
t.string :audio_file_name
|
5
|
+
t.string :audio_content_type
|
6
|
+
t.integer :audio_updated_at
|
7
|
+
t.integer :audio_file_size
|
8
|
+
t.string :image_file_name
|
9
|
+
t.string :image_content_type
|
10
|
+
t.integer :image_updated_at
|
11
|
+
t.integer :image_file_size
|
8
12
|
end
|
9
13
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -11,7 +11,7 @@ Bundler.require(:default)
|
|
11
11
|
# Connect to sqlite
|
12
12
|
ActiveRecord::Base.establish_connection("adapter" => "sqlite3", "database" => ":memory:")
|
13
13
|
|
14
|
-
ActiveRecord::Base.logger = Logger.new(
|
14
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
15
15
|
load(File.join(File.dirname(__FILE__), 'schema.rb'))
|
16
16
|
|
17
17
|
Paperclip::Railtie.insert
|
@@ -22,7 +22,7 @@ RSpec.configure do |config|
|
|
22
22
|
end
|
23
23
|
|
24
24
|
class Document < ActiveRecord::Base
|
25
|
-
has_attached_file :
|
25
|
+
has_attached_file :audio,
|
26
26
|
storage: :filesystem,
|
27
27
|
path: "./spec/tmp/:id.:extension",
|
28
28
|
url: "/spec/tmp/:id.:extension",
|
@@ -32,6 +32,17 @@ class Document < ActiveRecord::Base
|
|
32
32
|
}
|
33
33
|
}, processors: [:chainer]
|
34
34
|
|
35
|
-
|
35
|
+
has_attached_file :image,
|
36
|
+
storage: :filesystem,
|
37
|
+
path: "./spec/tmp/:id.:extension",
|
38
|
+
url: "/spec/tmp/:id.:extension",
|
39
|
+
styles: {
|
40
|
+
small: {
|
41
|
+
format: :ogg
|
42
|
+
}
|
43
|
+
}, processors: [:chainer, :thumbnail]
|
44
|
+
|
45
|
+
do_not_validate_attachment_file_type :audio
|
46
|
+
do_not_validate_attachment_file_type :image
|
36
47
|
end
|
37
48
|
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip-av-chainer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Omar Abdel-Wahab
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 0.
|
117
|
+
version: 0.4.0
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: 0.
|
124
|
+
version: 0.4.0
|
125
125
|
description: Audio/Video Chainer for Paperclip using FFMPEG/Avconv
|
126
126
|
email:
|
127
127
|
- owahab@gmail.com
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- spec/schema.rb
|
144
144
|
- spec/spec_helper.rb
|
145
145
|
- spec/support/assets/audio.zip
|
146
|
+
- spec/support/assets/image.png
|
146
147
|
homepage: https://github.com/ruby-av/paperclip-av-chainer
|
147
148
|
licenses:
|
148
149
|
- MIT
|
@@ -172,3 +173,4 @@ test_files:
|
|
172
173
|
- spec/schema.rb
|
173
174
|
- spec/spec_helper.rb
|
174
175
|
- spec/support/assets/audio.zip
|
176
|
+
- spec/support/assets/image.png
|