carrierwave_backgrounder 0.1.3 → 0.1.4

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.
data/CHANGELOG.md CHANGED
@@ -1,7 +1,17 @@
1
+ ## 0.1.4
2
+
3
+ ### bug fixes
4
+ * [#109] Fix issue where setting Carrierwave.cache_dir to a full path would raise an exception [Sastopher].
5
+ * [#108] Remove the need to set an order in the Gemfile when using sidekiq [matthewsmart].
6
+
1
7
  ## 0.1.3
2
8
 
3
9
  ### enhancements
4
10
  * CarrierWave::Workers::ProcessAsset now uses #update_attribute when setting [column]_processing.
11
+ * [#104] Change the Sidekiq integration to use client_push [petergoldstein]
12
+
13
+ ### bug fixes
14
+ * [#103] Fix determine_backend behavior so that it doesn't throw an exception [petergoldstein].
5
15
 
6
16
  ## 0.1.2
7
17
 
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
- # CarrierWave Backgrounder
1
+ # CarrierWave Backgrounder
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/lardawge/carrierwave_backgrounder.png)](http://travis-ci.org/lardawge/carrierwave_backgrounder)
4
4
  [![Code Quality](https://codeclimate.com/badge.png)](https://codeclimate.com/github/lardawge/carrierwave_backgrounder)
5
+ [![Still Maintained](http://stillmaintained.com/lardawge/carrierwave_backgrounder.png)](http://stillmaintained.com/lardawge/carrierwave_backgrounder)
5
6
 
6
7
  I like CarrierWave. That being said, I don't like tying up app instances waiting for images to process.
7
8
 
@@ -38,8 +39,6 @@ These instructions assume you have previously set up [CarrierWave](https://githu
38
39
  In Rails, add the following your Gemfile:
39
40
 
40
41
  ```ruby
41
- # IMPORTANT: Be sure to list the backend job processor you intend to use, before carrierwave_backgrounder
42
- gem 'sidekiq' # or delayed_job, resque, ect...
43
42
  gem 'carrierwave_backgrounder'
44
43
  ```
45
44
 
@@ -131,6 +130,35 @@ We use the after_commit hook when using active_record. This creates a problem wh
131
130
  if you're using trasactional fixtures. One solution to the problem is to use the [TestAfterCommit gem](https://github.com/grosser/test_after_commit).
132
131
  There are various other solutions in which case google is your friend.
133
132
 
133
+ ### Uploaders mounted on mongoid embedded documents
134
+ The workers fetch the document with the mounted uploader using the model class name and id. Uploads on embedded documents
135
+ cannot be obtained this way. If the position of the document in the root document structure is known, a workaround is to override the embedded models
136
+ find method like this:
137
+
138
+ ```ruby
139
+ class SomeRootDocument
140
+ include Mongoid::Document
141
+
142
+ embeds_many :embedded_documents
143
+ end
144
+
145
+ class EmbeddedDocument
146
+ include Mongoid::Document
147
+
148
+ embedded_in :some_root_document
149
+
150
+ mount_uploader :image, ImageUploader
151
+ process_in_background :image
152
+
153
+ def self.find(id)
154
+ bson_id = Moped::BSON::ObjectId.from_string(id) # needed for Mongoid 3
155
+
156
+ root = SomeRootDocument.where('embedded_documents._id' => bson_id).first
157
+ root.embedded_documents.find(id)
158
+ end
159
+ end
160
+ ```
161
+
134
162
  ## License
135
163
 
136
164
  Copyright (c) 2011 Larry Sprock
@@ -1,5 +1,5 @@
1
1
  module CarrierWave
2
2
  module Backgrounder
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
@@ -3,8 +3,6 @@ module CarrierWave
3
3
  module Workers
4
4
 
5
5
  class ProcessAsset < Struct.new(:klass, :id, :column)
6
- include ::Sidekiq::Worker if defined?(::Sidekiq)
7
-
8
6
  def self.perform(*args)
9
7
  new(*args).perform
10
8
  end
@@ -3,7 +3,6 @@ module CarrierWave
3
3
  module Workers
4
4
 
5
5
  class StoreAsset < Struct.new(:klass, :id, :column)
6
- include ::Sidekiq::Worker if defined?(::Sidekiq)
7
6
  attr_reader :cache_path, :tmp_directory
8
7
 
9
8
  def self.perform(*args)
@@ -37,7 +36,7 @@ module CarrierWave
37
36
 
38
37
  def store_directories(record)
39
38
  asset, asset_tmp = record.send(:"#{column}"), record.send(:"#{column}_tmp")
40
- cache_directory = File.join(asset.root, asset.cache_dir)
39
+ cache_directory = File.expand_path(asset.cache_dir, asset.root)
41
40
  @cache_path = File.join(cache_directory, asset_tmp)
42
41
  @tmp_directory = File.join(cache_directory, asset_tmp.split("/").first)
43
42
  end
@@ -12,6 +12,16 @@ module CarrierWave
12
12
 
13
13
  def self.configure
14
14
  yield self
15
+ if @backend == :sidekiq
16
+ ::CarrierWave::Workers::ProcessAsset.class_eval do
17
+ require 'sidekiq'
18
+ include ::Sidekiq::Worker
19
+ end
20
+ ::CarrierWave::Workers::StoreAsset.class_eval do
21
+ require 'sidekiq'
22
+ include ::Sidekiq::Worker
23
+ end
24
+ end
15
25
  end
16
26
 
17
27
  end
@@ -86,4 +86,53 @@ describe CarrierWave::Workers::StoreAsset do
86
86
  expect(worker.column).to eql(:avatar)
87
87
  end
88
88
  end
89
+
90
+ describe '#store_directories' do
91
+ let(:record) { mock('Record') }
92
+ let(:root) { '/home/chris/dev/my-rails-project/public' }
93
+
94
+ context 'cache_path' do
95
+ it 'sets the cache_path correctly if a full path is set for the cache_dir' do
96
+ root = '/Users/lar/Sites/bunker/public'
97
+ cache_dir = '/Users/lar/Sites/bunker/tmp/uploads'
98
+ asset = mock(:cache_dir => cache_dir, :root => root)
99
+ record.expects(:image).returns(asset)
100
+ record.expects(:image_tmp).returns('images/test.jpg')
101
+ worker.send :store_directories, record
102
+ expect(worker.cache_path).to eql('/Users/lar/Sites/bunker/tmp/uploads/images/test.jpg')
103
+ end
104
+
105
+ it 'sets the cache_path correctly if a partial path is set for cache_dir' do
106
+ root = '/Users/lar/Sites/bunker/public'
107
+ cache_dir = 'uploads/tmp'
108
+ asset = mock(:cache_dir => cache_dir, :root => root)
109
+ record.expects(:image).returns(asset)
110
+ record.expects(:image_tmp).returns('images/test.jpg')
111
+ worker.send :store_directories, record
112
+ expect(worker.cache_path).to eql('/Users/lar/Sites/bunker/public/uploads/tmp/images/test.jpg')
113
+ end
114
+ end
115
+
116
+ context 'tmp_directory' do
117
+ it 'sets the tmp_directory correctly if a full path is set for the cache_dir' do
118
+ root = '/Users/lar/Sites/bunker/public'
119
+ cache_dir = '/Users/lar/Sites/bunker/tmp/uploads'
120
+ asset = mock(:cache_dir => cache_dir, :root => root)
121
+ record.expects(:image).returns(asset)
122
+ record.expects(:image_tmp).returns('images/test.jpg')
123
+ worker.send :store_directories, record
124
+ expect(worker.tmp_directory).to eql('/Users/lar/Sites/bunker/tmp/uploads/images')
125
+ end
126
+
127
+ it 'sets the tmp_directory correctly if a partial path is set for cache_dir' do
128
+ root = '/Users/lar/Sites/bunker/public'
129
+ cache_dir = 'uploads/tmp'
130
+ asset = mock(:cache_dir => cache_dir, :root => root)
131
+ record.expects(:image).returns(asset)
132
+ record.expects(:image_tmp).returns('images/test.jpg')
133
+ worker.send :store_directories, record
134
+ expect(worker.tmp_directory).to eql('/Users/lar/Sites/bunker/public/uploads/tmp/images')
135
+ end
136
+ end
137
+ end
89
138
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave_backgrounder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-07 00:00:00.000000000 Z
12
+ date: 2013-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: carrierwave
@@ -127,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  segments:
129
129
  - 0
130
- hash: -2596358502417703338
130
+ hash: 1765216748357494122
131
131
  required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  none: false
133
133
  requirements:
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  segments:
138
138
  - 0
139
- hash: -2596358502417703338
139
+ hash: 1765216748357494122
140
140
  requirements: []
141
141
  rubyforge_project:
142
142
  rubygems_version: 1.8.24