image_optim 0.22.1 → 0.23.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.
Files changed (50) hide show
  1. checksums.yaml +8 -8
  2. data/.appveyor.yml +95 -0
  3. data/.rubocop.yml +3 -0
  4. data/.travis.yml +27 -22
  5. data/CHANGELOG.markdown +10 -0
  6. data/CONTRIBUTING.markdown +2 -1
  7. data/Gemfile +1 -1
  8. data/README.markdown +10 -2
  9. data/image_optim.gemspec +4 -4
  10. data/lib/image_optim.rb +32 -16
  11. data/lib/image_optim/bin_resolver/bin.rb +11 -4
  12. data/lib/image_optim/cache.rb +71 -0
  13. data/lib/image_optim/cache_path.rb +16 -0
  14. data/lib/image_optim/config.rb +12 -2
  15. data/lib/image_optim/handler.rb +1 -1
  16. data/lib/image_optim/image_meta.rb +5 -10
  17. data/lib/image_optim/optimized_path.rb +25 -0
  18. data/lib/image_optim/path.rb +70 -0
  19. data/lib/image_optim/runner/option_parser.rb +13 -0
  20. data/lib/image_optim/worker.rb +5 -8
  21. data/lib/image_optim/worker/class_methods.rb +3 -1
  22. data/lib/image_optim/worker/jpegoptim.rb +3 -0
  23. data/lib/image_optim/worker/jpegrecompress.rb +3 -0
  24. data/lib/image_optim/worker/pngquant.rb +3 -0
  25. data/script/worker_analysis +10 -9
  26. data/spec/image_optim/bin_resolver/comparable_condition_spec.rb +1 -1
  27. data/spec/image_optim/bin_resolver/simple_version_spec.rb +48 -40
  28. data/spec/image_optim/bin_resolver_spec.rb +190 -172
  29. data/spec/image_optim/cache_path_spec.rb +59 -0
  30. data/spec/image_optim/cache_spec.rb +159 -0
  31. data/spec/image_optim/cmd_spec.rb +11 -7
  32. data/spec/image_optim/config_spec.rb +92 -71
  33. data/spec/image_optim/handler_spec.rb +3 -6
  34. data/spec/image_optim/image_meta_spec.rb +61 -0
  35. data/spec/image_optim/optimized_path_spec.rb +58 -0
  36. data/spec/image_optim/option_helpers_spec.rb +25 -0
  37. data/spec/image_optim/path_spec.rb +105 -0
  38. data/spec/image_optim/railtie_spec.rb +6 -6
  39. data/spec/image_optim/runner/glob_helpers_spec.rb +2 -6
  40. data/spec/image_optim/runner/option_parser_spec.rb +3 -3
  41. data/spec/image_optim/space_spec.rb +16 -18
  42. data/spec/image_optim/worker/optipng_spec.rb +3 -3
  43. data/spec/image_optim/worker/pngquant_spec.rb +47 -7
  44. data/spec/image_optim/worker_spec.rb +114 -17
  45. data/spec/image_optim_spec.rb +58 -69
  46. data/spec/images/broken_jpeg +1 -0
  47. data/spec/spec_helper.rb +40 -10
  48. metadata +30 -8
  49. data/lib/image_optim/image_path.rb +0 -68
  50. data/spec/image_optim/image_path_spec.rb +0 -54
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_optim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.1
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Kuchin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-21 00:00:00.000000000 Z
11
+ date: 2016-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fspath
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '2.1'
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '2.1'
26
+ version: '3.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: image_size
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -99,6 +99,9 @@ dependencies:
99
99
  - - ~>
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0.2'
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: 0.2.2
102
105
  type: :development
103
106
  prerelease: false
104
107
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,6 +109,9 @@ dependencies:
106
109
  - - ~>
107
110
  - !ruby/object:Gem::Version
108
111
  version: '0.2'
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: 0.2.2
109
115
  - !ruby/object:Gem::Dependency
110
116
  name: rspec
111
117
  requirement: !ruby/object:Gem::Requirement
@@ -141,6 +147,7 @@ executables:
141
147
  extensions: []
142
148
  extra_rdoc_files: []
143
149
  files:
150
+ - .appveyor.yml
144
151
  - .gitignore
145
152
  - .rubocop.yml
146
153
  - .travis.yml
@@ -158,16 +165,19 @@ files:
158
165
  - lib/image_optim/bin_resolver/comparable_condition.rb
159
166
  - lib/image_optim/bin_resolver/error.rb
160
167
  - lib/image_optim/bin_resolver/simple_version.rb
168
+ - lib/image_optim/cache.rb
169
+ - lib/image_optim/cache_path.rb
161
170
  - lib/image_optim/cmd.rb
162
171
  - lib/image_optim/config.rb
163
172
  - lib/image_optim/configuration_error.rb
164
173
  - lib/image_optim/handler.rb
165
174
  - lib/image_optim/hash_helpers.rb
166
175
  - lib/image_optim/image_meta.rb
167
- - lib/image_optim/image_path.rb
168
176
  - lib/image_optim/non_negative_integer_range.rb
177
+ - lib/image_optim/optimized_path.rb
169
178
  - lib/image_optim/option_definition.rb
170
179
  - lib/image_optim/option_helpers.rb
180
+ - lib/image_optim/path.rb
171
181
  - lib/image_optim/railtie.rb
172
182
  - lib/image_optim/runner.rb
173
183
  - lib/image_optim/runner/glob_helpers.rb
@@ -195,12 +205,17 @@ files:
195
205
  - spec/image_optim/bin_resolver/comparable_condition_spec.rb
196
206
  - spec/image_optim/bin_resolver/simple_version_spec.rb
197
207
  - spec/image_optim/bin_resolver_spec.rb
208
+ - spec/image_optim/cache_path_spec.rb
209
+ - spec/image_optim/cache_spec.rb
198
210
  - spec/image_optim/cmd_spec.rb
199
211
  - spec/image_optim/config_spec.rb
200
212
  - spec/image_optim/handler_spec.rb
201
213
  - spec/image_optim/hash_helpers_spec.rb
202
- - spec/image_optim/image_path_spec.rb
214
+ - spec/image_optim/image_meta_spec.rb
215
+ - spec/image_optim/optimized_path_spec.rb
203
216
  - spec/image_optim/option_definition_spec.rb
217
+ - spec/image_optim/option_helpers_spec.rb
218
+ - spec/image_optim/path_spec.rb
204
219
  - spec/image_optim/railtie_spec.rb
205
220
  - spec/image_optim/runner/glob_helpers_spec.rb
206
221
  - spec/image_optim/runner/option_parser_spec.rb
@@ -209,6 +224,7 @@ files:
209
224
  - spec/image_optim/worker/pngquant_spec.rb
210
225
  - spec/image_optim/worker_spec.rb
211
226
  - spec/image_optim_spec.rb
227
+ - spec/images/broken_jpeg
212
228
  - spec/images/comparison.png
213
229
  - spec/images/decompressed.jpeg
214
230
  - spec/images/icecream.gif
@@ -256,7 +272,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
272
  version: '0'
257
273
  requirements: []
258
274
  rubyforge_project: image_optim
259
- rubygems_version: 2.4.7
275
+ rubygems_version: 2.6.4
260
276
  signing_key:
261
277
  specification_version: 4
262
278
  summary: Optimize (lossless compress, optionally lossy) images (jpeg, png, gif, svg)
@@ -266,12 +282,17 @@ test_files:
266
282
  - spec/image_optim/bin_resolver/comparable_condition_spec.rb
267
283
  - spec/image_optim/bin_resolver/simple_version_spec.rb
268
284
  - spec/image_optim/bin_resolver_spec.rb
285
+ - spec/image_optim/cache_path_spec.rb
286
+ - spec/image_optim/cache_spec.rb
269
287
  - spec/image_optim/cmd_spec.rb
270
288
  - spec/image_optim/config_spec.rb
271
289
  - spec/image_optim/handler_spec.rb
272
290
  - spec/image_optim/hash_helpers_spec.rb
273
- - spec/image_optim/image_path_spec.rb
291
+ - spec/image_optim/image_meta_spec.rb
292
+ - spec/image_optim/optimized_path_spec.rb
274
293
  - spec/image_optim/option_definition_spec.rb
294
+ - spec/image_optim/option_helpers_spec.rb
295
+ - spec/image_optim/path_spec.rb
275
296
  - spec/image_optim/railtie_spec.rb
276
297
  - spec/image_optim/runner/glob_helpers_spec.rb
277
298
  - spec/image_optim/runner/option_parser_spec.rb
@@ -280,6 +301,7 @@ test_files:
280
301
  - spec/image_optim/worker/pngquant_spec.rb
281
302
  - spec/image_optim/worker_spec.rb
282
303
  - spec/image_optim_spec.rb
304
+ - spec/images/broken_jpeg
283
305
  - spec/images/comparison.png
284
306
  - spec/images/decompressed.jpeg
285
307
  - spec/images/icecream.gif
@@ -1,68 +0,0 @@
1
- require 'fspath'
2
- require 'image_optim/image_meta'
3
-
4
- class ImageOptim
5
- # FSPath with additional helpful methods
6
- class ImagePath < FSPath
7
- # Holds optimized image with reference to original and its size
8
- class Optimized < DelegateClass(self)
9
- def initialize(path, original_or_size = nil)
10
- path = ImagePath.convert(path)
11
- __setobj__(path)
12
- if original_or_size.is_a?(Integer)
13
- @original = path
14
- @original_size = original_or_size
15
- elsif original_or_size
16
- @original = ImagePath.convert(original_or_size)
17
- @original_size = @original.size
18
- end
19
- end
20
-
21
- # Original path, use original_size to get its size as original can be
22
- # overwritten
23
- attr_reader :original
24
-
25
- # Stored size of original
26
- attr_reader :original_size
27
- end
28
-
29
- # Get temp path for this file with same extension
30
- def temp_path(*args, &block)
31
- ext = extname
32
- self.class.temp_file_path([basename(ext).to_s, ext], *args, &block)
33
- end
34
-
35
- # Copy file to dest preserving attributes
36
- def copy(dst)
37
- FileUtils.copy_file(self, dst, true)
38
- end
39
-
40
- # Atomic replace src with self
41
- def replace(src)
42
- src = self.class.new(src)
43
- src.temp_path(src.dirname) do |temp|
44
- src.copy(temp)
45
- temp.write(read)
46
- temp.rename(src.to_s)
47
- unlink
48
- end
49
- end
50
-
51
- # Get format using ImageSize
52
- def format
53
- image_meta = ImageMeta.for_path(self)
54
- image_meta && image_meta.format
55
- end
56
-
57
- # Read binary data
58
- def binread
59
- open('rb', &:read)
60
- end
61
-
62
- # Returns path if it is already an instance of this class otherwise new
63
- # instance
64
- def self.convert(path)
65
- path.is_a?(self) ? path : new(path)
66
- end
67
- end
68
- end
@@ -1,54 +0,0 @@
1
- require 'spec_helper'
2
- require 'image_optim/image_path'
3
-
4
- describe ImageOptim::ImagePath do
5
- before do
6
- stub_const('ImagePath', ImageOptim::ImagePath)
7
- end
8
-
9
- describe :convert do
10
- it 'returns ImagePath for string' do
11
- path = 'a'
12
-
13
- expect(ImagePath.convert(path)).to be_a(ImagePath)
14
- expect(ImagePath.convert(path)).to eq(ImagePath.new(path))
15
-
16
- expect(ImagePath.convert(path)).not_to eq(path)
17
- expect(ImagePath.convert(path)).not_to be(path)
18
- end
19
-
20
- it 'returns ImagePath for Pathname' do
21
- pathname = Pathname.new('a')
22
-
23
- expect(ImagePath.convert(pathname)).to be_a(ImagePath)
24
- expect(ImagePath.convert(pathname)).to eq(ImagePath.new(pathname))
25
-
26
- expect(ImagePath.convert(pathname)).to eq(pathname)
27
- expect(ImagePath.convert(pathname)).not_to be(pathname)
28
- end
29
-
30
- it 'returns same instance for ImagePath' do
31
- image_path = ImagePath.new('a')
32
-
33
- expect(ImagePath.convert(image_path)).to be_a(ImagePath)
34
- expect(ImagePath.convert(image_path)).to eq(ImagePath.new(image_path))
35
-
36
- expect(ImagePath.convert(image_path)).to eq(image_path)
37
- expect(ImagePath.convert(image_path)).to be(image_path)
38
- end
39
- end
40
-
41
- describe :binread do
42
- it 'reads binary data' do
43
- data = (0..255).to_a.pack('c*')
44
-
45
- path = ImagePath.temp_file_path
46
- path.write(data)
47
-
48
- expect(path.binread).to eq(data)
49
- if ''.respond_to?(:encoding)
50
- expect(path.binread.encoding).to eq(Encoding.find('ASCII-8BIT'))
51
- end
52
- end
53
- end
54
- end