paperclip-tinify 0.0.1 → 0.0.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/paperclip-tinify.rb +16 -12
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 565bb6ebe534f0da8889c4e75dbc38e105f31548
4
- data.tar.gz: ca160158d460eecb2af53c74f7570926b1f883f0
3
+ metadata.gz: 35faae5ee027d6b07f0179c7c1a804c577d7c9ac
4
+ data.tar.gz: 53be166370e6e3a0727367b91fa80e7c1ead64f4
5
5
  SHA512:
6
- metadata.gz: 796452c2541c689297a21e04856343eee6915f78d6a7c8d1f8cd8237c05859894d490dbb554f2bfffb8137f68266838820ded193784264eaa05b68ffeacce095
7
- data.tar.gz: 7924c4534b886b63d758098f05fd4e878eaf898c98ce1a4d7cc05ec96cb172e2cef170fd558a85b3fd089ca5a939372dada5cddcbab02510c386b635d97eba92
6
+ metadata.gz: f933741373de1a4a57eb8261a792675f201f8e1901449443c5e8c7cafb47028e2e7c6e3f2489d8101b0c16ca65a3497888b6979cfeb44c5206d861956a43e449
7
+ data.tar.gz: 2c3188239076d8732b6d569505757cf06bdffdd0bde1adcca77d1fc7f857748b089f216c72b98a43308497fa379e6c5f877d7118acbd9acc7a836741a00fd645
@@ -3,7 +3,7 @@ module Paperclip
3
3
 
4
4
  class Tinify < Processor
5
5
  class << self
6
- attr_accessor :tinify_key
6
+ attr_accessor :tinify_key, :environments
7
7
  end
8
8
 
9
9
  def make
@@ -16,6 +16,10 @@ module Paperclip
16
16
 
17
17
  private
18
18
 
19
+ def environments
20
+ Tinify.environments || [:production]
21
+ end
22
+
19
23
  def first_processor?
20
24
  @first_processor ||= @file.is_a?(Paperclip::AbstractAdapter)
21
25
  end
@@ -25,24 +29,24 @@ module Paperclip
25
29
  end
26
30
 
27
31
  def compress
28
- current_extension = File.extname(@file.path)
29
- basename = File.basename(@file.path, current_extension)
32
+ src_path = File.expand_path(@file.path)
30
33
 
31
- src = @file
32
- dst = TempfileFactory.new.generate(basename)
34
+ unless environments.include? RailsEnvironment.get.to_sym
35
+ Paperclip.log "tinify ignores this environment, skipping..."
33
36
 
34
- if Tinify.tinify_key
35
- Paperclip.log "tinifying..."
37
+ return File.open(src_path)
38
+ end
36
39
 
37
- ::Tinify.key = Tinify.tinify_key
38
- ::Tinify.from_file(File.expand_path(src.path)).to_file(File.expand_path(dst))
40
+ if api_key = Tinify.tinify_key
41
+ Paperclip.log "tinifying #{src_path}"
39
42
 
40
- dst
43
+ ::Tinify.key = api_key
44
+ ::Tinify.from_file(src_path).to_file(src_path)
41
45
  else
42
46
  Paperclip.log "tinify key was not defined, skipping..."
43
-
44
- File.open(src.path)
45
47
  end
48
+
49
+ File.open(src_path)
46
50
  end
47
51
  end
48
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip-tinify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thales Pereira