In My lib folder, I have a file image_helper_exception.rb. The path is lib/dibs_exception/image_exception/image_helper_exception.rb
In this file I have all my Image Exceptions defined
module DibsException
module ImageException
class ImageHelperException < Exception; end
class InvalidEntityException < Exception; end
class InvalidImageTypeException < Exception; end
class InvalidImageVersionException < Exception; end
class InvalidImageUrlException < Exception; end
class ImageNotFoundException < Exception; end
end
end
I raise applications elsewhere in my application when certain things are missing. The path to the file image_resize.rb where it is being used is helpers/image_resize.rb
The image_resize.rb looks something like this.
module Helpers
class ImageResize
require 'RMagick'
require 'aws/s3'
require 'rvg/rvg'
require 'mechanize'
include Magick
def initialize(abc)
if abc
raise DibsException::ImageException::InvalidEntityException.new("Entity is invalid.")
#The above line raises a error
#NameError: uninitialized constant DibsException::ImageException::InvalidEntityException
else
raise DibsException::ImageException::ImageHelperException.new("ImageHelperException.")
#The above line does not raise a error
end
end
end
I would like to add lib gets loaded in application.rb.
I am not able to understand why(Helpers::ImageResize.new(true)
) is raising this error : NameError: uninitialized constant DibsException::ImageException::InvalidEntityException
But this works fine as expected : Helpers::ImageResize.new(false)
Why is only the first class loaded. Can some one help ? require does not work.