example_files v1.0.0 ExampleFiles.File
A GenServer that provides access to a project file that serves as an example
or a template for a project file.
The state of an ExampleFiles.File process is its filesystem path.
Summary
Functions
Deletes the file at the example file’s path-when-pulled (see
path_when_pulled/1)
Returns true if the specified path qualifies as an example file
Returns the example file’s path
Computes the path of the example file when it is pulled (see pull/1)
Copies the example file to its path-when-pulled (see path_when_pulled/1)
Starts an ExampleFiles.File process, linked to the current process, with the
specified path
Computes the status of the example file
Types
An error encountered while processing an example file.
To transform the second term of the tuple into user-friendly form, pass it to
:file.format_error/1.
Functions
Deletes the file at the example file’s path-when-pulled (see
path_when_pulled/1).
Examples
iex> path = Path.join(System.tmp_dir!, String.slice(to_string(:rand.uniform), 2..-1)) <> ".example"
...> {:ok, file} = ExampleFiles.File.start_link([path])
...> false = file |> ExampleFiles.File.path_when_pulled |> File.exists?
...> {:ok, :enoent} = file |> ExampleFiles.File.clean
...> file |> ExampleFiles.File.path_when_pulled |> File.exists?
false
iex> path = Path.join(System.tmp_dir!, String.slice(to_string(:rand.uniform), 2..-1)) <> ".example"
...> {:ok, file} = ExampleFiles.File.start_link([path])
...> file |> ExampleFiles.File.path_when_pulled |> File.touch!
...> true = file |> ExampleFiles.File.path_when_pulled |> File.exists?
...> {:ok, :deleted} = file |> ExampleFiles.File.clean
...> file |> ExampleFiles.File.path_when_pulled |> File.exists?
false
Returns true if the specified path qualifies as an example file.
Examples
iex> "foo" |> ExampleFiles.File.example_file?
false
iex> "example" |> ExampleFiles.File.example_file?
false
iex> "fooexample" |> ExampleFiles.File.example_file?
false
iex> "examplefoo" |> ExampleFiles.File.example_file?
false
iex> "foo.example/bar" |> ExampleFiles.File.example_file?
false
iex> "foo.example" |> ExampleFiles.File.example_file?
true
iex> "foo/bar-example" |> ExampleFiles.File.example_file?
true
iex> "fooExample" |> ExampleFiles.File.example_file?
true
iex> "example_foo" |> ExampleFiles.File.example_file?
true
iex> "exampleFoo" |> ExampleFiles.File.example_file?
true
iex> "foo.Example" |> ExampleFiles.File.example_file?
true
iex> "Example.foo" |> ExampleFiles.File.example_file?
true
iex> "123Example" |> ExampleFiles.File.example_file?
true
iex> "Example123" |> ExampleFiles.File.example_file?
true
iex> "foo.EXAMPLE" |> ExampleFiles.File.example_file?
true
iex> "EXAMPLE.foo" |> ExampleFiles.File.example_file?
true
iex> "foo.example.bar" |> ExampleFiles.File.example_file?
true
iex> "fooExampleBar" |> ExampleFiles.File.example_file?
true
iex> "123Example456" |> ExampleFiles.File.example_file?
true
Returns the example file’s path.
Examples
iex> {:ok, file} = ExampleFiles.File.start_link("foo.example")
...> file |> ExampleFiles.File.path
"foo.example"
Computes the path of the example file when it is pulled (see pull/1).
Examples
iex> {:ok, file} = ExampleFiles.File.start_link("foo.example")
...> file |> ExampleFiles.File.path_when_pulled
"foo"
iex> {:ok, file} = ExampleFiles.File.start_link("foo/bar-example")
...> file |> ExampleFiles.File.path_when_pulled
"foo/bar"
iex> {:ok, file} = ExampleFiles.File.start_link("fooExample")
...> file |> ExampleFiles.File.path_when_pulled
"foo"
iex> {:ok, file} = ExampleFiles.File.start_link("example_foo")
...> file |> ExampleFiles.File.path_when_pulled
"foo"
iex> {:ok, file} = ExampleFiles.File.start_link("exampleFoo")
...> file |> ExampleFiles.File.path_when_pulled
"Foo"
iex> {:ok, file} = ExampleFiles.File.start_link("foo.Example")
...> file |> ExampleFiles.File.path_when_pulled
"foo"
iex> {:ok, file} = ExampleFiles.File.start_link("Example.foo")
...> file |> ExampleFiles.File.path_when_pulled
"foo"
iex> {:ok, file} = ExampleFiles.File.start_link("123Example")
...> file |> ExampleFiles.File.path_when_pulled
"123"
iex> {:ok, file} = ExampleFiles.File.start_link("Example123")
...> file |> ExampleFiles.File.path_when_pulled
"123"
iex> {:ok, file} = ExampleFiles.File.start_link("foo.EXAMPLE")
...> file |> ExampleFiles.File.path_when_pulled
"foo"
iex> {:ok, file} = ExampleFiles.File.start_link("EXAMPLE.foo")
...> file |> ExampleFiles.File.path_when_pulled
"foo"
iex> {:ok, file} = ExampleFiles.File.start_link("foo.example.bar")
...> file |> ExampleFiles.File.path_when_pulled
"foo.bar"
iex> {:ok, file} = ExampleFiles.File.start_link("fooExampleBar")
...> file |> ExampleFiles.File.path_when_pulled
"fooBar"
iex> {:ok, file} = ExampleFiles.File.start_link("123Example456")
...> file |> ExampleFiles.File.path_when_pulled
"123456"
Copies the example file to its path-when-pulled (see path_when_pulled/1).
start_link(binary | [binary], [{atom, any}]) :: GenServer.on_start
Starts an ExampleFiles.File process, linked to the current process, with the
specified path.
The process exits if path is not an example file (see example_file?/1).