Class: Ppr::Require

Inherits:
LoadRequire show all
Defined in:
lib/ppr/ppr_core.rb

Overview

Describes a macro loading and pasting a file into the current one only if it has not already been loaded before.

Constant Summary collapse

@@required =

The already required files.

[]

Constants inherited from Macro

Macro::E_NUMBER, Macro::E_TYPE

Instance Attribute Summary

Attributes inherited from Macro

#name

Instance Method Summary collapse

Methods inherited from LoadRequire

#find_file, #initialize, #loadm, #set_locations

Methods inherited from Macro

#add, #e_message, e_message, #e_number, #e_shift_number, #e_type?, #empty?, #final?, #generate, #initialize, #to_quoted

Constructor Details

This class inherits a constructor from Ppr::LoadRequire

Instance Method Details

#apply(i_number) ⇒ Object

Applies the macro invoked at line number i_number, its result is the name of the file to be loaded if not already loaded.



354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/ppr/ppr_core.rb', line 354

def apply(i_number)
    # Expand the macro, its result is the name of the file to load.
    name = super(i_number)
    # Has it already been required?
    unless @@required.include?(name) then
        # No, mark it as required and load and preprocess the file.
        @@required << name
        # return File.read(name)
        return loadm(name)
    else
        # Yes, nothing to do.
        return ""
    end
end