has_attachable 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 97e43af2f9f77bf6a8969996b4ca3d1981c86d33
4
+ data.tar.gz: 1e2eda1b3e2679a86d93ae0ec8faa94b3456ff98
5
+ SHA512:
6
+ metadata.gz: dd9d3d43243fed145d0155ff2eba3b6d875e3631245f0d3c96becf50fbc41e2b53f866d554f8e0f7dcbaddb3133407fad62cb96ea7c4afa94c8ec5784821722f
7
+ data.tar.gz: 491227dec20ea95eaa48e9be20ac9090e5553327361f0d4672dead7b3c975cb563a5e22cf037f53d30d9df7dcabdcb1f6a4fbadf31c864e02113e923955db9cc
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ coverage
12
+ InstalledFiles
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
20
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in has_attachable.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Artellectual
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Zack Siri
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # HasAttachable
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'has_attachable'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install has_attachable
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -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 'has_attachable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "has_attachable"
8
+ spec.version = HasAttachable::VERSION
9
+ spec.authors = ["Zack Siri"]
10
+ spec.email = ["zack@artellectual.com"]
11
+ spec.description = %q{gem for managing async uploading to S3 and background processing with sidekiq}
12
+ spec.summary = %q{for managing async uploading}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,58 @@
1
+ module HasAttachable
2
+ module Processing
3
+ extend ActiveSupport::Concern
4
+
5
+ def attachable_job
6
+ JobStatus.new(AttachableWorker.sidekiq_options["queue"].to_s,
7
+ self.class.name.downcase, self.id)
8
+ end
9
+
10
+ def process_attachable?
11
+ field = get_changed_attachable
12
+ return false if field.nil?
13
+
14
+ case attachable_options[field][:type]
15
+ when :downloadable, :streamable then false
16
+ else
17
+ send("#{field}_name_changed?") and \
18
+ send("#{field}_name").present? ? true : false
19
+ end
20
+ end
21
+
22
+ def remove_attachable?
23
+ field = get_remove_attachable
24
+ return false if field.nil?
25
+
26
+ send("async_remove_#{field}") and \
27
+ send("#{field}_name").present? ? true : false
28
+ end
29
+
30
+ def get_changed_attachable
31
+ changed_attachable = nil
32
+ attachable_fields.each do |field|
33
+ changed_attachable = field if changes.has_key?("#{field}_name")
34
+ end
35
+ changed_attachable
36
+ end
37
+
38
+ def get_remove_attachable
39
+ remove_attachable = nil
40
+ attachable_fields.each do |field|
41
+ remove_attachable = field if send("async_remove_#{field}")
42
+ end
43
+ remove_attachable
44
+ end
45
+
46
+ def attachable_status_path
47
+ "/monitor/#{AttachableWorker.sidekiq_options['queue'].to_s}/#{self.class.name.downcase}/#{self.id}"
48
+ end
49
+
50
+ def processing_options
51
+ {
52
+ klass: self.class.name,
53
+ id: id,
54
+ context: get_changed_attachable || get_remove_attachable
55
+ }
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module HasAttachable
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,59 @@
1
+ require "has_attachable/version"
2
+ require "has_attachable/processing"
3
+
4
+ module HasAttachable
5
+ extend ActiveSupport::Concern
6
+
7
+ class NoUploaderError < StandardError
8
+ def message
9
+ "No Uploader found, please specify an uploader"
10
+ end
11
+ end
12
+
13
+ included do
14
+ after_update -> {
15
+ AttachableWorker.
16
+ perform_async('process',
17
+ processing_options) if process_attachable?
18
+ AttachableWorker.
19
+ perform_async('remove',
20
+ processing_options) if remove_attachable?
21
+ }
22
+ include Attachable::Processing
23
+ end
24
+
25
+ module ClassMethods
26
+ def has_attachable(*attachable_options)
27
+ field = attachable_options[0]
28
+ options = attachable_options[1]
29
+ options[:type] = :graphic unless options[:type].present?
30
+ initialize_attachable(field, options)
31
+ end
32
+
33
+ private
34
+
35
+ def initialize_attachable(field, options)
36
+ class_attribute :attachable_options unless defined? self.attachable_options
37
+ self.attachable_options ||= {}
38
+ self.attachable_options[field] = options
39
+
40
+ class_attribute :attachable_fields unless defined? self.attachable_fields
41
+ self.attachable_fields ||= []
42
+ self.attachable_fields << field
43
+
44
+ raise NoUploaderError unless attachable_options[field][:uploader].present?
45
+ attachable_field = :attachable unless field.present?
46
+
47
+
48
+ class_eval do
49
+ attr_accessible "async_remove_#{field}".to_sym, "#{field}_name".to_sym
50
+ attr_accessor "async_remove_#{field}".to_sym
51
+
52
+ mount_uploader field,
53
+ attachable_options[field][:uploader],
54
+ mount_on: "#{field}_name"
55
+
56
+ end
57
+ end
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has_attachable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Zack Siri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-14 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: gem for managing async uploading to S3 and background processing with
42
+ sidekiq
43
+ email:
44
+ - zack@artellectual.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - has_attachable.gemspec
56
+ - lib/has_attachable.rb
57
+ - lib/has_attachable/processing.rb
58
+ - lib/has_attachable/version.rb
59
+ homepage: ''
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.0.5
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: for managing async uploading
83
+ test_files: []