Sha256: ca22c902745a000da13f29b567a885962cbcb8451701b5ce63f98b1c6b4a9442

Contents?: true

Size: 841 Bytes

Versions: 5

Compression:

Stored size: 841 Bytes

Contents

module Tr3llo
  module Command
    module Card
      module SelfAssign
        extend self

        def execute(key, user_id)
          card_id = Entities.parse_id(:card, key)
          assert_card_id!(card_id, key)

          assign_card(card_id, user_id)

          interface = Application.fetch_interface!()

          interface.print_frame do
            interface.puts("Card has been assigned to yourself")
          end
        end

        private

        def assign_card(card_id, user_id)
          card = API::Card.find(card_id)
          members = card.members.map(&:id) + [user_id]

          API::Card.assign_members(card_id, members)
        end

        def assert_card_id!(card_id, key)
          raise InvalidArgumentError.new("#{key.inspect} is not a valid card key") unless card_id
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
3llo-1.3.1 lib/3llo/command/card/self_assign.rb
3llo-1.3.1.pre.rc.0 lib/3llo/command/card/self_assign.rb
3llo-1.2.0 lib/3llo/command/card/self_assign.rb
3llo-1.1.0 lib/3llo/command/card/self_assign.rb
3llo-1.0.0 lib/3llo/command/card/self_assign.rb