Class: DataMetaDom::Sources
- Inherits:
-
Object
- Object
- DataMetaDom::Sources
- Defined in:
- lib/dataMetaDom/sources.rb
Overview
All sources including all includes from the master file.
For command line details either check the new method’s source or the README.rdoc file, the usage section.
Instance Attribute Summary collapse
-
#masterPath ⇒ Object
readonly
Returns the value of attribute masterPath.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Fetches the instance of SourceFile by its key.
-
#doneKeys ⇒ Object
Returns the set of the keys of the source files alredy parsed.
-
#initialize(masterFile) ⇒ Sources
constructor
Start parsing from the master file, collect all the files that are included.
-
#next ⇒ Object
Returns next source file in queue if any, returns
nil
if no more source files left to parse. -
#queue(name) ⇒ Object
Queue a source file for parsing.
Constructor Details
#initialize(masterFile) ⇒ Sources
Start parsing from the master file, collect all the files that are included.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/dataMetaDom/sources.rb', line 18 def initialize(masterFile) @masterPath = File.dirname(masterFile) @todo = {}; @done = {} libSpec = ENV[DATAMETA_LIB] @paths = libSpec ? libSpec.split(File::PATH_SEPARATOR).map { |e| uniPath(e) } : [] @paths.unshift(@masterPath).flatten! if @masterPath @paths.unshift '.' # start looking in the current directory and then in the rest of the path src = SourceFile.new(@masterPath, File.basename(masterFile)) @todo[src.key] = src end |
Instance Attribute Details
#masterPath ⇒ Object (readonly)
Returns the value of attribute masterPath.
14 15 16 |
# File 'lib/dataMetaDom/sources.rb', line 14 def masterPath @masterPath end |
Instance Method Details
#[](key) ⇒ Object
Fetches the instance of SourceFile by its key.
37 |
# File 'lib/dataMetaDom/sources.rb', line 37 def [](key); @done[key] end |
#doneKeys ⇒ Object
Returns the set of the keys of the source files alredy parsed.
32 |
# File 'lib/dataMetaDom/sources.rb', line 32 def doneKeys; @done.keys end |
#next ⇒ Object
Returns next source file in queue if any, returns nil
if no more source files left to parse.
59 60 61 62 63 64 65 66 |
# File 'lib/dataMetaDom/sources.rb', line 59 def next return nil if @todo.empty? @key = nil @todo.each_key { |k| @key = k; break } @val = @todo[@key] @todo.delete @key; @done[@key] = @val @val end |
#queue(name) ⇒ Object
Queue a source file for parsing
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/dataMetaDom/sources.rb', line 40 def queue(name) # need to resolve the name to the path first includeDir = nil @paths.each { |m| fullName = "#{m}#{File::SEPARATOR}#{name}" if File.exist?(fullName) includeDir = m break end } raise "Missing include '#{name}' in the path #{@paths.join(File::PATH_SEPARATOR)}" unless includeDir src = SourceFile.new(includeDir, name) @todo[src.key]=src unless @todo[src.key] || @done[src.key] self end |