Module: Loader::Fetcher

Extended by:
Fetcher, Utils
Included in:
Fetcher
Defined in:
lib/loader/fetcher.rb

Instance Method Summary collapse

Methods included from Utils

pwd, require, underscore

Instance Method Details

#load(caller_class, name) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/loader/fetcher.rb', line 21

def load(caller_class, name)
  folder_path = get_folder_path(caller_class)
  file_name = Loader::Utils.underscore(name)

  Loader.project_root_folders.each do |project_root|
    Dir.glob(File.join(project_root, '**', [folder_path, "#{file_name}.{rb,ru}"].compact)).each do |ruby_file_path|
      if Loader::Utils.require(ruby_file_path)
        c = fetch_constant(caller_class, name)

        return c unless c.nil?
      end
    end
  end

  return load_gem(caller_class, name)
end

#load_gem(caller_class, constant_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/loader/fetcher.rb', line 6

def load_gem(caller_class, constant_name)
  underscore_name = Loader::Utils.underscore(constant_name)
  gem_symbolic_name = underscore_name.sub(File::Separator, '-')

  begin
    require(underscore_name)
  rescue LoadError
    require(gem_symbolic_name)
  end

  return fetch_constant(caller_class, constant_name)
rescue LoadError
  nil
end