Skip to content

Commit

Permalink
define the "stockable()" type as a union of meal|food|offer
Browse files Browse the repository at this point in the history
  • Loading branch information
waisbrot committed Oct 26, 2017
1 parent e6898e3 commit 896a44d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/open_pantry/web/models/stock.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
"""
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 896a44d

Please sign in to comment.