Class: Mj::AlternativeFile::Commands::ListCommandHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/mj/alternative_file/commands/list_command_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(resolvers:) ⇒ ListCommandHandler

Returns a new instance of ListCommandHandler.



7
8
9
# File 'lib/mj/alternative_file/commands/list_command_handler.rb', line 7

def initialize(resolvers:)
  @resolvers = resolvers
end

Instance Method Details

#handle(command) ⇒ Object

rubocop:disable Metrics/MethodLength



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mj/alternative_file/commands/list_command_handler.rb', line 12

def handle(command)
  candidates = @resolvers.resolve(command.file)

  if command.types.any?
    candidates = candidates.of_types(command.types)
  end

  if command.exists?
    candidates = candidates.existing
  end

  unless command.debug?
    candidates = candidates.unique
  end

  candidates.sorted_by_path
end