Created
April 2, 2018 17:41
-
-
Save cored/80a203607a344905d777673959371dfa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Scans | |
class Action | |
def self.call(scan) | |
factory(scan).call | |
end | |
def self.factory(scan) | |
const_get(scan.type.camelcase).new(scan) | |
end | |
Departure = Struct.new(:scan) do | |
def call | |
shipment.ship | |
end | |
private | |
def shipment | |
find_shipment_with_tracking or raise_shipment_not_found! | |
end | |
def find_shipment_with_tracking | |
Shipment.by_tracking(scan.tracking) | |
end | |
def raise_shipment_not_found! | |
raise NotFound.new("Departure scan for unknown tracking number") | |
end | |
end | |
end | |
class NotFound < StandardError | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment