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

- (PathComponent) initialize(path)

A new instance of PathComponent

Parameters:

  • path (Pathname)

    full path to the current file or directory



17
18
19
# File 'lib/wolverine/path_component.rb', line 17

def initialize path
  @path = path
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (PathComponent, Object) method_missing(sym, *args)

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:



26
27
28
29
# File 'lib/wolverine/path_component.rb', line 26

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