I'm working on an open source Rails 4 project that uses PDF Tool Kit ('pdf-forms' gem) to auto-fill PDF forms based on info stored in the app's database. PDFtk requires binaries to be installed, and the instantiated PDFtk model requires a path to the binaries. The path needs to be dynamic so it will work on Heroku, Mac OS X, and Windows, so I figured I'd use the 'which' command and grab the echoed path. But, Windows doesn't use 'which', it uses 'where'.
My best attempt is to detect platform with RbConfig (see below). However, I'm not familiar with the native and portable platforms for Windows, as I'm a Mac user. Is there a way to instead detect if the platform responds to a command, and if so, then execute command?
def pdftk
# Use path stored in Heroku env vars or else get path to local binaries
@pdftk ||= PdfForms.new(ENV['PDFTK_PATH'] || local_path)
end
def local_path
os = RbConfig::CONFIG['arch']
if /mswin/ =~ os
`where pdftk` # Get pdftk filepath, Windows equiv of *nix 'which' command
else
`which pdftk` # Get pdftk filepath on POSIX systems
end
end
