Class: Wolverine::PathComponent

Inherits:
Object
  • Object
show all
Defined in:
lib/wolverine/path_component.rb

Overview

A PathComponent represents either the Wolverine.config.script_path directory, or a subdirectory of it. Calling (nearly) any method on it will cause it to look in the filesystem at the location it refers to for a file or directory matching the method name. These results are cached.

Calling a method that maps to a directory will return a new PathComponent with a path referring to that directory.

Calling a method that maps to a file (with ‘.lua’ automatically appended to the name) will load the file via Script and call it with the arugments passed, returning the result (#method_missing).

Defined Under Namespace

Classes: MissingTemplate

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ PathComponent

Returns a new instance of PathComponent.

Parameters:

  • path (Pathname)

    full path to the current file or directory

  • redis (Redis)


18
19
20
21
22
23
24
# File 'lib/wolverine/path_component.rb', line 18

def initialize path, options = {}
  @path = path
  @options = options
  @cache_to = options[:cache_to]
  @redis = options[:redis] || Wolverine.redis
  @config = options[:config] || Wolverine.config
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ PathComponent, Object

Returns A new, nested Wolverine::PathComponent if sym resolves to a directory, or an execution result if it resolves to a file.

Parameters:

  • sym (Symbol)

    the file or directory to look up and execute

  • args (*Objects)

    arguments to pass to the Script, if sym resolves to a lua file

Returns:

Raises:



31
32
33
34
# File 'lib/wolverine/path_component.rb', line 31

def method_missing sym, *args
  create_method sym, *args
  send sym, *args
end