Class: Nanoc2::Extra::FileProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/nanoc2/extra/file_proxy.rb

Overview

A FileProxy is a proxy for a File object. It is used to prevent a File object from being created until it is actually necessary.

For example, a site with a few thousand pages would fail to compile because the massive amount of file descriptors necessary, but the file proxy will make sure the File object is not created until it is used.

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileProxy

Creates a new file proxy for the given path. This is similar to creating a File object with the same path, except that the File object will not be created until it is accessed.



16
17
18
# File 'lib/nanoc2/extra/file_proxy.rb', line 16

def initialize(path)
  @path = path
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

Makes sure all method calls are relayed to a File object, which will be created right before the method call takes place and destroyed right after.



23
24
25
# File 'lib/nanoc2/extra/file_proxy.rb', line 23

def method_missing(sym, *args, &block)
  File.new(@path).__send__(sym, *args, &block)
end