sausage-sandwich/ruby_sandwich

View on GitHub
lib/sandwich/interactors/find_or_create_ingredient.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

require 'hanami/interactor'

class FindOrCreateIngredient
  include Hanami::Interactor

  expose :ingredient

  def call(title:)
    title = title.strip.downcase
    @ingredient = ingredient_repo.find_by_title(title) || ingredient_repo.create(title: title)
  end

  private

  def ingredient_repo
    @ingredient_repo ||= IngredientRepository.new
  end
end