Class: ImageOptim::BinResolver::Bin
- Inherits:
-
Object
- Object
- ImageOptim::BinResolver::Bin
- Defined in:
- lib/image_optim/bin_resolver/bin.rb
Overview
Holds bin name and path, gets version
Defined Under Namespace
Classes: BadVersion, UnknownVersion
Constant Summary collapse
- FAIL_CHECKS =
[ [:pngcrush, is.between?('1.7.60', '1.7.65'), 'is known to produce '\ 'broken pngs'], [:pngcrush, is == '1.7.80', 'loses one color in indexed images'], [:pngquant, is < '2.0', 'is not supported'], ].freeze
- WARN_CHECKS =
[ [:advpng, is < '1.17', 'does not use zopfli'], [:gifsicle, is < '1.85', 'does not support removing extension blocks'], [:pngcrush, is < '1.7.38', 'does not have blacken flag'], [:pngquant, is < '2.1', 'may be lossy even with quality `100-`'], [:optipng, is < '0.7', 'does not support -strip option'], ].freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#check! ⇒ Object
Run check_fail!, otherwise warn if version is known to misbehave.
-
#check_fail! ⇒ Object
Fail if version will not work properly.
-
#initialize(name, path) ⇒ Bin
constructor
A new instance of Bin.
- #to_s ⇒ Object
Constructor Details
#initialize(name, path) ⇒ Bin
Returns a new instance of Bin.
15 16 17 18 19 |
# File 'lib/image_optim/bin_resolver/bin.rb', line 15 def initialize(name, path) @name = name.to_sym @path = path.to_s @version = detect_version end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/image_optim/bin_resolver/bin.rb', line 14 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/image_optim/bin_resolver/bin.rb', line 14 def path @path end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
14 15 16 |
# File 'lib/image_optim/bin_resolver/bin.rb', line 14 def version @version end |
Instance Method Details
#check! ⇒ Object
Run check_fail!, otherwise warn if version is known to misbehave
54 55 56 57 58 59 60 61 62 |
# File 'lib/image_optim/bin_resolver/bin.rb', line 54 def check! check_fail! WARN_CHECKS.each do |bin_name, matcher, | next unless bin_name == name next unless matcher.match(version) warn "WARN: #{self} (#{matcher}) #{}" end end |
#check_fail! ⇒ Object
Fail if version will not work properly
43 44 45 46 47 48 49 50 51 |
# File 'lib/image_optim/bin_resolver/bin.rb', line 43 def check_fail! fail UnknownVersion, "didn't get version of #{self}" unless version FAIL_CHECKS.each do |bin_name, matcher, | next unless bin_name == name next unless matcher.match(version) fail BadVersion, "#{self} (#{matcher}) #{}" end end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/image_optim/bin_resolver/bin.rb', line 21 def to_s "#{name} #{version || '?'} at #{path}" end |