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 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
nilif 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.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dataMetaDom/sources.rb', line 17 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 Method Details
#[](key) ⇒ Object
Fetches the instance of SourceFile by its key.
36 |
# File 'lib/dataMetaDom/sources.rb', line 36 def [](key); @done[key] end |
#doneKeys ⇒ Object
Returns the set of the keys of the source files alredy parsed.
31 |
# File 'lib/dataMetaDom/sources.rb', line 31 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.
58 59 60 61 62 63 64 65 |
# File 'lib/dataMetaDom/sources.rb', line 58 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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dataMetaDom/sources.rb', line 39 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 |