figaro icon indicating copy to clipboard operation
figaro copied to clipboard

Figaro is loading Rails when it is not needed

Open l8nite opened this issue 10 years ago • 0 comments

We have a hybrid rails application + console application project that shares a common repository.

The gems for the console application are segregated via Bundler group, and it is the console application we're interested in using Figaro with, i.e.:

source 'https://rubygems.org'

gem 'rails'

group :console do
  gem 'figaro'
end

When our console application starts, it uses Bundler.require(:console) to bring in figaro (along with its other gems), and that ends up doing a require 'rails' from lib/figaro/rails.rb. Under normal circumstances this would probably be ok (the require would just fail), but since we have rails in our Gemfile, the require succeeds and rails is inadvertently loaded.

This unfortunately breaks some other gems our console application is relying on which guard against Rails-specific behavior by explicitly checking whether or not the Rails constant is defined.

I believe the fix for this is straight-forward, instead of explicitly requiring rails, we can check whether or not Rails is defined in lib/figaro/rails.rb and initialize the railtie and set the default adapter appropriately.

I'll submit a PR to address this shortly.

l8nite avatar Jun 28 '15 03:06 l8nite