View Source AutoDocPackage.Utils (auto_doc_package v0.1.1)

Utilities for the AutoDoc package. Used for file manipulation, path conversion, and name conversion and more.

None of the functions here are meant to be used directly in your project. They are meant to be used solely by the AutoDoc package to handle custom logic.

Summary

Functions

Create nested directories. If a directory already exists, it will not raise an error and will continue to the next one in line. If the directory does not exist, it will create it and continue to the next one in line.

Generates the file path for the documentation file.

Guess the possible documentation's inner-most directory for the params.ex, responses.ex, operations.ex file paths.

Checks if a file exists.

Checks if a module name is a controller module.

Checks if a module name is a controller test module.

Checks if a module name is a test module.

Checks if a module name is a view module.

Checks if a module name is a view test module.

Converts a module name to a path.

Guess the possible documentation's operations.ex file path.

Parses the file path from relative to usable type.

Converts a path to a module name.

Returns the name of the project container.

Read file and returns the content.

Converts a string to camelCase.

Converts a string to PascalCase.

Converts a string to snake_case.

Functions

Link to this function

create_nested_directories(path)

View Source

Create nested directories. If a directory already exists, it will not raise an error and will continue to the next one in line. If the directory does not exist, it will create it and continue to the next one in line.

Important: The path should contain ONLY directories, not a file at the end or ../ in the beginning.

Link to this function

doc_file_path(documentation_path, controller_path, file_name)

View Source

Generates the file path for the documentation file.

Examples

  iex> doc_file_path("auto_doc/lib/auto_doc/documentation", "lib/auto_doc_web/controllers/page_controller.ex", "params.ex")
  "auto_doc/lib/auto_doc_web/documentation/page/params.ex"
Link to this function

doc_path(documentation_path, controller_path)

View Source

Guess the possible documentation's inner-most directory for the params.ex, responses.ex, operations.ex file paths.

Examples

  iex> doc_path("auto_doc/lib/auto_doc/documentation", "lib/auto_doc_web/controllers/page_controller.ex")
  "auto_doc/lib/auto_doc_web/documentation/page"

Checks if a file exists.

Examples

  iex> file_exists?("lib/auto_doc/utils.ex")
  true

  iex> file_exists?("auto_doc/lib/auto_doc/utils.ex")
  true

  iex> file_exists?("lib/auto_doc/not_existing.ex")
  false
Link to this function

find_schema_path(documentation_path, controller_path)

View Source
Link to this function

is_controller_module?(module_name)

View Source

Checks if a module name is a controller module.

Examples

  iex> is_controller_module?("AutoDoc.PageController")
  true

  iex> is_controller_module?("AutoDoc.PageView")
  false
Link to this function

is_controller_test_module?(module_name)

View Source

Checks if a module name is a controller test module.

Examples

  iex> is_controller_test_module?("AutoDocWeb.PageControllerTest")
  true

  iex> is_controller_test_module?("AutoDocWeb.PageController")
  false
Link to this function

is_test_module?(module_name)

View Source

Checks if a module name is a test module.

Examples

  iex> is_test_module?("AutoDoc.UtilsTest")
  true

  iex> is_test_module?("AutoDoc.Utils")
  false
Link to this function

is_view_module?(module_name)

View Source

Checks if a module name is a view module.

Examples

  iex> is_view_module?("AutoDoc.PageView")
  true

  iex> is_view_module?("AutoDoc.PageController")
  false
Link to this function

is_view_test_module?(module_name)

View Source

Checks if a module name is a view test module.

Examples

  iex> is_view_test_module?("AutoDocWeb.PageViewTest")
  true

  iex> is_view_test_module?("AutoDocWeb.PageView")
  false
Link to this function

module_name_to_path(module_name, suffix \\ "ex")

View Source

Converts a module name to a path.

Examples

  iex> module_name_to_path("AutoDoc.Utils")
  "auto_doc/lib/auto_doc/utils.ex"

  iex> module_name_to_path("AutoDoc.UtilsTest")
  "auto_doc/test/auto_doc/utils_test.exs"
Link to this function

operations_path(documentation_path, controller_path)

View Source

Guess the possible documentation's operations.ex file path.

Examples

  iex> operations_path("auto_doc/lib/auto_doc/documentation", "lib/auto_doc_web/controllers/page_controller.ex")
  "auto_doc/lib/auto_doc_web/documentation/page/operations.ex"

  iex> operations_path("auto_doc/lib/auto_doc/private/v2/documentation", "lib/auto_doc_web/private/v2/controllers/page_controller.ex")
  "auto_doc/lib/auto_doc_web/private/v2/documentation/page/operations.ex"
Link to this function

parse_file_path(file_path)

View Source

Parses the file path from relative to usable type.

Examples

  iex> parse_file_path("lib/auto_doc/utils.ex")
  "auto_doc/lib/auto_doc/utils.ex"

  iex> parse_file_path("auto_doc/lib/auto_doc/utils.ex")
  "auto_doc/lib/auto_doc/utils.ex"
Link to this function

path_to_module_name(path)

View Source

Converts a path to a module name.

Examples

  iex> path_to_module_name("auto_doc/lib/auto_doc/utils.ex")
  "AutoDoc.Utils"

  iex> path_to_module_name("auto_doc/test/auto_doc/utils_test.exs")
  "AutoDoc.UtilsTest"
Link to this function

project_container_name()

View Source

Returns the name of the project container.

Examples

  iex> project_container_name()
  "auto_doc"

Read file and returns the content.

Link to this function

run_mix_format(file_path)

View Source

Runs mix format on given file.

Examples

  iex> run_mix_format("lib/auto_doc/utils.ex")
  {:ok, "File formatted successfully."}

  iex> run_mix_format("lib/auto_doc/utils.ex")
  {:error, "File formatting failed. File: "lib/auto_doc/utils.ex""}

Converts a string to camelCase.

Examples

  iex> to_camel_case("helloWorld")
  "helloWorld"

  iex> to_camel_case("hello_world")
  "helloWorld"

  iex> to_camel_case("HelloWorld")
  "helloWorld"

  iex> to_camel_case("Invalid_Type")
  ** (ArgumentError)
  ** ...

Converts a string to PascalCase.

Examples

  iex> to_pascal_case("helloWorld")
  "HelloWorld"

  iex> to_pascal_case("hello_world")
  "HelloWorld"

  iex> to_pascal_case("HelloWorld")
  "HelloWorld"

  iex> to_pascal_case("Invalid_Type")
  ** (ArgumentError)
  ** ...

Converts a string to snake_case.

Examples

  iex> to_snake_case("helloWorld")
  "hello_world"

  iex> to_snake_case("hello_world")
  "hello_world"

  iex> to_snake_case("HelloWorld")
  "hello_world"

  iex> to_snake_case("Invalid_Type")
  ** (ArgumentError)
  ** ...
Link to this function

write_file(path, content, modes \\ [])

View Source

Write to file.