View Source Recode.Project (Recode v0.1.0)

The %Project{} conatins all Recode.Sources of a project.

Link to this section Summary

Functions

Retruns conflicts between sources.

Counts the items of the given type in the project.

Creates a %Project{} from the given sources.

Returns true if any source has one or more issues.

Return a %Project{} where each source is the result of invoking fun on each source of the given project.

Creates a %Project{} from the given inputs.

Saves all sources in the project to disk.

Same as source/2 but raises on error.

Returns a %Source{} for the given key.

Returns all sources sorted by path.

Returns the unreferenced sources.

Updates the project with the given source.

Link to this section Types

@type id() :: reference()
@type t() :: %Recode.Project{
  inputs: [Path.t()],
  modules: term(),
  paths: %{required(Path.t()) => id()},
  sources: %{required(id()) => Recode.Source.t()}
}

Link to this section Functions

@spec conflicts(t()) :: %{required(Path.t()) => [Recode.Source.t()]}

Retruns conflicts between sources.

Sources with the same path have a conflict.

@spec count(t(), type :: :sources | :scripts) :: non_neg_integer()

Counts the items of the given type in the project.

The type :sources returns the count for all sources in the project, including scripts.

The type :scripts returns the count of all sources with a path that ends with ".exs".

Creates a %Project{} from the given sources.

@spec issues?(t()) :: boolean()

Returns true if any source has one or more issues.

Link to this function

map(project, opts \\ nil, fun)

View Source
@spec map(t(), opts, fun) :: t()
when opts: term() | nil,
     fun:
       (Recode.Source.t() -> Recode.Source.t())
       | (Recode.Source.t(), term() -> Recode.Source.t())

Return a %Project{} where each source is the result of invoking fun on each source of the given project.

The optional opts becomes the second argument of fun.

The fun must return {:ok, source} to update the project or :error to skip the update of the source.

@spec new(Path.t() | [Path.t()]) :: t()

Creates a %Project{} from the given inputs.

The inputs can also contain wildcards.

examples

Examples

iex> alias Recode.Project
Link to this function

save(project, exclude \\ [])

View Source
@spec save(t(), [Path.t()]) :: :ok | {:error, :conflicts | {Path.t(), File.posix()}}

Saves all sources in the project to disk.

This function call Recode.Source.save/1 on all sources in the project.

The optional second argument accepts a list of paths for files to be excluded.

@spec source!(t(), key) :: Recode.Source.t() when key: id() | Path.t() | module()

Same as source/2 but raises on error.

@spec source(t(), key) :: {:ok, Recode.Source.t()} | :error when key: id() | Path.t()

Returns a %Source{} for the given key.

The key could be a path or an id. For path keys, the most recent file is returned.

examples

Examples

iex> source = Source.from_string(
...>    """
...>    defmodule MyApp.Mode do
...>    end
...>    """,
...>    "my_app/mode.ex"
...> )
iex> project = Project.from_sources([source])
iex> Project.source(project, "my_app/mode.ex")
{:ok, source}
iex> Project.source(project, source.id)
{:ok, source}
iex> Project.source(project, "foo")
:error

iex> source = Source.from_string(":a", "a.ex")
iex> project = Project.from_sources(
...>   [source, Source.from_string(":b", "b.ex")]
...> )
iex> update = Source.update(source, :test, path: "b.ex")
iex> project = Project.update(project, update)
iex> Project.source(project, "a.ex")
{:ok, update}
iex> Project.source(project, "b.ex")
{:ok, update}
@spec sources(t()) :: [Recode.Source.t()]

Returns all sources sorted by path.

@spec unreferenced(t()) :: [Recode.Source.t()]

Returns the unreferenced sources.

Unreferenced source are sources whose original path is no longer part of the project.

@spec update(t(), Recode.Source.t()) :: t()

Updates the project with the given source.

If the source is part of the project the source will be replaced, otherwise the source will be added.