Module: DragonflyMozjpeg::Utils

Defined in:
lib/dragonfly_mozjpeg/utils.rb

Constant Summary collapse

BASE_PATH =
File.expand_path(File.join(__dir__, '../../vendor/mozjpeg'))

Class Method Summary collapse

Class Method Details

.check_binary(current, file) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/dragonfly_mozjpeg/utils.rb', line 16

def check_binary(current, file)
  if current && File.exists?(current)
    current
  elsif OS.linux? && OS.bits == 64
    File.join(BASE_PATH, "linux/#{file}")
  else
    logger.warn("dragonfly_mozjpeg: missing #{file} path")
    nil
  end
end

.loggerObject



10
11
12
13
14
# File 'lib/dragonfly_mozjpeg/utils.rb', line 10

def logger
  @logger       ||= Logger.new(STDOUT)
  @logger.level ||= Logger::WARN
  @logger
end

.stringify_options(opts = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/dragonfly_mozjpeg/utils.rb', line 27

def stringify_options(opts = nil)
  return '' if opts.nil?

  if opts.is_a? String
    opts.gsub('-outfile', '')
  elsif opts.is_a? Array
    opts[-1] = opts.last.map do |k,v|
      " -#{k} #{v}" unless k.to_s == 'outfile'
    end.join[2..-1] if opts.last.is_a? Hash
    " -#{(opts - ['outfile']).join(' -')}"
  elsif opts.is_a? Hash
    opts.map do |k,v|
      " -#{k} #{v}" unless k.to_s == 'outfile'
    end.join
  else
    ''
  end
end