Module: Inform::RuntimeClassMethods

Included in:
Runtime
Defined in:
lib/runtime/runtime.rb

Overview

The RuntimeClassMethods module

Instance Method Summary collapse

Instance Method Details

#database_saves_dir_pathObject



79
80
81
# File 'lib/runtime/runtime.rb', line 79

def database_saves_dir_path
  File.join(Inform::Runtime.project_dir_path, '.' + Inform::Game.config[:database_name] + '_saves')
end

#default_configObject



55
56
57
# File 'lib/runtime/runtime.rb', line 55

def default_config
  @default_config ||= Inform::Config::DEFAULTS
end

#default_environmentObject



83
84
85
# File 'lib/runtime/runtime.rb', line 83

def default_environment
  Inform::Runtime.default_config[:environment]
end

#default_game_dir_pathObject



59
60
61
# File 'lib/runtime/runtime.rb', line 59

def default_game_dir_path
  File.join(project_dir_path, Inform::Runtime.default_config[:game_dir_name])
end

#inform_dir_pathObject



67
68
69
# File 'lib/runtime/runtime.rb', line 67

def inform_dir_path
  Inform::INFORM_DIR_PATH
end

#init(options = Inform::Runtime.default_config) ⇒ Object



115
116
117
# File 'lib/runtime/runtime.rb', line 115

def init(options = Inform::Runtime.default_config)
  Inform::Runtime.instance(options)
end

#instance(options = Inform::Runtime.default_config) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/runtime/runtime.rb', line 119

def instance(options = Inform::Runtime.default_config)
  return @instance unless @instance.nil?
  @instance_mutex.synchronize do
    @instance ||= new(options)
  end
  @instance
end

#invocation_contextObject



92
93
94
95
# File 'lib/runtime/runtime.rb', line 92

def invocation_context
  return Inform::Runtime.instance.invocation_context unless Inform::Runtime.instance.nil?
  Struct.new(*Inform::Runtime.invocation_properties)
end

#invocation_propertiesObject



87
88
89
90
# File 'lib/runtime/runtime.rb', line 87

def invocation_properties
  return Inform::Runtime.instance.invocation_properties unless Inform::Runtime.instance.nil?
  Inform::Runtime.default_config.fetch(:properties, '').split.map(&:to_sym)
end

#language_nameObject



97
98
99
# File 'lib/runtime/runtime.rb', line 97

def language_name
  Inform::Runtime.default_config[:language]
end

#lib_dir_pathObject



71
72
73
# File 'lib/runtime/runtime.rb', line 71

def lib_dir_path
  Inform::LIB_DIR_PATH
end

#librariesObject



51
52
53
# File 'lib/runtime/runtime.rb', line 51

def libraries
  Inform::Runtime::LibraryRegistry
end

#main_gem_spec_executableObject



101
102
103
104
105
106
107
108
# File 'lib/runtime/runtime.rb', line 101

def main_gem_spec_executable
  require 'rubygems'
  current_working_dir = File.expand_path(__dir__)
  gem_spec = Gem.loaded_specs.values.find do |s|
    current_working_dir.start_with?(s.full_gem_path)
  end
  (gem_spec&.executables || []).first
end

#player?(obj) ⇒ Boolean

Returns:

  • (Boolean)


110
111
112
113
# File 'lib/runtime/runtime.rb', line 110

def player?(obj)
  return false unless defined?(Inform::IO::Session) && Inform::IO::Session.respond_to?(:players)
  Inform::IO::Session.players.include?(obj)
end

#project_dir_pathObject



75
76
77
# File 'lib/runtime/runtime.rb', line 75

def project_dir_path
  Inform::PROJECT_DIR_PATH
end

#support_dir_pathObject



63
64
65
# File 'lib/runtime/runtime.rb', line 63

def support_dir_path
  Inform::SUPPORT_DIR_PATH
end