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.



189
190
191
192
193
# File 'lib/daedalus/dependency_grapher.rb', line 189

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

Instance Attribute Details

#includesObject (readonly)

Returns the value of attribute includes.



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

def includes
  @includes
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.cacheObject



185
186
187
# File 'lib/daedalus/dependency_grapher.rb', line 185

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

Instance Method Details

#collect_dependencies(set) ⇒ Object



228
229
230
231
232
233
# File 'lib/daedalus/dependency_grapher.rb', line 228

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

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

#execute(defines, node) ⇒ Object



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/daedalus/dependency_grapher.rb', line 212

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)


195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/daedalus/dependency_grapher.rb', line 195

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