fileclip 0.2.4 → 0.3.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: 9d40924bf65cf039c91bcceead4b1cf7c74eb45b
4
- data.tar.gz: f611297bd1576eba94220544c3b3657a92b0b1d2
3
+ metadata.gz: 0676c859073d216852c397b109a24de44013b53f
4
+ data.tar.gz: 6d017f9ac5d01e0b750144009c432c2583f5192a
5
5
  SHA512:
6
- metadata.gz: dc984b5f899557d9fcf6ba87d799cfe094dd8fa2a04e8c12ec92338a63cb87f4445e71ebb2009d08c3190bacc17a45d7b0f1cb994be6f564158ffb29311020f9
7
- data.tar.gz: 88cde2cfabb89d4738540c0a2bb4d1e0b09f10495a2e43ccdeee86071fa2bdac9a95b8addf43b8053d05771ec99a59a51febcc121554822e23fcf7c4459818e4
6
+ metadata.gz: ae6c1d30f895d8071d07f693e3913ebb011c0c4dd9455d99af9fb97fd25572c7550680710ca2564132158c424cdab6d3d91d723de87df4961088a86bc8291a06
7
+ data.tar.gz: 13c7805036a72919a2060226c9a5440ab65411b6dc8716825bd74531eef12b16aa05b7474392cf7905948eef2f7476cb48ee548c12241fa0810af7b0a2c47239
data/Gemfile CHANGED
@@ -1,6 +1,3 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
-
5
- gem 'rails', "3.2.14"
6
-
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fileclip (0.2.3)
4
+ fileclip (0.2.4)
5
5
  paperclip
6
6
  paperclip (>= 3.5.1)
7
7
  railties (>= 3.0)
@@ -39,11 +39,21 @@ GEM
39
39
  multi_json (~> 1.0)
40
40
  arel (3.0.2)
41
41
  builder (3.0.4)
42
+ celluloid (0.15.2)
43
+ timers (~> 1.1.0)
42
44
  climate_control (0.0.3)
43
45
  activesupport (>= 3.0)
44
- cocaine (0.5.2)
46
+ cocaine (0.5.3)
45
47
  climate_control (>= 0.0.3, < 1.0)
48
+ connection_pool (1.2.0)
49
+ coveralls (0.7.0)
50
+ multi_json (~> 1.3)
51
+ rest-client
52
+ simplecov (>= 0.7)
53
+ term-ansicolor
54
+ thor
46
55
  diff-lcs (1.2.4)
56
+ docile (1.1.0)
47
57
  erubis (2.7.0)
48
58
  hike (1.2.3)
49
59
  i18n (0.6.4)
@@ -55,10 +65,10 @@ GEM
55
65
  mime-types (1.23)
56
66
  mono_logger (1.1.0)
57
67
  multi_json (1.7.7)
58
- paperclip (3.5.1)
68
+ paperclip (3.5.2)
59
69
  activemodel (>= 3.0.0)
60
70
  activesupport (>= 3.0.0)
61
- cocaine (~> 0.5.0)
71
+ cocaine (~> 0.5.3)
62
72
  mime-types
63
73
  polyglot (0.3.3)
64
74
  rack (1.4.5)
@@ -107,6 +117,17 @@ GEM
107
117
  rspec-expectations (2.14.0)
108
118
  diff-lcs (>= 1.1.3, < 2.0)
109
119
  rspec-mocks (2.14.1)
120
+ sidekiq (2.14.0)
121
+ celluloid (>= 0.14.1)
122
+ connection_pool (>= 1.0.0)
123
+ json
124
+ redis (>= 3.0.4)
125
+ redis-namespace
126
+ simplecov (0.8.2)
127
+ docile (~> 1.1.0)
128
+ multi_json
129
+ simplecov-html (~> 0.8.0)
130
+ simplecov-html (0.8.0)
110
131
  sinatra (1.4.3)
111
132
  rack (~> 1.4)
112
133
  rack-protection (~> 1.4)
@@ -117,8 +138,12 @@ GEM
117
138
  rack (~> 1.0)
118
139
  tilt (~> 1.1, != 1.3.0)
119
140
  sqlite3 (1.3.7)
141
+ term-ansicolor (1.2.2)
142
+ tins (~> 0.8)
120
143
  thor (0.18.1)
121
144
  tilt (1.4.1)
145
+ timers (1.1.0)
146
+ tins (0.13.1)
122
147
  treetop (1.4.14)
123
148
  polyglot
124
149
  polyglot (>= 0.3.1)
@@ -130,8 +155,10 @@ PLATFORMS
130
155
  ruby
131
156
 
132
157
  DEPENDENCIES
158
+ coveralls
133
159
  fileclip!
134
- rails (= 3.2.14)
160
+ rails
135
161
  resque
136
162
  rspec
163
+ sidekiq
137
164
  sqlite3
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- FileClip [![Build Status](https://travis-ci.org/ScotterC/fileclip.png?branch=master)](https://travis-ci.org/ScotterC/fileclip)
1
+ FileClip [![Build Status](https://travis-ci.org/ScotterC/fileclip.png?branch=master)](https://travis-ci.org/ScotterC/fileclip) [![Coverage Status](https://coveralls.io/repos/ScotterC/fileclip/badge.png?branch=master)](https://coveralls.io/r/ScotterC/fileclip?branch=master)
2
2
  ========
3
3
 
4
4
  A FilePicker / PaperClip mashup. Use Filepicker for uploads and paperclip to process them.
@@ -33,6 +33,7 @@ FileClip.configure do |config|
33
33
  config.storage_path = "/assets/" # Defaults to "/fileclip/"
34
34
  config.mime_types = "images/jpeg" # Defaults to "images/*"
35
35
  config.file_access = "private" # Defaults to "public"
36
+ config.excluded_environments = [] # Defaults to ["test"]
36
37
  end
37
38
  ````
38
39
 
data/TODO.md CHANGED
@@ -7,13 +7,11 @@ Backend:
7
7
  * Normalize filenames
8
8
 
9
9
  Frontend:
10
- * Loader for filepicker js only if needed
11
10
  * Eliminate need for jQuery
12
11
  * make it a form builder function that can accept a different url name
13
12
 
14
13
  Extra features:
15
14
  * Work with DelayedJob
16
- * Work with Sidekiq
17
15
  * Fallback to filepicker url if paperclip url doesn't exist
18
16
  * Filepicker converts to match paperclip styles
19
17
  * FilePicker droppane support
data/fileclip.gemspec CHANGED
@@ -24,6 +24,8 @@ Gem::Specification.new do |s|
24
24
  s.add_development_dependency 'sqlite3'
25
25
  s.add_development_dependency "rails"
26
26
  s.add_development_dependency 'resque'
27
+ s.add_development_dependency 'sidekiq'
28
+ s.add_development_dependency 'coveralls'
27
29
  s.add_runtime_dependency(%q<railties>, [">= 3.0"])
28
30
 
29
31
  s.add_runtime_dependency "paperclip"
data/lib/fileclip.rb CHANGED
@@ -4,6 +4,7 @@ require 'fileclip/validators'
4
4
  require 'fileclip/engine'
5
5
  require 'fileclip/railtie'
6
6
  require 'fileclip/jobs/resque'
7
+ require 'fileclip/jobs/sidekiq'
7
8
  require 'rest-client'
8
9
 
9
10
  # TODO: make fileclip methods only load on fileclipped models
@@ -26,6 +27,10 @@ module FileClip
26
27
  !!(defined? Resque)
27
28
  end
28
29
 
30
+ def sidekiq_enabled?
31
+ !!(defined? Sidekiq)
32
+ end
33
+
29
34
  def change_keys
30
35
  @@change_keys ||= [:filepicker_url]
31
36
  end
@@ -72,18 +77,25 @@ module FileClip
72
77
  if update_from_filepicker?
73
78
  if FileClip.resque_enabled?
74
79
  # TODO: self.class.name is webrick ???
75
- delay_process!
80
+ process_with_resque!
81
+ elsif FileClip.sidekiq_enabled?
82
+ process_with_sidekiq!
76
83
  else
77
84
  process_from_filepicker
78
85
  end
79
86
  end
80
87
  end
81
88
 
82
- def delay_process!
89
+ def process_with_resque!
83
90
  update_column(:"#{attachment_name}_processing", true) if FileClip.delayed?
84
91
  ::Resque.enqueue(FileClip::Jobs::Resque, self.class.name, self.id)
85
92
  end
86
93
 
94
+ def process_with_sidekiq!
95
+ update_column(:"#{attachment_name}_processing", true) if FileClip.delayed?
96
+ FileClip::Jobs::Sidekiq.perform_async(self.class.name, self.id)
97
+ end
98
+
87
99
  def process_from_filepicker
88
100
  self.class.skip_callback :commit, :after, :update_from_filepicker!
89
101
  self.send(:"#{attachment_name}=", URI.parse(filepicker_url))
@@ -4,7 +4,7 @@ module FileClip
4
4
 
5
5
  # Include relevant JS
6
6
  def fileclip_js_include_tag
7
- javascript_include_tag "//api.filepicker.io/v1/filepicker.js", "fileclip"
7
+ javascript_include_tag "fileclip"
8
8
  end
9
9
 
10
10
  # Options
@@ -2,7 +2,8 @@ module FileClip
2
2
  class Configuration
3
3
  attr_writer :filepicker_key, :services,
4
4
  :max_size, :storage_path,
5
- :mime_types, :file_access
5
+ :mime_types, :file_access,
6
+ :excluded_environments
6
7
 
7
8
  def filepicker_key
8
9
  @filepicker_key or raise "Set Filepicker api_key"
@@ -28,6 +29,10 @@ module FileClip
28
29
  @file_access or "public"
29
30
  end
30
31
 
32
+ def excluded_environments
33
+ @excluded_environments or ["test"]
34
+ end
35
+
31
36
  end
32
37
 
33
38
  class << self
@@ -0,0 +1,11 @@
1
+ module FileClip
2
+ module Jobs
3
+ class Sidekiq
4
+ include ::Sidekiq::Worker if defined?(::Sidekiq::Worker)
5
+
6
+ def perform(instance_klass, instance_id)
7
+ FileClip.process(instance_klass, instance_id)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module FileClip
2
- VERSION = "0.2.4"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -60,6 +60,17 @@ describe FileClip do
60
60
  FileClip.resque_enabled?.should be_true
61
61
  end
62
62
  end
63
+
64
+ describe "sidekiq_enabled?" do
65
+ it "returns false by default" do
66
+ FileClip.sidekiq_enabled?.should be_false
67
+ end
68
+
69
+ it "returns true if resque exists" do
70
+ stub_const "Sidekiq", Class.new
71
+ FileClip.sidekiq_enabled?.should be_true
72
+ end
73
+ end
63
74
  end
64
75
 
65
76
  describe "instance methods" do
@@ -82,7 +93,7 @@ describe FileClip do
82
93
 
83
94
  context "#update_from_filepicker!" do
84
95
 
85
- context "without resque" do
96
+ context "without a background queue" do
86
97
  before :each do
87
98
  image.filepicker_url = filepicker_url
88
99
  image.stub_chain(:previous_changes, :keys).and_return ["filepicker_url"]
@@ -96,17 +107,24 @@ describe FileClip do
96
107
  end
97
108
  end
98
109
 
99
- context "with resque" do
110
+ context "with a background queue" do
100
111
  before :each do
101
112
  image.filepicker_url = filepicker_url
102
113
  image.stub_chain(:previous_changes, :keys).and_return ["filepicker_url"]
103
114
  end
104
115
 
105
- it "enqueues job" do
116
+ it "enqueues job with Resque" do
106
117
  stub_const "Resque", Class.new
107
118
  Resque.should_receive(:enqueue).with(FileClip::Jobs::Resque, "Image", nil)
108
119
  image.update_from_filepicker!
109
120
  end
121
+
122
+ it "enqueues job with Sidekiq" do
123
+ stub_const "Sidekiq", Class.new
124
+ stub_const "Sidekiq::Worker", Class.new
125
+ FileClip::Jobs::Sidekiq.should_receive(:perform_async).with("Image", nil)
126
+ image.update_from_filepicker!
127
+ end
110
128
  end
111
129
 
112
130
  context "with delayed paperclip" do
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,9 @@ require 'rubygems' unless defined? Gem
2
2
  require 'bundler'
3
3
  Bundler.setup
4
4
 
5
+ require 'coveralls'
6
+ Coveralls.wear!
7
+
5
8
  # Prepare activerecord
6
9
  # require "active_record"
7
10
  require 'rails/all'
@@ -1,7 +1,15 @@
1
1
  class window.FileClip
2
2
  _clicked_button: ""
3
3
 
4
+ @env = ->
5
+ "<%= Rails.env %>"
6
+
4
7
  constructor: ->
8
+ excludedEnvs = <%= FileClip.configuration.excluded_environments %>
9
+ if @inArray(excludedEnvs, FileClip.env()) != -1
10
+ return false
11
+
12
+ @loadFilepicker()
5
13
  filepicker.setKey('<%= FileClip.configuration.filepicker_key %>');
6
14
 
7
15
  # For filepicker_helper
@@ -53,5 +61,35 @@ class window.FileClip
53
61
 
54
62
  callback(file, @_clicked_button) if callback
55
63
 
64
+ loadFilepicker: ->
65
+ ((a) ->
66
+ return if window.filepicker
67
+ b = a.createElement("script")
68
+ b.type = "text/javascript"
69
+ b.async = not 0
70
+ b.src = ((if "https:" is a.location.protocol then "https:" else "http:")) + "//api.filepicker.io/v1/filepicker.js"
71
+ c = a.getElementsByTagName("script")[0]
72
+ c.parentNode.insertBefore b, c
73
+ d = {}
74
+ d._queue = []
75
+ e = "pick,pickMultiple,pickAndStore,read,write,writeUrl,export,convert,store,storeUrl,remove,stat,setKey,constructWidget,makeDropPane".split(",")
76
+ f = (a, b) ->
77
+ ->
78
+ b.push [a, arguments]
79
+
80
+ g = 0
81
+
82
+ while g < e.length
83
+ d[e[g]] = f(e[g], d._queue)
84
+ g++
85
+ window.filepicker = d
86
+ ) document
56
87
 
88
+ inArray: (array, value) ->
89
+ return array.indexOf(value) if array.indexOf
90
+ i = 0
57
91
 
92
+ while i < array.length
93
+ return i if array[i] is value
94
+ i++
95
+ -1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fileclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Carleton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-29 00:00:00.000000000 Z
11
+ date: 2013-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paperclip
@@ -94,6 +94,34 @@ dependencies:
94
94
  - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sidekiq
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: railties
99
127
  requirement: !ruby/object:Gem::Requirement
@@ -147,6 +175,7 @@ files:
147
175
  - lib/fileclip/configuration.rb
148
176
  - lib/fileclip/engine.rb
149
177
  - lib/fileclip/jobs/resque.rb
178
+ - lib/fileclip/jobs/sidekiq.rb
150
179
  - lib/fileclip/railtie.rb
151
180
  - lib/fileclip/validators.rb
152
181
  - lib/fileclip/version.rb