image_optim 0.31.2 → 0.31.3

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
  SHA256:
3
- metadata.gz: 7197f37a1a5cd0a61248ccd4ef6b08f2c05ff8f084866da48f76b038bac4e4ec
4
- data.tar.gz: 7be50ee48142fd8775022855624a7ea642436b11d8ca260f322742a7814d513a
3
+ metadata.gz: edffa5fea26babe4654e681a829753b7df3d5d80a158a7b3d2974e97b46a49a5
4
+ data.tar.gz: 467cdc261c726ac97b5252b6b93507e4fac6e5d3804bd7fc17636ba32a6f565a
5
5
  SHA512:
6
- metadata.gz: 02dbbb2520b6250fc2a5262c2c0524a42519e3a969683efe95b384f0e0cc5b4247638e74e5766ce016ccc462f3646f3ab7e7bf363299b1f6e79894b59af69df2
7
- data.tar.gz: 6673410e57ba7e01f0f146678f2b74e8bbdcd97ccccb320679f24acb860ea46be229b2184383ee59e5a7bac6a4977f506e113a68bf53f975c1b296e9e28310d1
6
+ metadata.gz: '0379e12d0d4ef8dd0af9e047a728bc9acf0177136b83b9b4aced834238067d0ab3248350bc1813cc76b33eaa3fc5751032a72c14f03a81d3dad9eed61abb0b99'
7
+ data.tar.gz: 68489aa06564d6f8555adf409c23454fb4b9d57fa74117cd9b1174787ad65bc56a101a8cce9e455ba0e3474f1a1b7e8c8b9707549768be1bb3a94a063c200721
@@ -20,12 +20,12 @@ jobs:
20
20
  - '2.7'
21
21
  - '3.0'
22
22
  - '3.1'
23
- - jruby-9.2
23
+ - '3.2'
24
24
  - jruby-9.3
25
25
  - jruby-9.4
26
26
  fail-fast: false
27
27
  steps:
28
- - uses: actions/checkout@v2
28
+ - uses: actions/checkout@v3
29
29
  - uses: ruby/setup-ruby@v1
30
30
  with:
31
31
  ruby-version: "${{ matrix.ruby }}"
@@ -43,9 +43,11 @@ jobs:
43
43
  - '2.7'
44
44
  - '3.0'
45
45
  - '3.1'
46
+ - '3.2'
46
47
  fail-fast: false
48
+ continue-on-error: ${{ matrix.ruby == '3.2' }}
47
49
  steps:
48
- - uses: actions/checkout@v2
50
+ - uses: actions/checkout@v3
49
51
  - uses: ruby/setup-ruby@v1
50
52
  with:
51
53
  ruby-version: "${{ matrix.ruby }}"
@@ -70,10 +72,10 @@ jobs:
70
72
  env:
71
73
  CC_TEST_REPORTER_ID: b433c6540d220a2da0663670c9b260806bafdb3a43c6f22b2e81bfb1f87b12fe
72
74
  steps:
73
- - uses: actions/checkout@v2
75
+ - uses: actions/checkout@v3
74
76
  - uses: ruby/setup-ruby@v1
75
77
  with:
76
- ruby-version: '3.1'
78
+ ruby-version: '3'
77
79
  bundler-cache: true
78
80
  - run: sudo npm install -g svgo
79
81
  - run: curl -L "https://github.com/shssoichiro/oxipng/releases/download/v4.0.3/oxipng-4.0.3-x86_64-unknown-linux-musl.tar.gz" | tar -xz -C /usr/local/bin --strip-components 1 --wildcards '*oxipng'
@@ -19,7 +19,7 @@ jobs:
19
19
  language: [ 'ruby' ]
20
20
 
21
21
  steps:
22
- - uses: actions/checkout@v2
22
+ - uses: actions/checkout@v3
23
23
 
24
24
  - uses: github/codeql-action/init@v1
25
25
  with:
@@ -8,9 +8,9 @@ jobs:
8
8
  rubocop:
9
9
  runs-on: ubuntu-latest
10
10
  steps:
11
- - uses: actions/checkout@v2
11
+ - uses: actions/checkout@v3
12
12
  - uses: ruby/setup-ruby@v1
13
13
  with:
14
- ruby-version: '3.1'
14
+ ruby-version: '3'
15
15
  bundler-cache: true
16
16
  - run: bundle exec rubocop
data/CHANGELOG.markdown CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## unreleased
4
4
 
5
+ ## v0.31.3 (2023-02-17)
6
+
7
+ * Support Psych4/Ruby 3.1 changes to use safe_yaml methods by default [#203](https://github.com/toy/image_optim/issues/203) [#204](https://github.com/toy/image_optim/pull/204) [@oscillot](https://github.com/oscillot) [@toy](https://github.com/toy)
8
+
5
9
  ## v0.31.2 (2022-11-27)
6
10
 
7
11
  * Support jruby 9.4 [@toy](https://github.com/toy)
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2022 Ivan Kuchin
1
+ Copyright (c) 2012-2023 Ivan Kuchin
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.markdown CHANGED
@@ -1,7 +1,7 @@
1
1
  [![Gem Version](https://img.shields.io/gem/v/image_optim?logo=rubygems)](https://rubygems.org/gems/image_optim)
2
- [![Build Status](https://img.shields.io/github/workflow/status/toy/image_optim/check/master?logo=github)](https://github.com/toy/image_optim/actions/workflows/check.yml)
3
- [![Rubocop](https://img.shields.io/github/workflow/status/toy/image_optim/rubocop/master?label=rubocop&logo=rubocop)](https://github.com/toy/image_optim/actions/workflows/rubocop.yml)
4
- [![CodeQL](https://img.shields.io/github/workflow/status/toy/image_optim/codeql/master?label=codeql&logo=github)](https://github.com/toy/image_optim/actions/workflows/codeql.yml)
2
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/toy/image_optim/check.yml?logo=github)](https://github.com/toy/image_optim/actions/workflows/check.yml)
3
+ [![Rubocop](https://img.shields.io/github/actions/workflow/status/toy/image_optim/rubocop.yml?label=rubocop&logo=rubocop)](https://github.com/toy/image_optim/actions/workflows/rubocop.yml)
4
+ [![CodeQL](https://img.shields.io/github/actions/workflow/status/toy/image_optim/codeql.yml?label=codeql&logo=github)](https://github.com/toy/image_optim/actions/workflows/codeql.yml)
5
5
  [![Code Climate](https://img.shields.io/codeclimate/maintainability/toy/image_optim?logo=codeclimate)](https://codeclimate.com/github/toy/image_optim)
6
6
  [![Code Climate Coverage](https://img.shields.io/codeclimate/coverage/toy/image_optim?logo=codeclimate)](https://codeclimate.com/github/toy/image_optim)
7
7
  [![Depfu](https://img.shields.io/depfu/toy/image_optim)](https://depfu.com/github/toy/image_optim)
@@ -390,4 +390,4 @@ In separate file [CHANGELOG.markdown](CHANGELOG.markdown).
390
390
 
391
391
  ## Copyright
392
392
 
393
- Copyright (c) 2012-2022 Ivan Kuchin. See [LICENSE.txt](LICENSE.txt) for details.
393
+ Copyright (c) 2012-2023 Ivan Kuchin. See [LICENSE.txt](LICENSE.txt) for details.
data/image_optim.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'image_optim'
5
- s.version = '0.31.2'
5
+ s.version = '0.31.3'
6
6
  s.summary = %q{Command line tool and ruby interface to optimize (lossless compress, optionally lossy) jpeg, png, gif and svg images using external utilities (advpng, gifsicle, jhead, jpeg-recompress, jpegoptim, jpegrescan, jpegtran, optipng, oxipng, pngcrush, pngout, pngquant, svgo)}
7
7
  s.homepage = "https://github.com/toy/#{s.name}"
8
8
  s.authors = ['Ivan Kuchin']
@@ -42,7 +42,7 @@ class ImageOptim
42
42
  if optimized
43
43
  tmp = FSPath.temp_file_path(digest, @cache_dir)
44
44
  FileUtils.mv(optimized, tmp)
45
- tmp.chmod(0o666 & ~File.umask)
45
+ tmp.chmod(~File.umask & 0o666)
46
46
  tmp.rename(cached)
47
47
  cached_path = CachePath.convert(cached)
48
48
 
@@ -33,7 +33,7 @@ class ImageOptim
33
33
  end
34
34
  return {} unless File.size?(full_path)
35
35
 
36
- config = YAML.load_file(full_path)
36
+ config = load_yaml_file(full_path)
37
37
  unless config.is_a?(Hash)
38
38
  fail "expected hash, got #{config.inspect}"
39
39
  end
@@ -43,6 +43,14 @@ class ImageOptim
43
43
  warn "exception when reading #{full_path}: #{e}"
44
44
  {}
45
45
  end
46
+
47
+ def load_yaml_file(path)
48
+ if YAML.respond_to?(:safe_load_file)
49
+ YAML.safe_load_file(path, permitted_classes: [Range])
50
+ else
51
+ YAML.load_file(path)
52
+ end
53
+ end
46
54
  end
47
55
 
48
56
  # Merge config from files with passed options
@@ -202,13 +202,13 @@ ImageOptim::Runner::OptionParser::DEFINE = proc do |op, options|
202
202
  type, marking = case
203
203
  when [TrueClass, FalseClass, ImageOptim::TrueFalseNil].include?(type)
204
204
  [type, 'B']
205
- when Integer >= type
205
+ when type <= Integer
206
206
  [Integer, 'N']
207
- when Array >= type
207
+ when type <= Array
208
208
  [Array, 'a,b,c']
209
- when String >= type
209
+ when type <= String
210
210
  [String, 'S']
211
- when ImageOptim::NonNegativeIntegerRange == type
211
+ when type == ImageOptim::NonNegativeIntegerRange
212
212
  [type, 'M-N']
213
213
  else
214
214
  fail "Unknown type #{type}"
@@ -38,7 +38,7 @@ class ImageOptim
38
38
  if size_a == size_b
39
39
  "------ #{Space::EMPTY_SPACE}"
40
40
  else
41
- percent = 100 - (100.0 * size_b / size_a)
41
+ percent = 100 - (size_b * 100.0 / size_a)
42
42
  space = Space.space(size_a - size_b)
43
43
  format('%5.2f%% %s', percent, space)
44
44
  end
@@ -6,7 +6,7 @@ class ImageOptim
6
6
  SIZE_SYMBOLS = %w[B K M G T P E].freeze
7
7
  BASE = 1024.0
8
8
  PRECISION = 1
9
- LENGTH = 4 + PRECISION + 1
9
+ LENGTH = PRECISION + 4 + 1
10
10
 
11
11
  EMPTY_SPACE = ' ' * LENGTH
12
12
 
@@ -0,0 +1,3 @@
1
+ range: !ruby/range 80..99
2
+ number: 3
3
+ string: foo
@@ -223,7 +223,7 @@ describe ImageOptim::Config do
223
223
  with(path).and_return(full_path)
224
224
  expect(File).to receive(:size?).
225
225
  with(full_path).and_return(true)
226
- expect(YAML).to receive(:load_file).
226
+ expect(IOConfig).to receive(:load_yaml_file).
227
227
  with(full_path).and_return(stringified)
228
228
 
229
229
  expect(IOConfig.read_options(path)).to eq(symbolized)
@@ -235,7 +235,7 @@ describe ImageOptim::Config do
235
235
  with(path).and_return(full_path)
236
236
  expect(File).to receive(:size?).
237
237
  with(full_path).and_return(true)
238
- expect(YAML).to receive(:load_file).
238
+ expect(IOConfig).to receive(:load_yaml_file).
239
239
  with(full_path).and_return([:config])
240
240
 
241
241
  expect(IOConfig.read_options(path)).to eq({})
@@ -247,10 +247,46 @@ describe ImageOptim::Config do
247
247
  with(path).and_return(full_path)
248
248
  expect(File).to receive(:size?).
249
249
  with(full_path).and_return(true)
250
- expect(YAML).to receive(:load_file).
250
+ expect(IOConfig).to receive(:load_yaml_file).
251
251
  with(full_path).and_raise
252
252
 
253
253
  expect(IOConfig.read_options(path)).to eq({})
254
254
  end
255
255
  end
256
+
257
+ describe '.load_yaml_file' do
258
+ describe 'selecting method' do
259
+ let(:path){ 'foo' }
260
+ let(:result){ 'bar' }
261
+ let(:yaml){ double }
262
+
263
+ before do
264
+ stub_const('YAML', yaml)
265
+ end
266
+
267
+ it 'uses YAML.safe_load_file if available' do
268
+ expect(yaml).to receive(:safe_load_file).
269
+ with(path, permitted_classes: [Range]).and_return(result)
270
+
271
+ expect(IOConfig.load_yaml_file(path)).to eq(result)
272
+ end
273
+
274
+ it 'uses YAML.load if safe_load_file is not available' do
275
+ expect(yaml).to receive(:load_file).
276
+ with(path).and_return(result)
277
+
278
+ expect(IOConfig.load_yaml_file(path)).to eq(result)
279
+ end
280
+ end
281
+
282
+ it 'handles yaml that includes `!ruby/range`' do
283
+ path = 'spec/files/config_with_range.yaml'
284
+
285
+ expect(IOConfig.load_yaml_file(path)).to eq({
286
+ 'range' => 80..99,
287
+ 'number' => 3,
288
+ 'string' => 'foo',
289
+ })
290
+ end
291
+ end
256
292
  end
@@ -121,9 +121,9 @@ describe ImageOptim do
121
121
  it 'sends timeout to every worker' do
122
122
  some_path = instance_of(ImageOptim::Path)
123
123
 
124
- expect(workers[0]).to receive(:optimize).with(some_path, some_path, timeout: timer)
125
- expect(workers[1]).to receive(:optimize).with(some_path, some_path, timeout: timer)
126
- expect(workers[2]).to receive(:optimize).with(some_path, some_path, timeout: timer)
124
+ expect(workers[0]).to receive(:optimize).with(some_path, some_path, {timeout: timer})
125
+ expect(workers[1]).to receive(:optimize).with(some_path, some_path, {timeout: timer})
126
+ expect(workers[2]).to receive(:optimize).with(some_path, some_path, {timeout: timer})
127
127
 
128
128
  image_optim.optimize_image(path)
129
129
  end
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.31.2
4
+ version: 0.31.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Kuchin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-27 00:00:00.000000000 Z
11
+ date: 2023-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fspath
@@ -232,6 +232,7 @@ files:
232
232
  - script/template/worker_analysis.erb
233
233
  - script/update_worker_options_in_readme
234
234
  - script/worker_analysis
235
+ - spec/files/config_with_range.yaml
235
236
  - spec/image_optim/bin_resolver/comparable_condition_spec.rb
236
237
  - spec/image_optim/bin_resolver/simple_version_spec.rb
237
238
  - spec/image_optim/bin_resolver_spec.rb
@@ -292,7 +293,7 @@ licenses:
292
293
  metadata:
293
294
  bug_tracker_uri: https://github.com/toy/image_optim/issues
294
295
  changelog_uri: https://github.com/toy/image_optim/blob/master/CHANGELOG.markdown
295
- documentation_uri: https://www.rubydoc.info/gems/image_optim/0.31.2
296
+ documentation_uri: https://www.rubydoc.info/gems/image_optim/0.31.3
296
297
  source_code_uri: https://github.com/toy/image_optim
297
298
  post_install_message: |
298
299
  Rails image assets optimization is extracted into image_optim_rails gem
@@ -319,6 +320,7 @@ summary: Command line tool and ruby interface to optimize (lossless compress, op
319
320
  jhead, jpeg-recompress, jpegoptim, jpegrescan, jpegtran, optipng, oxipng, pngcrush,
320
321
  pngout, pngquant, svgo)
321
322
  test_files:
323
+ - spec/files/config_with_range.yaml
322
324
  - spec/image_optim/bin_resolver/comparable_condition_spec.rb
323
325
  - spec/image_optim/bin_resolver/simple_version_spec.rb
324
326
  - spec/image_optim/bin_resolver_spec.rb