paperclip-av-chainer 0.1.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fdbacfd64f64719206ade55adb7a2cef08cc6176
4
- data.tar.gz: 3fd2cbb391b91a92dc1d651021f90dc01a5f8dd0
3
+ metadata.gz: db7b12da41c54238ec0c0cac9a0ab34046a10726
4
+ data.tar.gz: 1e5586ca0d594be38c01c90fa666752790a03c42
5
5
  SHA512:
6
- metadata.gz: d836f46cd64845b18b5d90a5197878ddd844dc7d71052e1270edf8ae06c15b662a035e2e86bf26d4b771f04c08a7715afc75dfb0be566398231a11c035ba9743
7
- data.tar.gz: 3327f7a44c66acb8c7f6d6fc2fe54408e8dfcc656eea916973f9f25b70de3ced8e3b282ed3e34ee84b87c907c41b1d73bfd54aa0e6abb81b717909001b751824
6
+ metadata.gz: 8b5c975ef11cafb7b1122d7210e1c5e47a584e2eca9b3ffedb59bd515d28da333b507b0666901bd94c74ffb16c5b0900b3f9bb42ecf67576d03b5aea046dceaf
7
+ data.tar.gz: 528cb3d89634c6ac85fe229a56c009d8f869d6ecb84eb9f5a5dd3d3af759a19fa5af88cb3ec2be4f52ff691f42a2b7bd916c311a3f48a97e9631afdf1402c5c3
@@ -1,7 +1,7 @@
1
1
  module Paperclip
2
2
  module Av
3
3
  module Chainer
4
- VERSION = "0.1.0"
4
+ VERSION = "0.5.0"
5
5
  end
6
6
  end
7
7
  end
@@ -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] Got file #{@file.path} with extension #{@extension}"
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
- Paperclip.log "[chainer] Extracting contents to #{@destination}"
37
- Zip::File.open(File.expand_path(@file.path)) do |zip_file|
38
- Paperclip.log "[chainer] Creating #{@destination}"
39
- FileUtils.mkdir_p(@destination)
40
- zip_file.each do |source|
41
- # Extract to file/directory/symlink
42
- Paperclip.log "[chainer] Extracting #{source.name}"
43
- target_file = @destination.join(source.name)
44
- @target_format = File.extname(source.name)
45
- zip_file.extract(source, target_file) unless File.exists?(target_file)
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
@@ -26,5 +26,5 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_dependency "paperclip", ">=2.5.2"
28
28
  spec.add_dependency "rubyzip", "~> 1.1.0"
29
- spec.add_dependency "av", ">= 0.1.2"
29
+ spec.add_dependency "av", ">= 0.4.0"
30
30
  end
@@ -1,17 +1,35 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Paperclip::Chainer do
4
- let(:subject) { Paperclip::Chainer.new(source) }
5
- let(:document) { Document.create(original: Rack::Test::UploadedFile.new(source, 'application/zip')) }
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
- it { expect(File.exists?(document.original.path(:small))).to eq true }
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
- describe ".unzip" do
11
- before do
12
- subject.unzip
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(Dir["#{subject.destination}/*"].count).to eq 2 }
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
@@ -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 :original_file_name
5
- t.string :original_content_type
6
- t.integer :original_updated_at
7
- t.integer :original_file_size
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
@@ -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(nil)
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 :original,
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
- do_not_validate_attachment_file_type :original
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
 
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.1.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 00:00:00.000000000 Z
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.1.2
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.1.2
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