Class: Escort::Formatter::Commands

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/escort/formatter/commands.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(setup, context) ⇒ Commands

Returns a new instance of Commands.



18
19
20
21
# File 'lib/escort/formatter/commands.rb', line 18

def initialize(setup, context)
  @setup = setup
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



16
17
18
# File 'lib/escort/formatter/commands.rb', line 16

def context
  @context
end

#setupObject (readonly)

Returns the value of attribute setup.



16
17
18
# File 'lib/escort/formatter/commands.rb', line 16

def setup
  @setup
end

Class Method Details

.command_for(setup, context) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/escort/formatter/commands.rb', line 7

def command_for(setup, context)
  if context.empty?
    GlobalCommand.new(setup)
  else
    Command.new(context.last, setup, context)
  end
end

Instance Method Details

#countObject Also known as: size



30
31
32
# File 'lib/escort/formatter/commands.rb', line 30

def count
  setup.canonical_command_names_for(context).size
end

#each(&block) ⇒ Object



23
24
25
26
27
28
# File 'lib/escort/formatter/commands.rb', line 23

def each(&block)
  setup.canonical_command_names_for(context).each do |command_name|
    command = Command.new(command_name, setup, context)
    block.call(command)
  end
end