Module: FeduxOrgStdlib::RequireFiles

Defined in:
lib/fedux_org_stdlib/require_files.rb

Instance Method Summary collapse

Instance Method Details

#require_installed_gem(gems, message_template = 'You need to install %s to make "%s" work.') ⇒ Object

Raises:

  • (LoadError)


19
20
21
22
23
# File 'lib/fedux_org_stdlib/require_files.rb', line 19

def require_installed_gem(gems, message_template = 'You need to install %s to make "%s" work.')
  gems = Array(gems)

  raise LoadError, JSON.dump(gems: gems) if gems.any? { |name| Gem::Specification.find_all_by_name(name).blank? }
end

#require_library(libraries, message_template = 'You need to install %s to make "%s" work.') ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fedux_org_stdlib/require_files.rb', line 6

def require_library(libraries, message_template = 'You need to install %s to make "%s" work.')
  libraries = Array(libraries)

  begin
    libraries.each { |l| require l }
  rescue LoadError => e
    $stderr.puts format(message_template, libraries.map { |l| l.split(%r{/}).first }.uniq.to_list, caller[1].split(/:/)[0,2].join(':'))
    $stderr.puts
    $stderr.puts e.message
    exit 1 
  end
end