Module: VimMate::Requirer
- Defined in:
- lib/vim_mate/requirer.rb
Overview
This module contains methods to help when requiring files that could not be installed on the user computer.
Class Method Summary collapse
-
.raise_load_error_if ⇒ Object
Raise a LoadError if the provided block returns true.
-
.require_exit(file) ⇒ Object
Exit the program with a nice message if the specified file cannot be required.
-
.require_if(file, to_return_on_error = false) ⇒ Object
Runs the provided block if the file can be required.
-
.require_not_if(file, to_return_on_success = false) ⇒ Object
Runs the provided block if the file cannot be required.
Class Method Details
.raise_load_error_if ⇒ Object
Raise a LoadError if the provided block returns true
64 65 66 |
# File 'lib/vim_mate/requirer.rb', line 64 def self.raise_load_error_if raise LoadError, "Requirer cannot continue" if yield end |
.require_exit(file) ⇒ Object
Exit the program with a nice message if the specified file cannot be required
56 57 58 59 60 61 |
# File 'lib/vim_mate/requirer.rb', line 56 def self.require_exit(file) require file rescue LoadError puts "Module #{file} is required to run this program" exit end |
.require_if(file, to_return_on_error = false) ⇒ Object
Runs the provided block if the file can be required. If it can’t, return the value of to_return_on_error
32 33 34 35 36 37 38 39 40 |
# File 'lib/vim_mate/requirer.rb', line 32 def self.require_if(file, to_return_on_error = false) begin require file rescue LoadError to_return_on_error else yield end end |
.require_not_if(file, to_return_on_success = false) ⇒ Object
Runs the provided block if the file cannot be required. If it can, return the value of to_return_on_success
44 45 46 47 48 49 50 51 52 |
# File 'lib/vim_mate/requirer.rb', line 44 def self.require_not_if(file, to_return_on_success = false) begin require file rescue LoadError yield else to_return_on_success end end |