defmodule AppConfig do

  defmacro read_db_config do
    cond do
      database_url = System.get_env("DB_URL") ->
        database_url
      File.exists?("config/database.json")->
        {:ok, config_json} = File.read "config/database.json"
        {:ok, config} = JSEX.decode config_json
        database_url = config["#{Mix.env}"]
      true ->
        raise("Database details not found. Either create a config/database.json or set DATABASE_URL env")
    end

    quote do
      def url do
        unquote(database_url)
      end
    end
  end

end

defmodule AppConfig do

  defmacro read_db_config do
    cond do
      System.get_env("STACK") == "cedar" ->
        quote do
          def url do
            System.get_env("DATABASE_URL")
          end
        end

      File.exists?("config/database.json")->
        {:ok, config_json} = File.read "config/database.json"
        {:ok, config} = JSEX.decode config_json
        database_url = config["#{Mix.env}"]

        quote do
          def url do
            unquote(database_url)
          end
        end
      true ->
        raise("Database details not found. Either create a config/database.json or set DATABASE_URL env")
    end

  end
end

Check if heroku and use DATABASE_URL env var in read_db_config macro
Check if heroku and use DATABASE_URL env var in read_db_config macro

sashafklein/bloc-mogo,sashafklein/bloc-mogo,di-stars/mogo-chat,di-stars/mogo-chat,louishawkins/mogo-chat,HashNuke/mogo-chat,di-stars/mogo-chat,louishawkins/mogo-chat,HashNuke/mogo-chat,louishawkins/mogo-chat,HashNuke/mogo-chat,sashafklein/bloc-mogo