Module: RubyModKit::CoreExt::Load
- Included in:
- RubyModKit
- Defined in:
- lib/ruby_mod_kit/core_ext/load.rb
Overview
the extension for load/require
Constant Summary collapse
- LOADABLE_EXTS =
: Array
%w[.rb .rbm .so .o .dll].freeze
Class Method Summary collapse
- .load(path, wrap = false) ⇒ Boolean
- .load_path ⇒ Array<String>
- .loaded_features ⇒ Array<String>
- .require(path) ⇒ Boolean
- .require_path(path, expanded: false) ⇒ String?
Class Method Details
.load(path, wrap = false) ⇒ Boolean
23 24 25 26 27 28 29 |
# File 'lib/ruby_mod_kit/core_ext/load.rb', line 23 def load(path, wrap = false) # rubocop:disable Style/OptionalBooleanParameter return super unless path.end_with?(".rbm") b = wrap ? binding : TOPLEVEL_BINDING RubyModKit::CoreExt::Eval.eval(File.read(path), b, path) true end |
.load_path ⇒ Array<String>
54 55 56 |
# File 'lib/ruby_mod_kit/core_ext/load.rb', line 54 def load_path $LOAD_PATH end |
.loaded_features ⇒ Array<String>
48 49 50 |
# File 'lib/ruby_mod_kit/core_ext/load.rb', line 48 def loaded_features $LOADED_FEATURES end |
.require(path) ⇒ Boolean
35 36 37 38 39 40 41 42 43 |
# File 'lib/ruby_mod_kit/core_ext/load.rb', line 35 def require(path) require_path = Load.require_path(path) return super unless require_path&.end_with?(".rbm") return false if Load.loaded_features.include?(require_path) Load.loaded_features << require_path load(require_path) true end |
.require_path(path, expanded: false) ⇒ String?
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ruby_mod_kit/core_ext/load.rb', line 64 def require_path(path, expanded: false) if ! && !File.absolute_path?(path) return load_path.each.lazy.map { require_path(File.join(_1, path), expanded: true) }.find(&:itself) end pathes = if path.end_with?(*LOADABLE_EXTS) [path] else LOADABLE_EXTS.map { "#{path}#{_1}" } end pathes.find { File.exist?(_1) } end |