Class: Omaship::ShipDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/omaship/ship_detector.rb

Defined Under Namespace

Classes: DetectionError

Constant Summary collapse

SHIP_CONTEXT_ERROR_MESSAGE =
"Could not determine which ship to use automatically. Pass --ship <ship-domain> (or ship id) to choose a ship.".freeze

Instance Method Summary collapse

Constructor Details

#initialize(api_client:) ⇒ ShipDetector

Returns a new instance of ShipDetector.



8
9
10
# File 'lib/omaship/ship_detector.rb', line 8

def initialize(api_client:)
  @api_client = api_client
end

Instance Method Details

#detect_current_shipObject



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/omaship/ship_detector.rb', line 12

def detect_current_ship
  remote = git_remote_url
  full_name = parse_full_name(remote)
  ships = @api_client.list_ships
  match = ships.find { |ship| ship.fetch("full_name") == full_name }

  if match
    match
  else
    raise DetectionError, SHIP_CONTEXT_ERROR_MESSAGE
  end
end