delayed_paperclip 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  *.log
2
+ pkg/
2
3
  public/
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Jesse Storimer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOa AND
17
+ NONINFRINGEMENT. IN NO EVENT SaALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,47 @@
1
+ h1. Delayed::Paperclip
2
+
3
+ *Warning: ATM this is alpha software and has not been tested in a production environment*
4
+
5
+ Delayed_paperclip lets you process your "Paperclip":http://github.com/thoughtbot/paperclip attachments in a background task with "delayed_job":http://github.com/tobi/delayed_job.
6
+
7
+ h2. Why?
8
+
9
+ The most common use case for Paperclip is to easily attach image files to ActiveRecord models. Most of the time these image files will have multiple styles and will need to be resized when they are created. This is usually a pretty "slow operation":http://www.jstorimer.com/ruby/2010/01/05/speep-up-your-paperclip-tests.html and should be handled in a background task.
10
+
11
+ I'm sure that everyone knows this, this gem just makes it easy to do.
12
+
13
+ h2. Install
14
+
15
+ <code>sudo gem install delayed_paperclip</code>
16
+
17
+ Dependencies:
18
+ * Paperclip
19
+ * delayed_jobs
20
+
21
+ h2. Usage
22
+
23
+ Make sure that you have "DJ":http://github.com/tobi/delayed_job up and running.
24
+
25
+ In your model:
26
+
27
+ <pre><code>
28
+ class User < ActiveRecord::Base
29
+ has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
30
+
31
+ process_in_background :avatar
32
+ end
33
+ </code></pre>
34
+
35
+ Use your Paperclip attachment just like always in controllers and views.
36
+
37
+ h2. What if I'm not using images?
38
+
39
+ AFAIK this library should work no matter what kind of post-processing you are doing with Paperclip.
40
+
41
+ h2. Does it work with s3?
42
+
43
+ Yes.
44
+
45
+ h2. Inspirations
46
+
47
+ "http://blog.madeofcode.com/post/201282903/paperclip-s3-delayed-job-in-rails":http://blog.madeofcode.com/post/201282903/paperclip-s3-delayed-job-in-rails
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{delayed_paperclip}
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jesse Storimer"]
12
+ s.date = %q{2010-01-27}
13
+ s.description = %q{Process your Paperclip attachments in the background with delayed_job.}
14
+ s.email = %q{jesse@jstorimer.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.textile"
18
+ ]
19
+ s.files = [
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README.textile",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "delayed_paperclip.gemspec",
26
+ "lib/delayed/paperclip.rb",
27
+ "lib/delayed/paperclip_job.rb",
28
+ "lib/delayed_paperclip.rb",
29
+ "test/database.yml",
30
+ "test/delayed_paperclip_test.rb",
31
+ "test/fixtures/12k.png",
32
+ "test/test_helper.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/jstorimer/delayed_paperclip}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.5}
38
+ s.summary = %q{Process your Paperclip attachments in the background with delayed_job.}
39
+ s.test_files = [
40
+ "test/delayed_paperclip_test.rb",
41
+ "test/test_helper.rb"
42
+ ]
43
+
44
+ if s.respond_to? :specification_version then
45
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
49
+ s.add_runtime_dependency(%q<paperclip>, [">= 2.3.0"])
50
+ s.add_runtime_dependency(%q<delayed_job>, [">= 1.8.0"])
51
+ else
52
+ s.add_dependency(%q<paperclip>, [">= 2.3.0"])
53
+ s.add_dependency(%q<delayed_job>, [">= 1.8.0"])
54
+ end
55
+ else
56
+ s.add_dependency(%q<paperclip>, [">= 2.3.0"])
57
+ s.add_dependency(%q<delayed_job>, [">= 1.8.0"])
58
+ end
59
+ end
60
+
@@ -5,30 +5,6 @@ module Delayed
5
5
  end
6
6
 
7
7
  module ClassMethods
8
- # +process_in_background+ gives the class it is called on an attribute that maps to a file. This
9
- # is typically a file stored somewhere on the filesystem and has been uploaded by a user.
10
- # The attribute returns a Paperclip::Attachment object which handles the management of
11
- # that file. The intent is to make the attachment as much like a normal attribute. The
12
- # thumbnails will be created when the new file is assigned, but they will *not* be saved
13
- # until +save+ is called on the record. Likewise, if the attribute is set to +nil+ is
14
- # called on it, the attachment will *not* be deleted until +save+ is called. See the
15
- # Paperclip::Attachment documentation for more specifics. There are a number of options
16
- # you can set to change the behavior of a Paperclip attachment:
17
- # * +url+: The full URL of where the attachment is publically accessible. This can just
18
- # as easily point to a directory served directly through Apache as it can to an action
19
- # that can control permissions. You can specify the full domain and path, but usually
20
- # just an absolute path is sufficient. The leading slash *must* be included manually for
21
- # absolute paths. The default value is
22
- # "/system/:attachment/:id/:style/:filename". See
23
- # Paperclip::Attachment#interpolate for more information on variable interpolaton.
24
- # :url => "/:class/:attachment/:id/:style_:filename"
25
- # :url => "http://some.other.host/stuff/:class/:id_:extension"
26
- # * +default_url+: The URL that will be returned if there is no attachment assigned.
27
- # This field is interpolated just as the url is. The default value is
28
- # "/:attachment/:style/missing.png"
29
- # has_attached_file :avatar, :default_url => "/images/default_:style_avatar.png"
30
- # User.new.avatar_url(:small) # => "/images/default_small_avatar.png"
31
-
32
8
  def process_in_background(name)
33
9
  include InstanceMethods
34
10
 
@@ -38,7 +14,6 @@ module Delayed
38
14
 
39
15
  define_method "halt_processing_for_#{name}" do
40
16
  if self.send("#{name}_changed?")
41
- self.processing = true if self.respond_to?(:processing)
42
17
  false # halts processing
43
18
  end
44
19
  end
@@ -2,11 +2,6 @@ class DelayedPaperclipJob < Struct.new(:instance_id, :instance_klass, :attachmen
2
2
  def perform
3
3
  instance = instance_klass.constantize.find(instance_id)
4
4
 
5
- instance.send(attachment_name).reprocess!
6
-
7
- if instance.respond_to?(:processing)
8
- instance.processing = false
9
- instance.save
10
- end
5
+ instance.send(attachment_name).reprocess!
11
6
  end
12
7
  end
@@ -29,22 +29,6 @@ class DelayedPaperclipTest < Test::Unit::TestCase
29
29
  assert !@dummy.halt_processing_for_image
30
30
  end
31
31
 
32
- def test_halt_processing_if_source_changed_and_processing_attribute_defined
33
- reset_table("dummies") do |d|
34
- d.string :image_file_name
35
- d.integer :image_file_size
36
- d.boolean :processing
37
- end
38
- @dummy_class = reset_class "Dummy"
39
- @dummy_class.has_attached_file :image
40
- @dummy_class.process_in_background :image
41
- @dummy = Dummy.new(:image => File.read("#{RAILS_ROOT}/test/fixtures/12k.png"))
42
-
43
- @dummy.stubs(:image_changed?).returns(true)
44
- assert !@dummy.halt_processing_for_image
45
- assert @dummy.processing
46
- end
47
-
48
32
  def test_halt_processing_if_source_has_not_changed
49
33
  @dummy.stubs(:image_changed?).returns(false)
50
34
  assert_not_equal false, @dummy.halt_processing_for_image
@@ -71,27 +55,6 @@ class DelayedPaperclipTest < Test::Unit::TestCase
71
55
  DelayedPaperclipJob.new(@dummy.id, @dummy.class.name, :image).perform
72
56
  end
73
57
 
74
- def test_perform_job_with_processing_attribute
75
- reset_table("dummies") do |d|
76
- d.string :image_file_name
77
- d.integer :image_file_size
78
- d.boolean :processing
79
- end
80
- @dummy_class = reset_class "Dummy"
81
- @dummy_class.has_attached_file :image
82
- @dummy_class.process_in_background :image
83
-
84
- @dummy = Dummy.new(:image => File.open("#{RAILS_ROOT}/test/fixtures/12k.png"))
85
-
86
- Paperclip::Attachment.any_instance.expects(:reprocess!)
87
-
88
- @dummy.processing = true
89
- @dummy.save!
90
- DelayedPaperclipJob.new(@dummy.id, @dummy.class.name, :image).perform
91
-
92
- assert !@dummy.reload.processing
93
- end
94
-
95
58
  private
96
59
  def reset_dummy
97
60
  reset_table("dummies") do |d|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_paperclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Storimer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-26 00:00:00 -05:00
12
+ date: 2010-01-27 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -38,13 +38,16 @@ executables: []
38
38
 
39
39
  extensions: []
40
40
 
41
- extra_rdoc_files: []
42
-
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.textile
43
44
  files:
44
45
  - .gitignore
46
+ - LICENSE
47
+ - README.textile
45
48
  - Rakefile
46
49
  - VERSION
47
- - dev/null
50
+ - delayed_paperclip.gemspec
48
51
  - lib/delayed/paperclip.rb
49
52
  - lib/delayed/paperclip_job.rb
50
53
  - lib/delayed_paperclip.rb
data/dev/null DELETED
File without changes