Class: Ppr::LoadRequire

Inherits:
Macro
  • Object
show all
Defined in:
lib/ppr/ppr_core.rb

Overview

Descibes an abstract class for loading or requiring files.

Direct Known Subclasses

Load, Require

Constant Summary

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 Macro

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

Constructor Details

#initialize(num, ppr, expand: ":<") ⇒ LoadRequire

Creates a new load or require macro starting at line number num generated from preprocessor ppr.

The expand strings be redefined through keyword arguments.



302
303
304
# File 'lib/ppr/ppr_core.rb', line 302

def initialize(num, ppr, expand: ":<")
    super("",num,ppr,expand: expand)
end

Instance Method Details

#find_file(name) ⇒ Object



310
311
312
313
314
315
316
317
318
319
# File 'lib/ppr/ppr_core.rb', line 310

def find_file(name)
    @locations.each do |i|
      filepath =  i + "/" + name
      if File.exist?(filepath)
        return filepath
      end
    end

    raise "File #{name} was not found in includes."
end

#loadm(name) ⇒ Object

Loads and preprocess file name.



322
323
324
325
326
327
328
329
# File 'lib/ppr/ppr_core.rb', line 322

def loadm(name)
    output = StringIO.new("")
    # print "name=#{name}\n"
    File.open(find_file(name),"r") do |input|
        @ppr.preprocess(input,output)
    end
    return output.string
end

#set_locations(locations) ⇒ Object



306
307
308
# File 'lib/ppr/ppr_core.rb', line 306

def set_locations(locations)
    @locations = locations
end