rails_imager 0.0.29 → 0.0.30

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad885a728aa0846c006101b996e62bbd99819421
4
- data.tar.gz: afca7bba536f7d5a2463cbc48c5456fe9566f03b
3
+ metadata.gz: 335f5f841ec8b9052baf5ba8a97990046214fb2e
4
+ data.tar.gz: 19744bcd2fdc998b758e7cfa632248e336f52de3
5
5
  SHA512:
6
- metadata.gz: 304e153bf47f4e333ca0c6a94c59fa3b049c25c12e903d95e6ff1176606f056ccbddbb4d7d7ff2846c4bd1b8b3259b3d78ffd00342348f1683b294ac02e1253f
7
- data.tar.gz: dae814c368d23c0565491dee9b46a2cb5282f11451c3608ca41098fef027379989b2fc8f1b425839977f7d0156b40fad39bdc4a20f7815ad502af3497228932e
6
+ metadata.gz: cef0ac04a1d2936b3c4a77a9bc139286ff6cb59e62f80dd6aa2846e87b2befbefb7d2fda46a91dd5c73899d595d4d71e3b1fa654e57b7992b18ac430341ba632
7
+ data.tar.gz: cc19ffa85d34a6dd2e5a6de1c29f06649659b08181df94b1d92c0adbb2e68396e3c3e39c86b741edeed1120c8d4b8a38ed013492907ee1f61f70394efa9ebbf6
@@ -101,10 +101,7 @@ private
101
101
  end
102
102
 
103
103
  def cache_directory
104
- require "tmpdir"
105
- cache_path = "#{Dir.tmpdir}/rails-imager-cache"
106
- Dir.mkdir(cache_path) unless Dir.exist?(cache_path)
107
- return cache_path
104
+ RailsImager.cache_handler.path
108
105
  end
109
106
 
110
107
  def should_generate_cache?
@@ -126,6 +123,7 @@ private
126
123
  @image.format = "png"
127
124
  apply_image_changes
128
125
  @image.write(@cache_path)
126
+ @image.destroy!
129
127
  end
130
128
 
131
129
  #Create a new image-object based on the given image-object and the parameters.
@@ -41,6 +41,10 @@ module RailsImager
41
41
  require "RMagick"
42
42
  end
43
43
  end
44
+
45
+ def self.cache_handler
46
+ @cache_handler ||= RailsImager::CacheHandler.new
47
+ end
44
48
  end
45
49
 
46
50
  RailsImager.require_rmagick
@@ -0,0 +1,26 @@
1
+ class RailsImager::CacheHandler
2
+ def initialize(args = {})
3
+ @args = args
4
+ end
5
+
6
+ def path
7
+ unless @path
8
+ require "tmpdir"
9
+ @path = "#{Dir.tmpdir}/rails-imager-cache"
10
+ Dir.mkdir(@path) unless Dir.exist?(@path)
11
+ end
12
+
13
+ return @path
14
+ end
15
+
16
+ def clear(args = {})
17
+ Dir.foreach(path) do |file|
18
+ next if file == "." || file == ".."
19
+ next unless file.end_with?(".png")
20
+
21
+ full_path = "#{path}/#{file}"
22
+ File.unlink(full_path)
23
+ yield full_path if block_given?
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsImager
2
- VERSION = "0.0.29"
2
+ VERSION = "0.0.30"
3
3
  end
@@ -1,4 +1,14 @@
1
- # desc "Explaining what the task does"
2
- # task :rails_imager do
3
- # # Task goes here
4
- # end
1
+ namespace :rails_imager do
2
+ desc "Explaining what the task does"
3
+ task clear_cache: :environment do
4
+ puts "Beginning to clear cache"
5
+
6
+ count = 0
7
+ RailsImager.cache_handler.clear do |full_path|
8
+ puts "Deleted #{full_path}"
9
+ count += 1
10
+ end
11
+
12
+ puts "Cleared #{count} files"
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe RailsImager::CacheHandler do
4
+ it 'works' do
5
+ File.open("#{RailsImager.cache_handler.path}/test.png", "w").close
6
+
7
+ files = []
8
+ RailsImager.cache_handler.clear do |file|
9
+ files << file
10
+ end
11
+
12
+ expect(files).to include "#{RailsImager.cache_handler.path}/test.png"
13
+ end
14
+ end
@@ -11808,3 +11808,93 @@ Processing by RailsImager::ImagesController#show as HTML
11808
11808
  Sent file /tmp/rails-imager-cache/cdb14e91faa664e5555fd4bf048f485b.png (0.0ms)
11809
11809
  Completed 200 OK in 0ms (ActiveRecord: 0.0ms)
11810
11810
   (0.0ms) rollback transaction
11811
+  (0.1ms) begin transaction
11812
+  (0.0ms) rollback transaction
11813
+  (0.1ms) begin transaction
11814
+  (0.0ms) rollback transaction
11815
+  (0.1ms) begin transaction
11816
+  (0.0ms) rollback transaction
11817
+  (0.1ms) begin transaction
11818
+  (0.1ms) rollback transaction
11819
+  (0.1ms) begin transaction
11820
+  (0.0ms) rollback transaction
11821
+  (0.1ms) begin transaction
11822
+  (0.0ms) rollback transaction
11823
+  (0.0ms) begin transaction
11824
+ Processing by RailsImager::ImagesController#show as HTML
11825
+ Parameters: {"image"=>{"maxwidth"=>"200"}, "id"=>"test.png"}
11826
+ Sent file /tmp/rails-imager-cache/98c9a4c721daf05bde343cdf5f8e2a83.png (0.1ms)
11827
+ Completed 200 OK in 36ms (ActiveRecord: 0.0ms)
11828
+  (0.1ms) rollback transaction
11829
+  (0.0ms) begin transaction
11830
+ Processing by RailsImager::ImagesController#show as HTML
11831
+ Parameters: {"image"=>{"smartsize"=>"400"}, "id"=>"test.png"}
11832
+ Sent file /tmp/rails-imager-cache/a1d5e5791060350da8196efcf19e6d3c.png (0.1ms)
11833
+ Completed 200 OK in 82ms (ActiveRecord: 0.0ms)
11834
+  (0.1ms) rollback transaction
11835
+  (0.0ms) begin transaction
11836
+ Processing by RailsImager::ImagesController#show as HTML
11837
+ Parameters: {"image"=>{"smartsize"=>"640", "rounded_corners"=>"15", "border"=>"1", "border_color"=>"black"}, "id"=>"test.png"}
11838
+ Sent file /tmp/rails-imager-cache/cf61b86225ee9b620f73b5fe0e6af0b4.png (0.1ms)
11839
+ Completed 200 OK in 199ms (ActiveRecord: 0.0ms)
11840
+  (0.1ms) rollback transaction
11841
+  (0.0ms) begin transaction
11842
+ Processing by RailsImager::ImagesController#show as HTML
11843
+ Parameters: {"image"=>{"smartsize"=>"350"}, "id"=>"test.png"}
11844
+ Sent file /tmp/rails-imager-cache/3a04c3c926cd0bed2df232261ed539d0.png (0.1ms)
11845
+ Completed 200 OK in 65ms (ActiveRecord: 0.0ms)
11846
+ Processing by RailsImager::ImagesController#show as HTML
11847
+ Parameters: {"image"=>{"smartsize"=>"350"}, "id"=>"test.png"}
11848
+ Rendered text template (0.0ms)
11849
+ Completed 304 Not Modified in 4ms (Views: 4.0ms | ActiveRecord: 0.0ms)
11850
+  (0.1ms) rollback transaction
11851
+  (0.0ms) begin transaction
11852
+ Processing by RailsImager::ImagesController#show as HTML
11853
+ Parameters: {"image"=>{"width"=>"640", "height"=>"480"}, "id"=>"test.png"}
11854
+ Sent file /tmp/rails-imager-cache/3b24cae006ac63b391b4e16561d0c176.png (0.1ms)
11855
+ Completed 200 OK in 126ms (ActiveRecord: 0.0ms)
11856
+  (0.1ms) rollback transaction
11857
+  (0.0ms) begin transaction
11858
+ Processing by RailsImager::ImagesController#show as HTML
11859
+ Parameters: {"image"=>{"width"=>"640", "height"=>"480"}, "id"=>"test_æ_%C3%B8_å.png"}
11860
+ Sent file /tmp/rails-imager-cache/38575c34bde0655cda92b47d2763aec5.png (0.1ms)
11861
+ Completed 200 OK in 127ms (ActiveRecord: 0.0ms)
11862
+  (0.1ms) rollback transaction
11863
+  (0.0ms) begin transaction
11864
+ Processing by RailsImager::ImagesController#show as HTML
11865
+ Parameters: {"image"=>{"maxheight"=>"200"}, "id"=>"test.png"}
11866
+ Sent file /tmp/rails-imager-cache/d21ceb31c3fa4da3d50efe25436e51fe.png (0.0ms)
11867
+ Completed 200 OK in 27ms (ActiveRecord: 0.0ms)
11868
+  (0.1ms) rollback transaction
11869
+  (0.0ms) begin transaction
11870
+ Processing by RailsImager::ImagesController#show as HTML
11871
+ Parameters: {"image"=>{"smartsize"=>"400", "force"=>true}, "id"=>"test.png"}
11872
+ Sent file /tmp/rails-imager-cache/a1d5e5791060350da8196efcf19e6d3c.png (0.1ms)
11873
+ Completed 200 OK in 79ms (ActiveRecord: 0.0ms)
11874
+ Processing by RailsImager::ImagesController#show as HTML
11875
+ Parameters: {"image"=>{"smartsize"=>"400"}, "id"=>"test.png"}
11876
+ Sent file /tmp/rails-imager-cache/a1d5e5791060350da8196efcf19e6d3c.png (0.0ms)
11877
+ Completed 200 OK in 0ms (ActiveRecord: 0.0ms)
11878
+  (0.1ms) rollback transaction
11879
+  (0.0ms) begin transaction
11880
+ Processing by RailsImager::ImagesController#show as HTML
11881
+ Parameters: {"image"=>{"smartsize"=>"200", "rounded_corners"=>"8"}, "id"=>"test.png"}
11882
+ Sent file /tmp/rails-imager-cache/68a968398cfa1d0cd84dd5a794089554.png (0.1ms)
11883
+ Completed 200 OK in 38ms (ActiveRecord: 0.0ms)
11884
+  (0.1ms) rollback transaction
11885
+  (0.0ms) begin transaction
11886
+ Processing by RailsImager::ImagesController#show as HTML
11887
+ Parameters: {"image"=>{"smartsize"=>"200"}, "id"=>"test.png"}
11888
+ Sent file /tmp/rails-imager-cache/cdb14e91faa664e5555fd4bf048f485b.png (0.0ms)
11889
+ Completed 200 OK in 30ms (ActiveRecord: 0.0ms)
11890
+  (0.0ms) rollback transaction
11891
+  (0.0ms) begin transaction
11892
+ Processing by RailsImager::ImagesController#show as HTML
11893
+ Parameters: {"image"=>{"smartsize"=>"200"}, "id"=>"/../config.ru"}
11894
+ Completed 500 Internal Server Error in 0ms (ActiveRecord: 0.0ms)
11895
+  (0.0ms) rollback transaction
11896
+  (0.0ms) begin transaction
11897
+ Processing by RailsImager::ImagesController#show as HTML
11898
+ Parameters: {"image"=>{"invalid_param"=>"kasper"}, "id"=>"test.png"}
11899
+ Completed 500 Internal Server Error in 0ms (ActiveRecord: 0.0ms)
11900
+  (0.0ms) rollback transaction
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_imager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.29
4
+ version: 0.0.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-07 00:00:00.000000000 Z
11
+ date: 2015-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -183,10 +183,12 @@ files:
183
183
  - app/views/layouts/rails_imager/application.html.erb
184
184
  - config/routes.rb
185
185
  - lib/rails_imager.rb
186
+ - lib/rails_imager/cache_handler.rb
186
187
  - lib/rails_imager/config.rb
187
188
  - lib/rails_imager/engine.rb
188
189
  - lib/rails_imager/version.rb
189
190
  - lib/tasks/rails_imager_tasks.rake
191
+ - spec/cache_handler_spec.rb
190
192
  - spec/controllers/rails_imager/images_controller_spec.rb
191
193
  - spec/dummy/README.rdoc
192
194
  - spec/dummy/Rakefile
@@ -335,5 +337,6 @@ test_files:
335
337
  - spec/dummy/config/locales/en.yml
336
338
  - spec/dummy/config/database.yml
337
339
  - spec/dummy/config/routes.rb
340
+ - spec/cache_handler_spec.rb
338
341
  - spec/spec_helper.rb
339
342
  - spec/helpers/rails_imager/images_helper_spec.rb