Module: Hocho::Utils::Finder

Defined in:
lib/hocho/utils/finder.rb

Defined Under Namespace

Classes: NotFound

Class Method Summary collapse

Class Method Details

.find(const, prefix, name) ⇒ Object



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

def self.find(const, prefix, name)
  retried = false
  constant_name = name.to_s.gsub(/\A.|_./) { |s| s[-1].upcase }

  begin
    const.const_get constant_name, false
  rescue NameError
    unless retried
      begin
        require "#{prefix}/#{name}"
      rescue LoadError
      end

      retried = true
      retry
    end
    raise NotFound, "Couldn't find #{prefix}/#{name}"
  end
end