rack_image_resizer 1.2.7 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rack_image_resizer.rb +15 -23
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5bfffa4712aea033e1e8e17def1e465b9134d67ce179f07149d122d3b6d838f4
4
- data.tar.gz: 173fcb522dd5d12d4fc18b6e29891e79d9babd127a3327913d0f038449232b18
3
+ metadata.gz: 317f602a60fc3a621da4897c29786fb636f8155660980b92a1134b74900ad3aa
4
+ data.tar.gz: 530c8fff285afe3f52e66aec8a2897378d4f97fbcb24aefddfb6099162a9b4d4
5
5
  SHA512:
6
- metadata.gz: f85c904064c5fc9eff1613dbd28002b464a0fd470124ac9397c2d656a2a6d9c62623b6f210a864d8ba5898103eed49bf6f362315d984881c553296c629e15d67
7
- data.tar.gz: 22c0a8ee256585c84fe8a49350ddc5d83dccd4aec6282e3f34e9dd02773f4748e458471c617f82a0e72ee8a862d18d6b8b458f59d850c604b741192fdbce9f8c
6
+ metadata.gz: 8820004e65a2dc8c6cf6bb60caeb59cc0ddcbb04539912d59c936c7e0850c8204e61267cab05712e989d411da21074845abbf94a1e3c0a05aa02ab440483aa19
7
+ data.tar.gz: f5aa083ad8276879d9ce911a4812a1bc0d3b82a1ece44d6b711f762e9b6255e57441b853b7cea62bcbbcac8d28ed61a83a22f9f495c6bf9278f9b48f92b4b7cc
@@ -6,11 +6,16 @@ module ::RackImageResizer
6
6
  extend self
7
7
 
8
8
  def resizer_secret
9
- ENV.fetch('RESIZER_SECRET')
9
+ @secret || ENV.fetch('RESIZER_SECRET')
10
10
  end
11
11
 
12
12
  def resizer_url
13
- ENV.fetch('RESIZER_URL')
13
+ @url || ENV.fetch('RESIZER_URL')
14
+ end
15
+
16
+ def set name, value
17
+ raise 'not allowed' unless [:secret, :url].include?(name)
18
+ instance_variable_set '@%s' % name, value
14
19
  end
15
20
 
16
21
  ###
@@ -18,40 +23,27 @@ module ::RackImageResizer
18
23
  # "http://foo.jpg".resize_image({ s: "222x222", q: 80 }
19
24
  # "http://foo.jpg".resize_image("^200x200")
20
25
  # "http://foo.jpg".resize_image - expcts size as param
21
- def get opts=nil
22
- image = opts.delete(:i) || opts.delete(:image)
26
+ def get opts
27
+ opts[:i] ||= opts.delete(:image)
28
+ opts[:s] ||= opts.delete(:size) if opts[:size]
23
29
 
24
30
  # return empty pixel unless self
25
- return "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" if self.blank?
31
+ return "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" if opts[:i].to_s == ''
26
32
 
27
- image = image.sub(%r{^(\w+)://}, '')
33
+ opts[:i] = opts[:i].sub(%r{^(\w+)://}, '')
28
34
  prefix = $1 == 'https' ? 's' : 'p'
29
- image = prefix + image
30
-
31
- to_encode =
32
- if opts
33
- if opts.is_a?(Hash)
34
- opts[:s] ||= opts.delete(:size) if opts[:size]
35
- else
36
- opts = { s: opts }
37
- end
38
-
39
- opts[:i] = image
40
- opts.to_json
41
- else
42
- image
43
- end
35
+ opts[:i] = prefix + opts[:i]
44
36
 
45
37
  data = []
46
38
 
47
39
  # add base
48
- data.push Base64.urlsafe_encode64(to_encode).gsub(/=*\s*$/, '')
40
+ data.push Base64.urlsafe_encode64(opts.to_json).gsub(/=*\s*$/, '')
49
41
 
50
42
  # add check
51
43
  data.push Digest::SHA1.hexdigest(resizer_secret+data.first)[0,4]
52
44
 
53
45
  # add extension
54
- ext = image.split('.').last.to_s.downcase
46
+ ext = opts[:i].split('.').last.to_s.downcase
55
47
  ext = 'jpg' unless ['jpg', 'jpeg', 'gif', 'png', 'svg'].index(ext)
56
48
  data.push '.%s' % ext
57
49
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack_image_resizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.7
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dino Reic