Class: WickedPdf::Binary
- Inherits:
-
Object
- Object
- WickedPdf::Binary
- Defined in:
- lib/wicked_pdf/binary.rb
Constant Summary collapse
- EXE_NAME =
'wkhtmltopdf'.freeze
- MINIMUM_BINARY_VERSION =
Gem::Version.new('0.12.0')
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.default ⇒ Object
Shared instance, so the version check (
wkhtmltopdf -Vsubprocess) runs once instead of once per render. - .reset_default! ⇒ Object
Instance Method Summary collapse
-
#initialize(binary_path = nil) ⇒ Binary
constructor
A new instance of Binary.
- #parse_version_string(version_info) ⇒ Object
Constructor Details
#initialize(binary_path = nil) ⇒ Binary
Returns a new instance of Binary.
23 24 25 26 27 28 29 30 31 |
# File 'lib/wicked_pdf/binary.rb', line 23 def initialize(binary_path = nil) @path = binary_path || find_binary_path @version = retrieve_binary_version raise "Minimum version of wkhtmltopdf is #{MINIMUM_BINARY_VERSION}. Version found was #{@version}." if @version < MINIMUM_BINARY_VERSION raise "Location of #{EXE_NAME} unknown" if @path.empty? raise "Bad #{EXE_NAME}'s path: #{@path}" unless File.exist?(@path) raise "#{EXE_NAME} is not executable" unless File.executable?(@path) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/wicked_pdf/binary.rb', line 6 def path @path end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
6 7 8 |
# File 'lib/wicked_pdf/binary.rb', line 6 def version @version end |
Class Method Details
.default ⇒ Object
Shared instance, so the version check (wkhtmltopdf -V subprocess) runs
once instead of once per render. Re-resolved whenever config.exe_path
changes — including back to nil (automatic path detection).
11 12 13 14 15 16 |
# File 'lib/wicked_pdf/binary.rb', line 11 def self.default configured_path = WickedPdf.config.exe_path @default = nil if @default && @default_configured_path != configured_path @default_configured_path = configured_path @default ||= new end |
.reset_default! ⇒ Object
18 19 20 21 |
# File 'lib/wicked_pdf/binary.rb', line 18 def self.reset_default! @default = nil @default_configured_path = nil end |
Instance Method Details
#parse_version_string(version_info) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/wicked_pdf/binary.rb', line 33 def parse_version_string(version_info) match_data = /wkhtmltopdf\s*(\d*\.\d*\.\d*\w*)/.match(version_info) if match_data && (match_data.length == 2) Gem::Version.new(match_data[1]) else MINIMUM_BINARY_VERSION end end |