Hi Neil,

Have never used Wicked before, but when using image magick I had some similar 
code.

I ended up moving it into its own module. From there, any common usage patterns 
ended up moving there as well. It provided a nice insulation layer and cleaned 
up my logic elsewhere that was not application specific.

YYMV,
Keenan

initializer:

Wicked.mode = (Rails.env.test?||Rails.env.development?) ? 'amd' : 'intel'


class Wicked
  def self.mode=(_mode)
    @mode=_mode
  end

  def self.amd?
    @mode == 'amd'
  end

  def self.path
    @path ||= amd? ? '/usr/local/bin/wkhtmltopdf' : Rails.root.join('bin')
  end

  def self.suffix
    amd? ? '-amd64' : ''
  end

  def self.exe
    @exe ||= path + "wkhtmltopdf#{suffix}"
  end

  def self.make_pdf(filename, …)
    #...
  end
end


(maybe cattr would work better than the variables I used there.


On Friday, March 2, 2012 at 4:29 AM, Neil Middleton wrote:

> On Tuesday, 28 February 2012 at 20:21, Patrick Stinson wrote:
> > I'm no gem expert, but I have two little problems with managing different 
> > sets of gems.
> >  
> > First, I want to use pdfkit in my rails project which requires wkhtmltopdf. 
> > wkhtmltopdf comes in two binary versions, one for my mac 
> > (wkhtmltopdf-binary) and one for amd64 (wkhtmltopdf-heroku) that works on 
> > heroku. How do I use one on my local system and the other on heroku? The 
> > pdfkit gem will use whichever one I have told bundler to install (I think), 
> > so when I try to trick it by installing the wkhtmltopdf-heroku gem and 
> > wkhtmltopdf binary locally it looks for the amd64 version instead of the 
> > local version, which obviously doesn't work on my mac I use for development.
> I've done this recently and used the following approach:
>  
> In my Gemfile I had (as a global gem):
>  
> gem 'wicked_pdf'
>  
> then in an initializer I have:
> WICKED_PDF = { :wkhtmltopdf => (Rails.env.test? || Rails.env.development? ? 
> '/usr/local/bin/wkhtmltopdf' : Rails.root.join('bin', 
> 'wkhtmltopdf-amd64').to_s), :exe_path => (Rails.env.test? || 
> Rails.env.development? ? '/usr/local/bin/ ' : Rails.root.join('bin', 
> 'wkhtmltopdf-amd64').to_s) }
> So, wkhtmltopdf-amd64' is committed into a local bin folder and used by 
> wicked_pdf as the binary in anything other than development, where it uses 
> the local path of the installed binary.
> Hopefully this makes sense.
>  
> -Neil
>  
>  
> >  
> > Second, I fixed a bug in the pdfkit gem. How, then, do I use my patched 
> > version instead of having heroku automatically install the current version 
> > from the gem's original vendor?
> >  
> > Thanks!  
> >  
> > --  
> > You received this message because you are subscribed to the Google Groups 
> > "Heroku" group.
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msg/heroku/-/mRxTkY2NHH8J.
> > To post to this group, send email to [email protected] 
> > (mailto:[email protected]).
> > To unsubscribe from this group, send email to 
> > [email protected] 
> > (mailto:[email protected]).
> > For more options, visit this group at 
> > http://groups.google.com/group/heroku?hl=en.
>  
> --  
> You received this message because you are subscribed to the Google Groups 
> "Heroku" group.
> To post to this group, send email to [email protected] 
> (mailto:[email protected]).
> To unsubscribe from this group, send email to 
> [email protected] 
> (mailto:[email protected]).
> For more options, visit this group at 
> http://groups.google.com/group/heroku?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Heroku" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/heroku?hl=en.

Reply via email to