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

Class Method Details

.augment_inform_library!Object



35
36
37
38
39
40
41
42
43
# File 'lib/story_teller/library/loader.rb', line 35

def augment_inform_library!
  ensure_inform_object_model!
  InformLibrary.extend(StoryTeller::Engine::Library)
  InformLibrary.class_eval do
    include Inform::Context unless include?(Inform::Context)
    include Inform::StdLib unless include?(Inform::StdLib)
  end
  InformLibrary.prepend(StoryTeller::Library::Location)
end

.ensure_inform_object_model!Object



58
59
60
61
62
# File 'lib/story_teller/library/loader.rb', line 58

def ensure_inform_object_model!
  return if inform_object_model?

  StoryTeller::EphemeralAdapter.register!
end

.inform_object_model?Boolean

Returns:

  • (Boolean)


50
51
52
53
54
55
56
# File 'lib/story_teller/library/loader.rb', line 50

def inform_object_model?
  object_class = StoryTeller::ModelAdapter.object_class
  return false if object_class.nil?

  object_class.method_defined?(:<<) &&
    object_class.method_defined?(:with)
end

.load_grammar(module_name) ⇒ Object

rubocop: enable Metrics/AbcSize rubocop: enable Metrics/MethodLength



87
88
89
# File 'lib/story_teller/library/loader.rb', line 87

def load_grammar(module_name)
  Inform::Grammar.load_by_name(module_name)
end

.load_grammar_by_path(module_path) ⇒ Object



91
92
93
# File 'lib/story_teller/library/loader.rb', line 91

def load_grammar_by_path(module_path)
  Inform::Grammar.load_by_path(module_path)
end

.load_libraryObject



45
46
47
48
# File 'lib/story_teller/library/loader.rb', line 45

def load_library
  augment_inform_library!
  StoryTeller::Library::Bootstrap.manage_inform_library
end

.require_first_existing(guesses) ⇒ Object

rubocop: disable Metrics/AbcSize rubocop: disable Metrics/MethodLength



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/story_teller/library/loader.rb', line 66

def require_first_existing(guesses)
  guessed_file_path = File.join(StoryTeller::Engine.inform_code_prefix, guesses.shift)
  guessed_local_file_path = File.expand_path(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.message
  e.backtrace.each { |t| log.warn t }
  raise e
rescue LoadError => e
  log.warn e.message
  e.backtrace.each { |t| log.warn t }
  retry unless guesses.empty?
end

.unload_grammars!Object



95
96
97
98
# File 'lib/story_teller/library/loader.rb', line 95

def unload_grammars!
  log.debug "Unloading all grammars"
  Inform::Grammar::Verbs.clear
end