Class: MilkTea::PreludeInstaller
- Inherits:
-
Object
- Object
- MilkTea::PreludeInstaller
- Defined in:
- lib/milk_tea/core/prelude_installer.rb
Constant Summary collapse
- PRELUDE_MODULE_PATHS =
%w[std.option std.result].freeze
Instance Method Summary collapse
-
#initialize(resolve_module_path:, check_block:, bind_block:) ⇒ PreludeInstaller
constructor
A new instance of PreludeInstaller.
- #install_prelude_modules!(ast, modules, importer_path: nil, collecting_errors: false) ⇒ Object
Constructor Details
#initialize(resolve_module_path:, check_block:, bind_block:) ⇒ PreludeInstaller
Returns a new instance of PreludeInstaller.
7 8 9 10 11 |
# File 'lib/milk_tea/core/prelude_installer.rb', line 7 def initialize(resolve_module_path:, check_block:, bind_block:) @resolve_module_path = resolve_module_path @check_block = check_block @bind_block = bind_block end |
Instance Method Details
#install_prelude_modules!(ast, modules, importer_path: nil, collecting_errors: false) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/milk_tea/core/prelude_installer.rb', line 13 def install_prelude_modules!(ast, modules, importer_path: nil, collecting_errors: false) current_module_name = ast.module_name&.to_s return if PRELUDE_MODULE_PATHS.include?(current_module_name) PRELUDE_MODULE_PATHS.each do |module_path| next if modules.key?(module_path) begin import_path = @resolve_module_path.call(module_path, importer_path:) import_analysis = @check_block.call(import_path, collecting_errors) modules[module_path] = @bind_block.call(import_analysis) rescue ModuleLoadError end end end |