Class: Jekyll::Images::Runner
- Inherits:
-
Object
- Object
- Jekyll::Images::Runner
- Defined in:
- lib/jekyll/images/runner.rb
Overview
Runner for optimizations
Instance Attribute Summary collapse
-
#binary ⇒ Object
readonly
Returns the value of attribute binary.
-
#bytes_after ⇒ Object
readonly
Returns the value of attribute bytes_after.
-
#bytes_before ⇒ Object
readonly
Returns the value of attribute bytes_before.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#interlaced ⇒ Object
readonly
Returns the value of attribute interlaced.
Class Method Summary collapse
- .mime(file) ⇒ Object
-
.register(mime, class_name) ⇒ Object
XXX: This only allows one optimization per file type, we could make it an array but how do we garantee order? Maybe adding a priority field?.
- .run(file, interlaced = false) ⇒ Object
- .runners ⇒ Object
Instance Method Summary collapse
- #exist? ⇒ Boolean
-
#initialize(file, interlaced = false) ⇒ Runner
constructor
A new instance of Runner.
- #run ⇒ Object
Constructor Details
#initialize(file, interlaced = false) ⇒ Runner
Returns a new instance of Runner.
37 38 39 40 41 |
# File 'lib/jekyll/images/runner.rb', line 37 def initialize(file, interlaced = false) @file = file @bytes_before = bytes_after @interlaced = interlaced end |
Instance Attribute Details
#binary ⇒ Object (readonly)
Returns the value of attribute binary.
10 11 12 |
# File 'lib/jekyll/images/runner.rb', line 10 def binary @binary end |
#bytes_after ⇒ Object (readonly)
Returns the value of attribute bytes_after.
10 11 12 |
# File 'lib/jekyll/images/runner.rb', line 10 def bytes_after @bytes_after end |
#bytes_before ⇒ Object (readonly)
Returns the value of attribute bytes_before.
10 11 12 |
# File 'lib/jekyll/images/runner.rb', line 10 def bytes_before @bytes_before end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
10 11 12 |
# File 'lib/jekyll/images/runner.rb', line 10 def file @file end |
#interlaced ⇒ Object (readonly)
Returns the value of attribute interlaced.
10 11 12 |
# File 'lib/jekyll/images/runner.rb', line 10 def interlaced @interlaced end |
Class Method Details
.mime(file) ⇒ Object
25 26 27 28 29 |
# File 'lib/jekyll/images/runner.rb', line 25 def mime(file) @@mime ||= FileMagic.new @@mime.file(file, true) end |
.register(mime, class_name) ⇒ Object
XXX: This only allows one optimization per file type, we could make it an array but how do we garantee order? Maybe adding a priority field?
16 17 18 19 |
# File 'lib/jekyll/images/runner.rb', line 16 def register(mime, class_name) @@runners ||= {} @@runners[mime] = class_name end |
.run(file, interlaced = false) ⇒ Object
31 32 33 34 |
# File 'lib/jekyll/images/runner.rb', line 31 def run(file, interlaced = false) type = mime(file) runners[type].new(file, interlaced).run if runners[type] end |
.runners ⇒ Object
21 22 23 |
# File 'lib/jekyll/images/runner.rb', line 21 def runners @@runners end |
Instance Method Details
#exist? ⇒ Boolean
47 48 49 50 51 52 |
# File 'lib/jekyll/images/runner.rb', line 47 def exist? @binary, _, status = Open3.capture3("which #{self.class::BINARY}") @binary.chomp! status.success? end |
#run ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/jekyll/images/runner.rb', line 54 def run return unless exist? _, status = Open3.capture2e(*command) [bytes_before, bytes_after] if status.success? end |