carrierwave_versions_backgrounder 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 85301eb03024227430f1fbf9a3d49b1cd28a16fb
4
+ data.tar.gz: 2556bcb58db8308da8c2c27d74e64c1ca54504a1
5
+ SHA512:
6
+ metadata.gz: 673e5d3303b6bac952ef7d6ede185c7ed71c5fe5fbb73e932a0a123da3d228a5a00dd9f43725017036f295716edfca9953a8a52c3ee589e7defa8fab623c2223
7
+ data.tar.gz: ab05915aee5609dfb0bcda24da737f4d5fed69ee9372e5225be61dc725b543148917616aa5f172c3190f3121e2af2dfc31fa304a1b79cd0f5cd11dd7bbb5623a
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in carrierwave_versions_backgrounder.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Abraham Kuri
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,79 @@
1
+ # [Carrierwave Versions Backgrounder](https://github.com/IcaliaLabs/carrierwave_versions_backgrounder)
2
+
3
+ CarrierWave Versions Backgrounder is an extension for CarrierWave to handle the version process on a background process created and maintained by [Abraham Kuri](https://twitter.com/kurenn) from [Icalia Labs](http://twitter.com/icalialabs).
4
+
5
+ It currently works only with ActiveRecord, and might need some tweaks!
6
+
7
+ ## Getting started
8
+
9
+ carrierwave_versions_backgrounder works with rails 3 onwards. You can add it to your Gemfile with:
10
+
11
+ ```ruby
12
+ gem 'carrierwave_versions_backgrounder'
13
+ gem 'delayed_job_active_record'
14
+ ```
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ ##Configuration
20
+
21
+ It is really easy to setup the delay version process, you just need to follow these 2 steps:
22
+
23
+
24
+ 1. Pass an `delay` option to the mount uploader class method:
25
+ ```ruby
26
+ class User < ActiveRecord::Base
27
+ mount_uploader :avatar, ImageUploader, delay: true
28
+ end
29
+ ```
30
+ 2. Then go to your uploader and add a method on the versions you want to be versioned on a background process:
31
+ ```ruby
32
+ class ImageUploader < CarrierWave::Uploader::Base
33
+ version :thumb, if: :is_processing_delayed? do
34
+ process :resize_to_fill => [80, 80]
35
+ end
36
+ end
37
+ ```
38
+
39
+ Enjoy!
40
+
41
+ ##Queue priority
42
+
43
+ We have provided a method to handle the priority for the queue, by default the value is `20`. Just in case you want to change it, here is a quick example:
44
+
45
+ ```ruby
46
+ class User < ActiveRecord::Base
47
+ def self.queue_priority
48
+ 10
49
+ end
50
+ end
51
+ ```
52
+
53
+ ## Contributing
54
+
55
+ 1. Fork it
56
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
57
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
58
+ 4. Push to the branch (`git push origin my-new-feature`)
59
+ 5. Create new Pull Request
60
+
61
+ ### Devs
62
+
63
+ * Abraham Kuri (https://github.com/kurenn)
64
+
65
+ ### Future
66
+
67
+ * Support for Mongoid
68
+
69
+ ## Credits
70
+ Icalia Labs - weare@icalialabs.com
71
+
72
+ [Follow us](http://twitter.com/icalialabs "Follow us")
73
+ [Like us on Facebook](https://www.facebook.com/icalialab "Like us on Facebook")
74
+
75
+ Special thanks to [@jaghion](http://twitter.com/jaghion), in which this gem was inspired!
76
+
77
+ ### License
78
+
79
+ MIT License. Copyright 2012-2013 IcaliaLabs. http://icalialabs.com
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'carrierwave_versions_backgrounder/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "carrierwave_versions_backgrounder"
8
+ spec.version = CarrierwaveVersionsBackgrounder::VERSION
9
+ spec.authors = ["Abraham Kuri"]
10
+ spec.email = ["kurenn@icalialabs.com"]
11
+ spec.summary = %q{An extension to carrierwave to handle asynchronous version processing with delayed job.}
12
+ spec.description = %q{An extension to carrierwave to handle asynchronous version processing with delayed job. It currently work with active record}
13
+ spec.homepage = "https://github.com/IcaliaLabs/carrierwave_versions_backgrounder"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_dependency "carrierwave", ["~> 0.6"]
23
+ end
@@ -0,0 +1,14 @@
1
+ require 'active_support/core_ext/object/blank'
2
+ require 'active_support/core_ext/class/attribute'
3
+ require 'active_support/concern'
4
+
5
+ module CarrierWaveVersionsBackgrounder
6
+ class Railtie < Rails::Railtie
7
+ initializer "carrierwave_versions_backgrounder.active_record" do
8
+ ActiveSupport.on_load :active_record do
9
+ require 'carrierwave_versions_backgrounder/uploader_methods'
10
+ require 'orm/activerecord'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ module CarrierWaveVersionsBackgrounder
2
+ module UploaderMethods
3
+ #Based on https://gist.github.com/dblock/1710609#file_carrierwave.rb
4
+ #Kudos to @jaghion
5
+ def is_processing_delayed?(img = nil)
6
+ !! @is_processing_delayed
7
+ end
8
+
9
+ def is_processing_immediate?(img = nil)
10
+ ! is_processing_delayed?
11
+ end
12
+
13
+ def is_processing_delayed=(value)
14
+ @is_processing_delayed = value
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module CarrierwaveVersionsBackgrounder
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,38 @@
1
+ module CarrierWaveVersionsBackgrounder
2
+ module ActiveRecord
3
+
4
+ #Extens the mount uploader provided by CarrierWave
5
+ #It uses a delay option for setting up the background versioning process
6
+ def mount_uploader(column, uploader=nil, options={}, &block)
7
+ delay = options.delete(:delay)
8
+ super
9
+ if delay
10
+ process_in_background(column)
11
+ if uploader && !uploader.include?(CarrierWaveVersionsBackgrounder::UploaderMethods)
12
+ uploader.send(:include, CarrierWaveVersionsBackgrounder::UploaderMethods)
13
+ end
14
+ end
15
+ end
16
+
17
+ #Method to process image versions in background
18
+ def process_in_background(column = nil)
19
+ after_save :queue_versions_recreations!, :if => :"#{column}_changed?"
20
+
21
+ def self.queue_priority
22
+ 20
23
+ end
24
+
25
+ class_eval <<-RUBY, __FILE__, __LINE__+1
26
+ def queue_versions_recreations!
27
+ self.#{column}.is_processing_delayed = true
28
+ self.#{column}.recreate_versions!
29
+ end
30
+
31
+ RUBY
32
+ handle_asynchronously :queue_versions_recreations!, :priority => queue_priority
33
+ end
34
+
35
+ end
36
+ end
37
+
38
+ ActiveRecord::Base.extend CarrierWaveVersionsBackgrounder::ActiveRecord
@@ -0,0 +1,17 @@
1
+ module CarrierWave
2
+ module Versions
3
+ module Backgrounder
4
+
5
+ def initialize(model=nil, mounted_as=nil, *delayed_versions)
6
+ @model = model
7
+ @mounted_as = mounted_as
8
+ @delayed_versions = *delayed_versions
9
+ end
10
+
11
+
12
+ def recreate_delayed_versions!
13
+ self.recreate_versions(@delayed_versions)
14
+ end
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: carrierwave_versions_backgrounder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Abraham Kuri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: carrierwave
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.6'
41
+ description: An extension to carrierwave to handle asynchronous version processing
42
+ with delayed job. It currently work with active record
43
+ email:
44
+ - kurenn@icalialabs.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - carrierwave_versions_backgrounder.gemspec
55
+ - lib/carrierwave_versions_backgrounder.rb
56
+ - lib/carrierwave_versions_backgrounder/uploader_methods.rb
57
+ - lib/carrierwave_versions_backgrounder/version.rb
58
+ - lib/orm/activerecord.rb
59
+ - lib/versions/backgrounder.rb
60
+ homepage: https://github.com/IcaliaLabs/carrierwave_versions_backgrounder
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.2.1
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: An extension to carrierwave to handle asynchronous version processing with
84
+ delayed job.
85
+ test_files: []
86
+ has_rdoc: