Class: Daedalus::DependencyGrapher::IncludedFile

Inherits:
Node
  • Object
show all
Includes:
Container
Defined in:
lib/daedalus/dependency_grapher.rb

Instance Attribute Summary collapse

Attributes included from Container

#body

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Container

#close, #execute_body

Methods inherited from Node

#add_else, #close

Constructor Details

#initialize(name, parser) ⇒ IncludedFile

Returns a new instance of IncludedFile.



141
142
143
144
145
# File 'lib/daedalus/dependency_grapher.rb', line 141

def initialize(name, parser)
  super parser
  @name = name
  @includes = []
end

Instance Attribute Details

#includesObject (readonly)

Returns the value of attribute includes.



135
136
137
# File 'lib/daedalus/dependency_grapher.rb', line 135

def includes
  @includes
end

#nameObject (readonly)

Returns the value of attribute name.



135
136
137
# File 'lib/daedalus/dependency_grapher.rb', line 135

def name
  @name
end

Class Method Details

.cacheObject



137
138
139
# File 'lib/daedalus/dependency_grapher.rb', line 137

def self.cache
  @cache ||= {}
end

Instance Method Details

#collect_dependencies(set) ⇒ Object



180
181
182
183
184
185
# File 'lib/daedalus/dependency_grapher.rb', line 180

def collect_dependencies(set)
  return if set.include? @name

  set << @name
  @includes.each { |x| x.collect_dependencies(set) }
end

#execute(defines, node) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/daedalus/dependency_grapher.rb', line 164

def execute(defines, node)
  expand_filename(node)

  if cached = self.class.cache[@name.to_sym]
    @body = cached.body
  else
    parser = FileParser.new self, @parser.directories
    parser.parse_file @name
    self.class.cache[@name.to_sym] = self
  end

  execute_body defines, self

  node.includes << self
end

#expand_filename(node) ⇒ Object

Raises:

  • (Errno::ENOENT)


147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/daedalus/dependency_grapher.rb', line 147

def expand_filename(node)
  return if File.exist? @name

  @parser.directories.each do |dir|
    path = File.join dir, @name
    return @name = path if File.file? path
  end

  # Try to find the file in the same directory as where we're looking from
  dir = File.dirname(node.name)
  path = File.join dir, @name

  return @name = path if File.file?(path)

  raise Errno::ENOENT, "unable to find file to include: #{@name} from #{node.name}"
end