Max Williams said:
Eg when i do a require, raise a warning if the gem wasn't loaded. Then,
when i restart the app, i see the warnings and can install the gems.
Right, this is why RubyFrontier uses "myrequire" instead of "require":
def myrequire(*what)
# (1) no penalty for failure; we catch the LoadError and we don't
re-raise
# (2) arg can be an array, so multiple requires can be combined in one
line
# (3) array element itself can be a pair, in which case second must be
array of desired includes as symbols
# that way, we don't try to perform the includes unless the require
succeeded
# and we never *say* the include as a module, so it can't fail at
compile time
# and if an include fails, that does raise all the way since we don't
catch NameError
what.each do |thing|
begin
require((t = Array(thing))[0])
Array(t[1]).each {|inc| include self.class.const_get(inc) rescue
puts "Warning: failed to include #{inc.to_s}"}
rescue LoadError
puts "Warning: Require failed", "This could cause trouble later...
or not. Here's the error message we got:"
puts $!
end
end
end
The idea here is that by using "myrequire" everywhere, I *notify* the
user that a require failed, without actually encountering a fatal error.
The fatal error would be encountered only the user tried to *use* some
code that actually *calls* something inside one of the required files -
and that might never happen. But at least this way the user gets a list,
up front, of gems that need installing sooner or later.
So I'm thinking you could use this, or something like it... m.