Class: Gizzard::ReportCommand
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
Instance Method Details
#down(id) ⇒ Object
498
499
500
501
502
503
|
# File 'lib/gizzard/commands.rb', line 498
def down(id)
vals = manager.list_downward_links(id).map do |link|
down(link.down_id)
end
{ id.to_unix => vals }
end
|
#group(arr) ⇒ Object
472
473
474
475
476
477
478
|
# File 'lib/gizzard/commands.rb', line 472
def group(arr)
arr.inject({}) do |m, e|
m[e] ||= []
m[e] << e
m
end.to_a.sort_by { |k, v| v.length }.reverse
end
|
#parse(obj, id = nil, depth = 0, sub = true) ⇒ Object
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
|
# File 'lib/gizzard/commands.rb', line 480
def parse(obj, id = nil, depth = 0, sub = true)
case obj
when Hash
id, prefix = parse(obj.keys.first, id, depth, sub)
[ prefix ] + parse(obj.values.first, id, depth + 1, sub)
when String
host, prefix = obj.split("/")
host = "db" if host != "localhost" && sub
id ||= prefix[/(\w+ward_)?n?\d+_\d+(_\w+ward)?/]
prefix = (" " * depth) + host + "/" + ((sub && id) ? prefix.sub(id, "[ID]") : prefix)
[ id, prefix ]
when Array
obj.map do |e|
parse e, id, depth, sub
end
end
end
|
#run ⇒ Object
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
|
# File 'lib/gizzard/commands.rb', line 451
def run
things = @argv.map do |shard|
parse(down(ShardId.parse(shard))).join("\n")
end
if command_options.flat
things.zip(@argv).each do |thing, shard_id|
puts "#{sign(thing)}\t#{shard_id}"
end
else
group(things).each do |string, things|
puts "=== " + sign(string) + ": #{things.length}" + " ===================="
puts string
end
end
end
|
#sign(string) ⇒ Object
468
469
470
|
# File 'lib/gizzard/commands.rb', line 468
def sign(string)
::Digest::MD5.hexdigest(string)[0..10]
end
|