Module: Kernel

Defined in:
lib/bunto/assets/patches/kernel.rb

Overview


Frozen-string-literal: true Copyright: 2016-present - MIT License Encoding: utf-8


Instance Method Summary collapse

Instance Method Details

#try_require(file) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/bunto/assets/patches/kernel.rb', line 8

def try_require(file)
  require file
  if block_given?
    yield
  end
rescue LoadError
  return nil
end

#try_require_if_javascript(file) ⇒ Object




19
20
21
22
23
24
25
26
27
28
# File 'lib/bunto/assets/patches/kernel.rb', line 19

def try_require_if_javascript(file)
  ["execjs", file].map(&method(:require))
  if block_given?
    yield
  end
rescue LoadError, ExecJS::RuntimeUnavailable
  Bunto.logger.debug("ExecJS, JS Runtime or `#{file}' not available." \
    " Skipping the loading of libraries.")
  return
end