Skip to content

Instantly share code, notes, and snippets.

@cored
Created April 2, 2018 17:41
Show Gist options
  • Save cored/80a203607a344905d777673959371dfa to your computer and use it in GitHub Desktop.
Save cored/80a203607a344905d777673959371dfa to your computer and use it in GitHub Desktop.
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