I agree. If a dependency is not met, exit immediately with an error.
If the missing dependency isn't REALLY a problem in some situations,
then encode that conditionality using ruby - check the platform,
environment, shell out to run a command, whatever you need. Isn't why
we are configuring the gems in ruby, to have that flexibility and
control?
-- Chad
At least that was the reason for dumping my original config/gems.yml approach :)
Yes, but you get the best of both worlds (dynamic control and
decoupling dependencies from app) if you run your YAML through ERB :)
Agreed. It always seemed strange to me that you can load your app
even if you are missing gems.
Maybe there should be a way to specify optional dependencies, but the
default should be to fail fast if a gem is missing.
- Rob
-1 on this. This should be thought through more.
First, there is now the standard "development" gem property which is
now in RubyGems 1.2.0 (see gem install --help). This is already a way
of specifying gems which are only required in development, but not to
run the app in production/runtime. How would an "optional" flag
relate to this?
Also, what does it mean for a dependency to be "optional"? If it
isn't required sometime, somewhere, for something, it should not be a
dependency. The when, where, and why is completely dependent on the
situation. That's why this should be handled with custom ruby
conditional code - based on platform, RAILS_ENV, hostname, whatever.
In other words, no dependency is ever "optional" - someone must need
it, otherwise it would not be a dependency.
So, I think that this should be handled by leveraging the standard
support which is already in Rubygems, and allow the config.gems to
pass through the --development option to the underlying gem install
command. Anything else that doesn't fall into the current standard
development/runtime category should be handled with custom
conditionals on a per-app basis.
-- Chad
In my case the difference between production and development is that
development also uses gems like rspec, faker, annotate-models. These
are not necessary for running in production. Those are specified
separately in config/environments/development.rb. That, however, has
nothing to do with gem development dependencies. These dependencies
do not interest the app under any condition, it only needs these gems
and their runtime dependencies.
>
> Also, what does it mean for a dependency to be "optional"? If it
> isn't required sometime, somewhere, for something, it should not be a
> dependency. The when, where, and why is completely dependent on the
> situation. That's why this should be handled with custom ruby
> conditional code - based on platform, RAILS_ENV, hostname, whatever.
> In other words, no dependency is ever "optional" - someone must need
> it, otherwise it would not be a dependency.
A lot of times optional means "use it if it's there, don't bother me
if it's not", which is different from only using a gem in a particular
setup. Uv is a good example, it's painful to install and not
supported on JRuby, so you would want to disable this dependency when
running on JRuby, but also make it optional in other conditions.
Assaf
You *should* be able to achieve this by using config.gem in
development.rb. If this doesn't work it's a bug and we should fix it.
> However, that's not the same thing as optional gems. Here's a concrete
> example of an optional gem:
We have cases of this in the rails codebase, but typically they rescue
LoadError and set up some stub versions of the relevant libraries.
i.e. it's not enough to just rescue the failed load, some values have
to be set up so the application knows what to do. Perhaps you require
an alternative gem, or you just stub out a few constants and methods
or set a global variable like $uv_installed = false.
I'm really not sold on doing this through config.gem as there's just
no simple 'else' case here.
--
Cheers
Koz
I still think this would be better handled via custom application
code. For example, never do it if platform is Jruby, or if some other
app-specific flag is set.
The app-specific flag could be a constant or environment variable
which says to either use or not use the dependency (depending on which
is the most common case). If you don't like environment variables,
put it as a constant in a file that is attempted to be loaded, but
ignored and never checked into source control. A developer-specific
config file, sort of like database.yml if you don't check it in.
Cool. Good to know. I never actually use config.gems myself, since
there are (cough cough geminstaller) more fully-featured alternatives.
Just Kidding :)
-- Chad