Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 54 lines (49 sloc) 1.148 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
defmodule Dynamo do
  @doc """
Starts the Dynamo framework.
"""
  def start(env, root) when is_atom(env) and is_binary(root) do
    :application.start(:mimetypes)
    :application.start(:crypto)
    :application.start(:dynamo)
    :application.set_env(:dynamo, :env, env)
    :application.set_env(:dynamo, :root, root)
  end

  @doc """
Sets the Dynamo application.
"""
  def app(nil) do
    :application.set_env(:dynamo, :app, nil)
  end

  def app(app) do
    if current = app() do
      raise "Cannot load Dynamo application #{inspect app}, because #{inspect current} is already loaded"
    else
      :application.set_env(:dynamo, :app, app)
    end
  end

  @doc """
Retrieves the current Dynamo application.
Returns nil if none is set.
"""
  def app do
    case :application.get_env(:dynamo, :app) do
      { :ok, val } -> val
      :undefined -> nil
    end
  end

  @doc """
Reads the current environment.
"""
  def env do
    { :ok, env } = :application.get_env(:dynamo, :env)
    env
  end

  @doc """
Reads Dynamo root.
"""
  def root do
    { :ok, root } = :application.get_env(:dynamo, :root)
    root
  end
end
Something went wrong with that request. Please try again.