Class: Gizzard::SubtreeCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/gizzard/commands.rb

Instance Attribute Summary

Attributes inherited from Command

#argv, #buffer, #command_options, #global_options, #job_injector, #manager

Instance Method Summary collapse

Methods inherited from Command

classify, #confirm!, #get_base_name, #help!, #initialize, make_job_injector, make_manager, #output, #require_tables, #require_template_options, run

Constructor Details

This class inherits a constructor from Gizzard::Command

Instance Method Details

#down(id, depth = 0) ⇒ Object



214
215
216
217
218
219
220
# File 'lib/gizzard/commands.rb', line 214

def down(id, depth = 0)
  manager.list_downward_links(id).map do |link|
    printable = "  " * depth + link.down_id.to_unix
    output printable
    down(link.down_id, depth + 1)
  end
end

#roots_of(id) ⇒ Object



205
206
207
208
209
210
211
212
# File 'lib/gizzard/commands.rb', line 205

def roots_of(id)
  links = manager.list_upward_links(id)
  if links.empty?
    [id]
  else
    links.map { |link| roots_of(link.up_id) }.flatten
  end
end

#runObject



193
194
195
196
197
198
199
200
201
202
203
# File 'lib/gizzard/commands.rb', line 193

def run
  @roots = []
  argv.each do |arg|
    @id = ShardId.parse(arg)
    @roots += roots_of(@id)
  end
  @roots.uniq.each do |root|
    output root.to_unix
    down(root, 1)
  end
end