Class: Spud::Lister

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/spud/lister.rb

Constant Summary collapse

TASKS_HEADER =
T.let('TASK', String)
ORDERED_HEADER =
T.let('ORDERED ARGS', String)
NAMED_HEADER =
T.let('NAMED ARGS', String)
SOURCES_HEADER =
T.let('SOURCE', String)

Instance Method Summary collapse

Constructor Details

#initialize(tasks) ⇒ Lister

Returns a new instance of Lister.



16
17
18
# File 'lib/spud/lister.rb', line 16

def initialize(tasks)
  @tasks = tasks
end

Instance Method Details

#list_tasks!Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/spud/lister.rb', line 21

def list_tasks!
  builder = StringIO.new

  if show_headers?
    builder.write TASKS_HEADER.ljust(max_task_length)

    if show_ordered_args?
      builder.write '  '
      builder.write ORDERED_HEADER.ljust(max_ordered_string_length)
    end

    if show_named_args?
      builder.write '  '
      builder.write NAMED_HEADER.ljust(max_named_string_length)
    end

    if show_sources?
      builder.write '  '
      builder.write SOURCES_HEADER
    end

    builder.write "\n"
  end

  @tasks.each do |task|
    builder.write task.name.ljust(max_task_length)

    if show_ordered_args?
      builder.write '  '
      builder.write task.args.ordered.join(' ').ljust(max_ordered_string_length)
    end

    if show_named_args?
      builder.write '  '
      builder.write task.args.named.join(' ').ljust(max_named_string_length)
    end

    if show_sources?
      builder.write '  '
      builder.write task.source
    end

    builder.write "\n"
  end

  puts builder.string
end