lib/runbox/scenario.ex

defmodule Runbox.Scenario do
  @moduledoc """
  Holds information about scenario.
  """

  defstruct [:manifest, :opts, :templates]

  @type t :: %__MODULE__{
          manifest: Runbox.Scenario.Manifest.t(),
          opts: map(),
          templates: [Runbox.ScenarioTemplate.t()]
        }

  @type component_def :: %{id: term(), mod: module(), fun: atom(), args: map}

  @spec manifest_module?(module()) :: boolean()
  def manifest_module?(module) do
    case Module.split(module) do
      ["Scenario", _] -> true
      ["Scenarios", _] -> true
      ["Scenarios", "Test", _] -> true
      _ -> false
    end
  end

  @spec template_module?(module(), module()) :: boolean()
  def template_module?(module, manifest_module) do
    module |> Module.split() |> prefixed?(scenario_prefix(manifest_module))
  end

  @spec get_impl_for(String.t()) :: %{template_inspector: module()}
  def get_impl_for("StageBased") do
    %{template_inspector: Runbox.Scenario.Template.StageBased}
  end

  defp scenario_prefix(manifest_module) do
    Module.split(manifest_module)
  end

  defp prefixed?(module_parts, prefix) do
    List.starts_with?(module_parts, prefix) and module_parts != prefix
  end
end