<commit_before>defmodule Weber.App do
  use GenServer.Behaviour

  @moduledoc """
    Weber web application initial process (Starts cowboy, parse routes, and etc...)
  """

  defrecord WeberApp,
    name:   nil, 
    routes: nil,
    config: nil,
    root:   nil,
    static_dir: nil,
    views_dir:  nil
  
  @doc """
  Start process which stores all project's parameters (router parameters, application name,
  static files directory and etc...).
  """
  def start_link(app_name, routes, root_directory, config) do
    :gen_server.start_link({:local, app_name}, __MODULE__, [app_name, routes, root_directory, config], [])
  end

  def init([app_name, routes, root_directory, config]) do
    :gen_server.cast(:erlang.self(), :init)
    :ets.new(:req_storage, [:named_table, :public, :set, {:keypos, 1}])
    { :ok, WeberApp.new name: app_name, 
                        routes: routes, 
                        root: root_directory, 
                        config: config,
                        static_dir: root_directory ++ '/public/',
                        views_dir:  root_directory ++ '/lib/views/' }
  end

  def handle_cast(:init, state) do
    Cowboy.start(state.name, state.config)
    {:noreply, state}
  end

  def handle_call(:routes, _from, state) do
    { :reply, state.routes, state }
  end

  def handle_call(:config, _from, state) do
    { :reply, state.config, state }
  end

  def handle_call(:root, _from, state) do
    { :reply, state.root, state }
  end

  def handle_call(:static, _from, state) do
    { :reply, state.static_dir, state }
  end

  def handle_call(:views, _from, state) do
    { :reply, state.views_dir, state }
  end

end<commit_msg>Remove handle_cast; Cowboy started in init function.<commit_after>defmodule Weber.App do
  use GenServer.Behaviour

  @moduledoc """
    Weber web application initial process (Starts cowboy, parse routes, and etc...)
  """

  defrecord WeberApp,
    name:   nil, 
    routes: nil,
    config: nil,
    root:   nil,
    static_dir: nil,
    views_dir:  nil
  
  @doc """
  Start process which stores all project's parameters (router parameters, application name,
  static files directory and etc...).
  """
  def start_link(app_name, routes, root_directory, config) do
    :gen_server.start_link({:local, app_name}, __MODULE__, [app_name, routes, root_directory, config], [])
  end

  def init([app_name, routes, root_directory, config]) do
    :ets.new(:req_storage, [:named_table, :public, :set, {:keypos, 1}])
    Cowboy.start(app_name, config)
    { :ok, WeberApp.new name: app_name, 
                        routes: routes, 
                        root: root_directory, 
                        config: config,
                        static_dir: root_directory ++ '/public/',
                        views_dir:  root_directory ++ '/lib/views/' }
  end

  def handle_call(:routes, _from, state) do
    { :reply, state.routes, state }
  end

  def handle_call(:config, _from, state) do
    { :reply, state.config, state }
  end

  def handle_call(:root, _from, state) do
    { :reply, state.root, state }
  end

  def handle_call(:static, _from, state) do
    { :reply, state.static_dir, state }
  end

  def handle_call(:views, _from, state) do
    { :reply, state.views_dir, state }
  end

end
{'fraction_non_alphanumeric': 0.11847328244274809, 'fraction_numerical': 0.0006106870229007634, 'mean_word_length': 2.664429530201342, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3344232', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1030, 'n_words': 292}