From 896a44df9d79516f8e15e124be02a7dc53a2cf8d Mon Sep 17 00:00:00 2001 From: Nathaniel Waisbrot Date: Wed, 25 Oct 2017 22:34:29 -0400 Subject: [PATCH] define the "stockable()" type as a union of meal|food|offer --- lib/open_pantry/web/models/stock.ex | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/open_pantry/web/models/stock.ex b/lib/open_pantry/web/models/stock.ex index 637deea..18b243e 100644 --- a/lib/open_pantry/web/models/stock.ex +++ b/lib/open_pantry/web/models/stock.ex @@ -35,6 +35,8 @@ defmodule OpenPantry.Stock do timestamps() end + @type stockable() :: Meal.t | Food.t | Offer.t + @doc """ Builds a changeset based on the `struct` and `params`. """ @@ -47,7 +49,7 @@ defmodule OpenPantry.Stock do |> check_constraint(:quantity, name: :non_negative_quantity) end - @spec stockable!(Stock.t) :: Meal.t | Food.t | Offer.t + @spec stockable!(Stock.t) :: stockable() def stockable!(stock) do stock.food || stock.meal || stock.offer end @@ -60,7 +62,7 @@ defmodule OpenPantry.Stock do (loaded_stock.offer && loaded_stock.offer.description) end - @spec stockable(Stock.t) :: Stock.t + @spec stockable(Stock.t) :: stockable() def stockable(stock) do stock |> stockable_load