Class: DataMetaDom::Sources

Inherits:
Object
  • Object
show all
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

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

#doneKeysObject

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

#nextObject

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