Module: NWN::TwoDA::Cache

Defined in:
lib/nwn/twoda.rb

Overview

This is a simple 2da cache.

Class Method Summary collapse

Class Method Details

.get(name) ⇒ Object

Get the 2da file with the given name. name is without extension. This being a cache, modifications to the returned Table will be reflected in further calls to Cache.get.

Raises:

  • (Exception)


365
366
367
368
369
370
# File 'lib/nwn/twoda.rb', line 365

def self.get(name)
  raise Exception,
    "You need to set up the cache first through the environment variable NWN_LIB_2DA_LOCATION." unless
      @_roots.size > 0
  @_cache[name.downcase] ||= read_2da(name.downcase)
end

.setup(root_directories) ⇒ Object

Set the file system path spec where all 2da files reside. Call this on application startup. path spec is a colon-separated list of paths, just like $PATH.



357
358
359
360
# File 'lib/nwn/twoda.rb', line 357

def self.setup root_directories
  @_roots = root_directories.split(File::PATH_SEPARATOR).
    compact.reject {|x| "" == x.strip }
end