Class: Omaship::ShipDetector
- Inherits:
-
Object
- Object
- Omaship::ShipDetector
- 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
- #detect_current_ship ⇒ Object
-
#initialize(api_client:) ⇒ ShipDetector
constructor
A new instance of ShipDetector.
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_ship ⇒ Object
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 |