Class: Tr3llo::CardCommandFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/3llo/card_command_factory.rb

Instance Method Summary collapse

Constructor Details

#initialize(subcommand, args) ⇒ CardCommandFactory

Returns a new instance of CardCommandFactory.



10
11
12
13
# File 'lib/3llo/card_command_factory.rb', line 10

def initialize(subcommand, args)
  @subcommand = subcommand
  @args = args
end

Instance Method Details

#factoryObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/3llo/card_command_factory.rb', line 15

def factory
  case subcommand
  when 'list'
    is_mine, _ = *args
    board_id = $container.resolve(:board)[:id]

    if is_mine == 'mine'
      user_id = $container.resolve(:user)[:id]
      Command::Card::ListMineCommand.new(board_id, user_id)
    else
      Command::Card::ListCommand.new(board_id)
    end
  when 'show'
    card_id, _ = args
    Command::Card::ShowCommand.new(card_id)
  when 'move'
    card_id, list_id = args
    board_id = $container.resolve(:board)[:id]
    Command::Card::MoveCommand.new(card_id, list_id, board_id)
  when 'self-assign'
    card_id, _ = args
    user_id = $container.resolve(:user)[:id]
    Command::Card::SelfAssignCommand.new(card_id, user_id)
  else
    Command::Card::InvalidCommand.new
  end
rescue Container::KeyNotFoundError
  Command::ErrorCommand.new
end