Module: Bees

Defined in:
lib/hive.rb

Defined Under Namespace

Classes: HandlerLoadError

Constant Summary collapse

STATUS_MESSAGE =
"The Bees They're In My Eyes"

Class Method Summary collapse

Class Method Details

.attempt_load(gem_name) ⇒ Object

Attempt to run the HTTP status code override in the given block. If the first try fails, require gem_name (might not actually be a gem), and try yielding again.

This allows us to do, e.g.,

require "rack/bees"

as equivalent to

require "rack"
require "rack/bees"

If gem_name can’t be require()d, a LoadError will be raised as usual.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/hive.rb', line 23

def self.attempt_load(gem_name)
  begin
    skip_retry = false
    begin
      yield
    rescue NameError
      return if skip_retry
      require gem_name
      skip_retry = true
      retry
    end
  rescue LoadError
    raise HandlerLoadError.new("Failed to load handler")
  end
end