Module: Kernel
- Defined in:
- lib/ruar/core_ext/kernel_require.rb
Class Method Summary collapse
- .load(path, from: :both) ⇒ Object
- .load_with_ruar(path, eval_bind = TOPLEVEL_BINDING) ⇒ Object
- .load_without_ruar ⇒ Object
- .require(path, from: :both) ⇒ Object
-
.require_relative(path, from: :both) ⇒ Object
TODO: need to test.
- .require_relative_without_ruar ⇒ Object
- .require_with_ruar(path, eval_bind = TOPLEVEL_BINDING) ⇒ Object
- .require_without_ruar ⇒ Object
- .ruar_eval_wrap(path, eval_bind = TOPLEVEL_BINDING) ⇒ Object
Class Method Details
.load(path, from: :both) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/ruar/core_ext/kernel_require.rb', line 96 def load(path, from: :both) case from when :both begin load_with_ruar(path) rescue LoadError load_without_ruar(path) end when :ruar load_with_ruar(path) when :local load_without_ruar(path) else raise Ruar::Access::CoreExt.make_load_error(path) end end |
.load_with_ruar(path, eval_bind = TOPLEVEL_BINDING) ⇒ Object
92 93 94 |
# File 'lib/ruar/core_ext/kernel_require.rb', line 92 def load_with_ruar(path, eval_bind = TOPLEVEL_BINDING) ruar_eval_wrap(path, eval_bind) end |
.load_without_ruar ⇒ Object
90 |
# File 'lib/ruar/core_ext/kernel_require.rb', line 90 alias load_without_ruar load |
.require(path, from: :both) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ruar/core_ext/kernel_require.rb', line 58 def require(path, from: :both) case from when :both begin require_with_ruar(path) rescue LoadError require_without_ruar(path) end when :ruar require_with_ruar(path) when :local require_without_ruar(path) else raise Ruar::Access::CoreExt.make_load_error(path) end end |
.require_relative(path, from: :both) ⇒ Object
TODO: need to test
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ruar/core_ext/kernel_require.rb', line 78 def require_relative(path, from: :both) caller_path = caller_locations.first.path.to_s caller_dir = Pathname.new(caller_path).dirname.to_s prefix = Ruar.path_prefix.to_s # Ruar Internal File caller_dir = caller_dir.delete_prefix(prefix).prepend(File::SEPARATOR) if caller_dir.start_with?(prefix) resolved_path = File.(path, caller_dir) require(resolved_path, from: from) end |
.require_relative_without_ruar ⇒ Object
75 |
# File 'lib/ruar/core_ext/kernel_require.rb', line 75 alias require_relative_without_ruar require_relative |
.require_with_ruar(path, eval_bind = TOPLEVEL_BINDING) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/ruar/core_ext/kernel_require.rb', line 48 def require_with_ruar(path, eval_bind = TOPLEVEL_BINDING) # puts "path = #{path}, location = #{eval_bind.source_location}" pseudo_entry = Ruar::Access::CoreExt.pseudo_lf_entry(path) return false if $LOADED_FEATURES.include?(pseudo_entry) # Already been required ruar_eval_wrap(path, eval_bind) do $LOADED_FEATURES << pseudo_entry end end |
.require_without_ruar ⇒ Object
46 |
# File 'lib/ruar/core_ext/kernel_require.rb', line 46 alias require_without_ruar require |
.ruar_eval_wrap(path, eval_bind = TOPLEVEL_BINDING) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ruar/core_ext/kernel_require.rb', line 29 def ruar_eval_wrap(path, eval_bind = TOPLEVEL_BINDING) Ruar.eval("#{path}.rb", eval_bind) # Ruar.eval(path.rb, eval_bind) yield if block_given? true rescue Ruar::Error::FileNotFound # Try again without .rb extension begin Ruar.eval(path, eval_bind) yield if block_given? true rescue Ruar::Error::BaseError raise Ruar::Access::CoreExt.make_load_error(path) end rescue Ruar::Error::BaseError raise Ruar::Access::CoreExt.make_load_error(path) end |