Module: Checkup::ErrorsHelper

Included in:
Errors
Defined in:
lib/checkup/errors.rb

Overview

when included, automatically creates new Exceptions depending on the Const passed in

Instance Method Summary collapse

Instance Method Details

#const_missing(const) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/checkup/errors.rb', line 4

def const_missing(const)
  if const.to_s.end_with?('Error')
    # create new exception class
    module_eval do
      new_class = Class.new Checkup::Errors::Error
      const_set const, new_class
    end
    
  else
    
    # dealing with a module here, create it
    module_eval do
      new_module = Module.new do
        extend Checkup::ErrorsHelper
      end
      
      const_set const, new_module
    end
  end
  const_get const
end