I'm writing a Rails application with functionality that interfaces with a third-party API (streamsend) via ActiveResource. I'm using shopify's fork of ActiveResource for thread-safe operation because different users of my application will have their own streamsend API client ID's and secret keys and I don't want my app to step on them when interfacing with the third-party API.
I have this in my controller associated with an around_action
filter:
private
# set StreamSend credentials in every request
def set_ss_credentials
StreamSend.site,
StreamSend.user,
StreamSend.password = current_user_credentials
yield
ensure
StreamSend.site =
StreamSend.user =
StreamSend.password = nil
end
DEFAULT_SITE, DEFAULT_USER, DEFAULT_PASSWORD = [
Rails.application.secrets.streamsend_api_endpoint, "username", "password" ]
def current_user_credentials
current_user.present? ?
[ Rails.application.secrets.streamsend_api_endpoint, current_user.ss_userid, current_user.ss_key ] :
[ DEFAULT_SITE, DEFAULT_USER, DEFAULT_PASSWORD ]
end
And in my model:
class StreamSend < ActiveResource::Base
self.format = :xml
def self.audience
@audience ||= StreamSend::Audience.find(:first)
end
end
The site and credentials are meant to be fed in via the controller action and the current user that's logged in.
This works fine when using WEBrick, but because the default setting for Rails in production mode is config.eager_load = true
, my application won't start because the actual model is lacking a site and credentials as well.
Is there a way I can tell eager_load
to ignore my ARes-dependent models but eager load all my actual database models?