image_optim 0.26.3 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.appveyor.yml +9 -2
  3. data/.rubocop.yml +34 -12
  4. data/.travis.yml +18 -15
  5. data/CHANGELOG.markdown +23 -0
  6. data/CONTRIBUTING.markdown +4 -1
  7. data/Gemfile +3 -1
  8. data/LICENSE.txt +1 -1
  9. data/README.markdown +10 -3
  10. data/Vagrantfile +2 -0
  11. data/bin/image_optim +1 -0
  12. data/image_optim.gemspec +5 -7
  13. data/lib/image_optim.rb +2 -0
  14. data/lib/image_optim/bin_resolver.rb +2 -0
  15. data/lib/image_optim/bin_resolver/bin.rb +4 -0
  16. data/lib/image_optim/bin_resolver/comparable_condition.rb +3 -0
  17. data/lib/image_optim/bin_resolver/error.rb +2 -0
  18. data/lib/image_optim/bin_resolver/simple_version.rb +2 -0
  19. data/lib/image_optim/cache.rb +2 -0
  20. data/lib/image_optim/cache_path.rb +21 -2
  21. data/lib/image_optim/cmd.rb +2 -0
  22. data/lib/image_optim/config.rb +6 -4
  23. data/lib/image_optim/configuration_error.rb +2 -0
  24. data/lib/image_optim/handler.rb +2 -0
  25. data/lib/image_optim/hash_helpers.rb +2 -0
  26. data/lib/image_optim/image_meta.rb +2 -0
  27. data/lib/image_optim/non_negative_integer_range.rb +2 -0
  28. data/lib/image_optim/optimized_path.rb +3 -1
  29. data/lib/image_optim/option_definition.rb +2 -0
  30. data/lib/image_optim/option_helpers.rb +2 -0
  31. data/lib/image_optim/path.rb +30 -5
  32. data/lib/image_optim/runner.rb +2 -0
  33. data/lib/image_optim/runner/glob_helpers.rb +3 -1
  34. data/lib/image_optim/runner/option_parser.rb +5 -2
  35. data/lib/image_optim/space.rb +3 -1
  36. data/lib/image_optim/true_false_nil.rb +2 -0
  37. data/lib/image_optim/worker.rb +1 -0
  38. data/lib/image_optim/worker/advpng.rb +2 -0
  39. data/lib/image_optim/worker/class_methods.rb +4 -0
  40. data/lib/image_optim/worker/gifsicle.rb +2 -0
  41. data/lib/image_optim/worker/jhead.rb +3 -1
  42. data/lib/image_optim/worker/jpegoptim.rb +8 -4
  43. data/lib/image_optim/worker/jpegrecompress.rb +17 -0
  44. data/lib/image_optim/worker/jpegtran.rb +2 -0
  45. data/lib/image_optim/worker/optipng.rb +4 -2
  46. data/lib/image_optim/worker/pngcrush.rb +4 -2
  47. data/lib/image_optim/worker/pngout.rb +2 -0
  48. data/lib/image_optim/worker/pngquant.rb +3 -0
  49. data/lib/image_optim/worker/svgo.rb +2 -0
  50. data/script/update_worker_options_in_readme +4 -3
  51. data/script/worker_analysis +7 -3
  52. data/spec/image_optim/bin_resolver/comparable_condition_spec.rb +2 -0
  53. data/spec/image_optim/bin_resolver/simple_version_spec.rb +2 -0
  54. data/spec/image_optim/bin_resolver_spec.rb +2 -0
  55. data/spec/image_optim/cache_path_spec.rb +71 -26
  56. data/spec/image_optim/cache_spec.rb +5 -1
  57. data/spec/image_optim/cmd_spec.rb +2 -0
  58. data/spec/image_optim/config_spec.rb +2 -0
  59. data/spec/image_optim/handler_spec.rb +2 -0
  60. data/spec/image_optim/hash_helpers_spec.rb +2 -0
  61. data/spec/image_optim/image_meta_spec.rb +2 -0
  62. data/spec/image_optim/optimized_path_spec.rb +2 -0
  63. data/spec/image_optim/option_definition_spec.rb +2 -0
  64. data/spec/image_optim/option_helpers_spec.rb +2 -0
  65. data/spec/image_optim/path_spec.rb +65 -24
  66. data/spec/image_optim/runner/glob_helpers_spec.rb +2 -0
  67. data/spec/image_optim/runner/option_parser_spec.rb +2 -0
  68. data/spec/image_optim/space_spec.rb +13 -11
  69. data/spec/image_optim/worker/jpegrecompress_spec.rb +32 -0
  70. data/spec/image_optim/worker/optipng_spec.rb +2 -0
  71. data/spec/image_optim/worker/pngquant_spec.rb +2 -0
  72. data/spec/image_optim/worker_spec.rb +2 -0
  73. data/spec/image_optim_spec.rb +7 -4
  74. data/spec/images/invisiblepixels/generate +1 -0
  75. data/spec/images/quant/generate +3 -2
  76. data/spec/spec_helper.rb +2 -0
  77. metadata +14 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec91f27b4e53d23a3516908c5714011fb47bbc251e95ef9952acc62948d123af
4
- data.tar.gz: 8b5a675e29709e03bf5ca0567ae742f8d4d7f3d7e90f89ac5ef8c1935c594555
3
+ metadata.gz: 818160db3036f1fd4305077d943e59991aebe5fb1023b3c7e46db02e63c5fb37
4
+ data.tar.gz: 76c76ec43a5c05b9e35de21757928ec8793709a3db27e8a982cc46612f8d491e
5
5
  SHA512:
6
- metadata.gz: 847ee0b721a90d761ccfa4948c979e532dfd53d52f2e4c82e9df1e3301bcaba6a4217f98ae5cd5be2bcd7407339614710bd95ef381e9d422e778a4674ddeb81b
7
- data.tar.gz: 7f5b009a16df3c671ebc9a8c934cb499fd7ac47a0a464d33130ab1197ffa4b9c1f2767467226124dbd78281bcffd7864c058d8f3ff9fe7b58addfd3b6411ace7
6
+ metadata.gz: f30e6f493be6ff4e98407bb611d8fd868733af14da078b225b6708c7f6aabaa41d00b08e82c3801c788bd70c4d7278ee91a186a3dc54bc7bdcc16e685d27c7a8
7
+ data.tar.gz: b3402efe19eeb298518cfeb117f38c7aca1e0bbabe68313663107269d3ab87f8900f238db182042377adb5ebc12f69dd133ee5c922fcbde54c4b647bc9efa836
@@ -3,6 +3,7 @@ install:
3
3
  - mkdir tmp\bin || exit 0
4
4
  - set PATH=C:\Ruby25-x64\bin;%cd%\tmp\bin;%PATH%
5
5
  - ruby --version
6
+ - gem --version
6
7
  - bundle package --all
7
8
 
8
9
  - ps: git --work-tree=tmp\bin checkout origin/windows-binaries -- '*.exe'
@@ -26,10 +27,16 @@ test_script:
26
27
  - ps: |
27
28
  $path = $env:Path
28
29
  $rubypaths = ls -Path C:\Ruby*\bin
29
- foreach ($rubypath in $rubypaths[-2, -1]) {
30
- echo "################################################################################"
30
+ foreach ($rubypath in $rubypaths) {
31
31
  $env:Path = "$rubypath;" + $path
32
+ ruby -e "abort unless RUBY_VERSION > '2.3'"
33
+ if ($LASTEXITCODE -gt 0) {
34
+ continue
35
+ }
36
+
37
+ echo "################################ $rubypath ################################"
32
38
  ruby --version
39
+ gem --version
33
40
  bundle package --all
34
41
  bundle install --local -j4
35
42
  bundle exec rspec
@@ -2,6 +2,7 @@ AllCops:
2
2
  Exclude:
3
3
  - '*.gemspec'
4
4
  - 'vendor/**/*'
5
+ NewCops: enable
5
6
 
6
7
  Bundler/OrderedGems:
7
8
  Enabled: false
@@ -9,6 +10,9 @@ Bundler/OrderedGems:
9
10
  Layout/AccessModifierIndentation:
10
11
  EnforcedStyle: outdent
11
12
 
13
+ Layout/AssignmentIndentation:
14
+ Enabled: false
15
+
12
16
  Layout/CaseIndentation:
13
17
  EnforcedStyle: end
14
18
 
@@ -18,18 +22,18 @@ Layout/DotPosition:
18
22
  Layout/EndAlignment:
19
23
  EnforcedStyleAlignWith: variable
20
24
 
21
- Layout/IndentArray:
25
+ Layout/FirstArrayElementIndentation:
22
26
  EnforcedStyle: consistent
23
27
 
24
- Layout/IndentAssignment:
25
- Enabled: false
26
-
27
- Layout/IndentHash:
28
+ Layout/FirstHashElementIndentation:
28
29
  EnforcedStyle: consistent
29
30
 
30
- Layout/IndentHeredoc:
31
+ Layout/HeredocIndentation:
31
32
  Enabled: false
32
33
 
34
+ Layout/LineLength:
35
+ Max: 120
36
+
33
37
  Layout/RescueEnsureAlignment:
34
38
  Enabled: false
35
39
 
@@ -47,10 +51,10 @@ Lint/AmbiguousBlockAssociation:
47
51
  Lint/NestedPercentLiteral:
48
52
  Enabled: false
49
53
 
50
- Lint/UnneededRequireStatement:
54
+ Lint/RedundantRequireStatement:
51
55
  Enabled: false
52
56
 
53
- Lint/UnneededSplatExpansion:
57
+ Lint/RedundantSplatExpansion:
54
58
  Enabled: false
55
59
 
56
60
  Metrics/AbcSize:
@@ -68,19 +72,19 @@ Metrics/ClassLength:
68
72
  Metrics/CyclomaticComplexity:
69
73
  Max: 11
70
74
 
71
- Metrics/LineLength:
72
- Max: 120
73
-
74
75
  Metrics/MethodLength:
75
76
  Max: 25
76
77
 
77
78
  Metrics/PerceivedComplexity:
78
- Max: 8
79
+ Max: 10
79
80
 
80
81
  Security/MarshalLoad:
81
82
  Exclude:
82
83
  - 'script/worker_analysis'
83
84
 
85
+ Style/AccessorGrouping:
86
+ Enabled: false
87
+
84
88
  Style/Alias:
85
89
  EnforcedStyle: prefer_alias_method
86
90
 
@@ -99,18 +103,36 @@ Style/ExpandPathArguments:
99
103
  Style/FormatStringToken:
100
104
  Enabled: false
101
105
 
106
+ Style/HashEachMethods:
107
+ Enabled: true
108
+
102
109
  Style/HashSyntax:
103
110
  EnforcedStyle: hash_rockets
104
111
 
112
+ Style/HashTransformKeys:
113
+ Enabled: false
114
+
115
+ Style/HashTransformValues:
116
+ Enabled: false
117
+
105
118
  Style/IfUnlessModifier:
106
119
  Enabled: false
107
120
 
121
+ Style/NumericPredicate:
122
+ EnforcedStyle: comparison
123
+
124
+ Style/OptionalBooleanParameter:
125
+ Enabled: false
126
+
108
127
  Style/ParallelAssignment:
109
128
  Enabled: false
110
129
 
111
130
  Style/RescueStandardError:
112
131
  EnforcedStyle: implicit
113
132
 
133
+ Style/SafeNavigation:
134
+ Enabled: false
135
+
114
136
  Style/Semicolon:
115
137
  AllowAsExpressionSeparator: true
116
138
 
@@ -1,4 +1,5 @@
1
1
  sudo: false
2
+ dist: trusty
2
3
  language: ruby
3
4
  cache:
4
5
  bundler: true
@@ -6,37 +7,39 @@ cache:
6
7
  - $(npm root)
7
8
  - ~/bin
8
9
  rvm:
9
- - '1.8.7-p371'
10
10
  - '1.9.3-p551'
11
11
  - '2.0.0-p648'
12
12
  - '2.1.10'
13
13
  - '2.2.10'
14
- - '2.3.7'
15
- - '2.4.4'
16
- - '2.5.1'
17
- - 'jruby-9.0.5.0'
18
- - 'jruby-9.1.9.0'
14
+ - '2.3.8'
15
+ - '2.4.10'
16
+ - '2.5.8'
17
+ - '2.6.6'
18
+ - '2.7.2'
19
+ - 'jruby-9.2.11.1'
19
20
  script:
20
21
  - bundle exec image_optim --info
21
22
  - bundle exec rspec
22
23
  before_install:
23
- - gem update --system
24
- - gem install bundler
24
+ - 'echo "gem: --no-ri --no-rdoc --no-document" > ~/.gemrc'
25
+ - gem install rubygems-update || gem install rubygems-update --version '< 3'
26
+ - update_rubygems
27
+ - gem install bundler || gem install bundler --version '< 2'
25
28
  - nvm install stable
26
29
  - mkdir -p ~/bin
27
30
  - command -v svgo || npm install -g svgo
28
- - command -v pngout || curl -L "http://static.jonof.id.au/dl/kenutils/pngout-20150319-linux.tar.gz" | tar -xz -C ~/bin --strip-components 2 --wildcards '*/x86_64/pngout'
31
+ - command -v pngout || curl -L "https://www.jonof.id.au/files/kenutils/pngout-20200115-linux.tar.gz" | tar -xz -C ~/bin --strip-components 2 --wildcards '*/amd64/pngout'
29
32
  matrix:
30
33
  include:
31
- - env: CODECLIMATE=✓
32
- rvm: '2.4.4'
34
+ - env: CODECLIMATE=1
35
+ rvm: '2.4.10'
33
36
  after_success: bundle exec codeclimate-test-reporter
34
- - env: RUBOCOP=✓
35
- rvm: '2.4.4'
37
+ - env: RUBOCOP=1
38
+ rvm: '2.4.10'
36
39
  script: bundle exec rubocop
37
40
  before_install: gem update --system && gem install bundler
38
- - env: CHECK_RUBIES=✓
39
- rvm: '2.4.4'
41
+ - env: CHECK_RUBIES=1
42
+ rvm: '2.4.10'
40
43
  script: bundle exec travis_check_rubies
41
44
  before_install: gem update --system && gem install bundler
42
45
  addons:
@@ -2,6 +2,29 @@
2
2
 
3
3
  ## unreleased
4
4
 
5
+ ## v0.28.0 (2020-12-18)
6
+
7
+ * Fix and update list of markers in jpegoptim worker: allow to pass `com` instead of incorrect `comments` and add missing `xmp` and `none` [#188](https://github.com/toy/image_optim/issues/188) [@toy](https://github.com/toy)
8
+ * Add `--skip-if-larger` flag to pngquant worker. The pngquant worker already does this, but this will make it fail faster. [#125](https://github.com/toy/image_optim/pull/125) [#181](https://github.com/toy/image_optim/pull/181) [@iggant](https://github.com/iggant) [@oblakeerickson](https://github.com/oblakeerickson)
9
+ * Add `method` option for jpegrecompress, default to `ssim` [#102](https://github.com/toy/image_optim/issues/102) [#103](https://github.com/toy/image_optim/pull/103) [#182](https://github.com/toy/image_optim/pull/182) [@ramiroaraujo](https://github.com/ramiroaraujo) [@oblakeerickson](https://github.com/oblakeerickson)
10
+
11
+ ## v0.27.1 (2020-09-30)
12
+
13
+ * Fixed atomic replacement for case when equal `File::Stat#dev` doesn't mean that file can be linked [#180](https://github.com/toy/image_optim/issues/180) [@toy](https://github.com/toy)
14
+
15
+ ## v0.27.0 (2020-08-27)
16
+
17
+ * Use `.tmp` as the extension for temporary file if it needs to be created for atomic replacement [#178](https://github.com/toy/image_optim/issues/178) [@toy](https://github.com/toy)
18
+ * Don't create a temporary file in destination directory for atomic replacement if temporary directory is on same device as destination [#178](https://github.com/toy/image_optim/issues/178) [@toy](https://github.com/toy)
19
+
20
+ ## v0.26.5 (2019-07-14)
21
+
22
+ * Remove deprecated `rubyforge_project` attribute from gemspec [rubygems/rubygems#2436](https://github.com/rubygems/rubygems/pull/2436) [@toy](https://github.com/toy)
23
+
24
+ ## v0.26.4 (2019-05-23)
25
+
26
+ * Enable frozen string literals [@toy](https://github.com/toy)
27
+
5
28
  ## v0.26.3 (2018-10-13)
6
29
 
7
30
  * Handle `vnone` version of `advpng` that was erroneously produced for `ubuntu` and `homebrew` [#165](https://github.com/toy/image_optim/issues/165) [@toy](https://github.com/toy)
@@ -2,7 +2,10 @@
2
2
 
3
3
  * Create topic/feature branch: `git checkout -b awesome-changes`
4
4
  * Commit…
5
- * Add entry at the top of [ChangeLog](CHANGELOG.markdown)
5
+ * Add an entry at the top (after ## unreleased) of [ChangeLog](CHANGELOG.markdown), include:
6
+ * Issues (`[#123](https://github.com/toy/image_optim/issues/123)`)
7
+ * Pull requests (`[#123](https://github.com/toy/image_optim/pull/123)`)
8
+ * Authors (`[@octocat](https://github.com/octocat)`)
6
9
  * Run tests: `bundle exec rspec`
7
10
  * Check code style: `bundle exec rubocop`
8
11
  * Rebase on master and squash commits to logical units
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
@@ -10,6 +12,6 @@ if ENV['CODECLIMATE']
10
12
  end
11
13
  end
12
14
 
13
- if RUBY_VERSION >= '2.0'
15
+ if ENV['CHECK_RUBIES']
14
16
  gem 'travis_check_rubies', '~> 0.2'
15
17
  end
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-2018 Ivan Kuchin
1
+ Copyright (c) 2012-2020 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
@@ -27,6 +27,8 @@ Based on [ImageOptim.app](http://imageoptim.com/).
27
27
 
28
28
  Documentation for [latest gem version](http://rubydoc.info/gems/image_optim/frames) and [master branch](http://rubydoc.info/github/toy/image_optim/master/frames).
29
29
 
30
+ A test application with latest `image_optim` and `image_optim_pack` is available on heroku: https://iopack.herokuapp.com/.
31
+
30
32
  ## Gem installation
31
33
 
32
34
  ```sh
@@ -58,7 +60,7 @@ With version:
58
60
 
59
61
  <!---<update-version>-->
60
62
  ```ruby
61
- gem 'image_optim', '~> 0.26'
63
+ gem 'image_optim', '~> 0.28'
62
64
  ```
63
65
  <!---</update-version>-->
64
66
 
@@ -275,6 +277,10 @@ optipng:
275
277
  level: 5
276
278
  ```
277
279
 
280
+ ### Temporary directory
281
+
282
+ `image_optim` uses standard ruby library for creating temporary files. Temporary directory can be changed using one of `TMPDIR`, `TMP` or `TEMP` environment variables.
283
+
278
284
  ## Options
279
285
 
280
286
  * `:nice` — Nice level, priority of all used tools with higher value meaning lower priority, in range `-20..19`, negative values can be set only if run by root user *(defaults to `10`)*
@@ -304,12 +310,13 @@ Worker has no options
304
310
 
305
311
  ### jpegoptim:
306
312
  * `:allow_lossy` — Allow limiting maximum quality *(defaults to `false`)*
307
- * `:strip` — List of extra markers to strip: `:comments`, `:exif`, `:iptc`, `:icc` or `:all` *(defaults to `:all`)*
313
+ * `:strip` — List of markers to strip: `:com`, `:exif`, `:iptc`, `:icc`, `:xmp`, `:none` or `:all` *(defaults to `:all`)*
308
314
  * `:max_quality` — Maximum image quality factor `0`..`100`, ignored in default/lossless mode *(defaults to `100`)*
309
315
 
310
316
  ### jpegrecompress:
311
317
  * `:allow_lossy` — Allow worker, it is always lossy *(defaults to `false`)*
312
318
  * `:quality` — JPEG quality preset: `0` - low, `1` - medium, `2` - high, `3` - veryhigh *(defaults to `3`)*
319
+ * `:method` — Comparison Metric: `mpe` - Mean pixel error, `ssim` - Structural similarity, `ms-ssim` - Multi-scale structural similarity (slow!), `smallfry` - Linear-weighted BBCQ-like (may be patented) *(defaults to ssim)*
313
320
 
314
321
  ### jpegtran:
315
322
  * `:copy_chunks` — Copy all chunks *(defaults to `false`)*
@@ -355,4 +362,4 @@ In separate file [CHANGELOG.markdown](CHANGELOG.markdown).
355
362
 
356
363
  ## Copyright
357
364
 
358
- Copyright (c) 2012-2018 Ivan Kuchin. See [LICENSE.txt](LICENSE.txt) for details.
365
+ Copyright (c) 2012-2020 Ivan Kuchin. See [LICENSE.txt](LICENSE.txt) for details.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Vagrant.configure('2') do |config|
2
4
  config.vm.box = 'ubuntu/precise64'
3
5
 
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
+ # frozen_string_literal: true
3
4
 
4
5
  require 'image_optim/runner'
5
6
  require 'image_optim/runner/option_parser'
@@ -2,17 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'image_optim'
5
- s.version = '0.26.3'
5
+ s.version = '0.28.0'
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, pngcrush, pngout, pngquant, svgo)}
7
- s.homepage = "http://github.com/toy/#{s.name}"
7
+ s.homepage = "https://github.com/toy/#{s.name}"
8
8
  s.authors = ['Ivan Kuchin']
9
9
  s.license = 'MIT'
10
10
 
11
- s.rubyforge_project = s.name
12
-
13
11
  s.metadata = {
14
12
  'bug_tracker_uri' => "https://github.com/toy/#{s.name}/issues",
15
- 'changelog_uri' => "https://github.com/toy/#{s.name}/CHANGELOG.markdown",
13
+ 'changelog_uri' => "https://github.com/toy/#{s.name}/blob/master/CHANGELOG.markdown",
16
14
  'documentation_uri' => "https://www.rubydoc.info/gems/#{s.name}/#{s.version}",
17
15
  'source_code_uri' => "https://github.com/toy/#{s.name}",
18
16
  }
@@ -35,7 +33,7 @@ EOF
35
33
 
36
34
  s.add_development_dependency 'image_optim_pack', '~> 0.2', '>= 0.2.2'
37
35
  s.add_development_dependency 'rspec', '~> 3.0'
38
- if RUBY_VERSION >= '2.2'
39
- s.add_development_dependency 'rubocop', '~> 0.59'
36
+ if RUBY_VERSION >= '2.4' && !Gem.win_platform? && !defined?(JRUBY_VERSION)
37
+ s.add_development_dependency 'rubocop', '~> 1.0'
40
38
  end
41
39
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'image_optim/bin_resolver'
2
4
  require 'image_optim/cache'
3
5
  require 'image_optim/config'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thread'
2
4
  require 'fspath'
3
5
  require 'image_optim/bin_resolver/error'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'image_optim/bin_resolver/error'
2
4
  require 'image_optim/bin_resolver/simple_version'
3
5
  require 'image_optim/bin_resolver/comparable_condition'
@@ -12,9 +14,11 @@ class ImageOptim
12
14
  # Holds bin name and path, gets version
13
15
  class Bin
14
16
  class UnknownVersion < Error; end
17
+
15
18
  class BadVersion < Error; end
16
19
 
17
20
  attr_reader :name, :path, :version
21
+
18
22
  def initialize(name, path)
19
23
  @name = name.to_sym
20
24
  @path = path.to_s
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ImageOptim
2
4
  class BinResolver
3
5
  # Allows to externalize conditions for an instance of Comparable to use in
@@ -24,6 +26,7 @@ class ImageOptim
24
26
  end
25
27
 
26
28
  attr_reader :method, :args
29
+
27
30
  def initialize(method, *args)
28
31
  @method, @args = method.to_sym, args
29
32
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ImageOptim
2
4
  class BinResolver
3
5
  # Base error during bin resolving
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class ImageOptim
2
4
  class BinResolver
3
5
  # Allows comparision of simple versions, only numbers separated by dots are
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'digest/sha1'
2
4
  require 'fspath'
3
5
  require 'image_optim/cache_path'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'image_optim/path'
2
4
 
3
5
  class ImageOptim
@@ -5,8 +7,25 @@ class ImageOptim
5
7
  class CachePath < Path
6
8
  # Atomic replace dst with self
7
9
  def replace(dst)
8
- dst = self.class.new(dst)
9
- dst.temp_path(dst.dirname) do |temp|
10
+ dst = self.class.convert(dst)
11
+ tmpdir = [dirname, Path.new(Dir.tmpdir)].find do |dir|
12
+ dir.same_dev?(dst.dirname)
13
+ end
14
+ if tmpdir
15
+ begin
16
+ replace_using_tmp_file(dst, tmpdir)
17
+ rescue Errno::EXDEV
18
+ replace_using_tmp_file(dst, dst.dirname)
19
+ end
20
+ else
21
+ replace_using_tmp_file(dst, dst.dirname)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def replace_using_tmp_file(dst, tmpdir)
28
+ dst.temp_path_with_tmp_ext(tmpdir) do |temp|
10
29
  copy(temp)
11
30
  dst.copy_metadata(temp)
12
31
  temp.rename(dst.to_s)