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)


321
322
323
324
325
326
# File 'lib/nwn/twoda.rb', line 321

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 pathes, just like $PATH.



314
315
316
# File 'lib/nwn/twoda.rb', line 314

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