Module: ARake::Misc

Defined in:
lib/arake.rb

Defined Under Namespace

Classes: Tree

Class Method Summary collapse

Class Method Details

.pt_table_from_tasks(tasks) ⇒ Object

prerequisite-to-target table



109
110
111
112
113
114
115
116
117
# File 'lib/arake.rb', line 109

def self.pt_table_from_tasks(tasks)  # prerequisite-to-target table
  h = Hash.new {|h, name| h[name] = []}
  tasks.each do |target_task|
    target_task.prerequisites.each do |prerequisite|
      h[prerequisite.to_s].push target_task
    end
  end
  h
end

.root_tasks_of(task, tasks) ⇒ Object



105
106
107
# File 'lib/arake.rb', line 105

def self.root_tasks_of(task, tasks)
  tree_from_task(task, pt_table_from_tasks(tasks)).leaves
end

.tree_from_task(task, table = Hash.new {|h, key| h[key] = []}) ⇒ Object



119
120
121
122
123
124
# File 'lib/arake.rb', line 119

def self.tree_from_task(task, table = Hash.new {|h, key| h[key] = []})
  t = Tree.new
  t.value = task
  t.subtrees = table[task.to_s].map {|x| tree_from_task x, table}
  t
end