Class: Daedalus::DependencyGrapher::SourceFile

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

Instance Attribute Summary collapse

Attributes included from Container

#body

Instance Method Summary collapse

Methods included from Container

#close, #execute_body

Methods inherited from Node

#add_else, #close

Constructor Details

#initialize(name, parser) ⇒ SourceFile

Returns a new instance of SourceFile.



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

def initialize(name, parser)
  super parser
  @name = name
  @object_name = name.sub(/((c(pp)?)|S)$/, 'o')
  @includes = []
end

Instance Attribute Details

#dependenciesObject (readonly)

Returns the value of attribute dependencies.



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

def dependencies
  @dependencies
end

#includesObject (readonly)

Returns the value of attribute includes.



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

def includes
  @includes
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#object_nameObject (readonly)

Returns the value of attribute object_name.



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

def object_name
  @object_name
end

Instance Method Details

#collect_dependenciesObject



151
152
153
154
155
156
157
158
# File 'lib/daedalus/dependency_grapher.rb', line 151

def collect_dependencies
  set = Set.new

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

  @dependencies = set.to_a.sort
end

#execute(defines) ⇒ Object



147
148
149
# File 'lib/daedalus/dependency_grapher.rb', line 147

def execute(defines)
  execute_body defines, self
end


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

def print_dependencies(out, max)
  str = "#{@object_name}:"
  out.print str

  width = str.size
  @dependencies.each do |name|
    size = name.size + 1
    if width + size > max
      width = 0
      out.print " \\\n "
    end

    out.print " ", name
    width += size
  end

  out.print "\n"
end