Module: StoryTeller::Library::Loader
- Defined in:
- lib/story_teller/library/loader.rb
Overview
The Library::Loader module provides methods for loading Library files.
Class Method Summary collapse
- .augment_inform_library! ⇒ Object
-
.load_grammar(module_name) ⇒ Object
rubocop: enable Metrics/AbcSize rubocop: enable Metrics/MethodLength.
- .load_grammar_by_path(module_path) ⇒ Object
- .load_library ⇒ Object
-
.require_first_existing(guesses) ⇒ Object
rubocop: disable Metrics/AbcSize rubocop: disable Metrics/MethodLength.
- .unload_grammars! ⇒ Object
Class Method Details
.augment_inform_library! ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/story_teller/library/loader.rb', line 35 def augment_inform_library! InformLibrary.extend(StoryTeller::Engine::Library) InformLibrary.class_eval do include Inform::Context unless include?(Inform::Context) include Inform::StdLib unless include?(Inform::StdLib) include Inform::Rules unless include?(Inform::Rules) include Inform::History unless include?(Inform::History) end InformLibrary.prepend(StoryTeller::Library::Location) end |
.load_grammar(module_name) ⇒ Object
rubocop: enable Metrics/AbcSize rubocop: enable Metrics/MethodLength
74 75 76 |
# File 'lib/story_teller/library/loader.rb', line 74 def load_grammar(module_name) Inform::Grammar.load_by_name(module_name) end |
.load_grammar_by_path(module_path) ⇒ Object
78 79 80 |
# File 'lib/story_teller/library/loader.rb', line 78 def load_grammar_by_path(module_path) Inform::Grammar.load_by_path(module_path) end |
.load_library ⇒ Object
46 47 48 |
# File 'lib/story_teller/library/loader.rb', line 46 def load_library augment_inform_library! end |
.require_first_existing(guesses) ⇒ Object
rubocop: disable Metrics/AbcSize rubocop: disable Metrics/MethodLength
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/story_teller/library/loader.rb', line 52 def require_first_existing(guesses) guessed_file_path = File.join(StoryTeller::Engine.inform_code_prefix, guesses.shift) guessed_local_file_path = File.(guessed_file_path) if File.exist?(guessed_local_file_path) log.debug "Loading local library file: #{guessed_local_file_path}" require_relative guessed_local_file_path else log.debug "Loading library: #{guessed_file_path}" require guessed_file_path end rescue StandardError => e log.error e. e.backtrace.each { |t| log.warn t } raise e rescue LoadError => e log.warn e. e.backtrace.each { |t| log.warn t } retry unless guesses.empty? end |