Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Switch to exconfig-based config

  • Loading branch information...
commit 50d3c72ee07e8f2d2cec63741fd3395e76826197 1 parent e91c517
Yurii Rashkovskii authored
1  .gitignore
View
@@ -10,3 +10,4 @@ sys.config.exs
/priv/static/expm
.erlang.cookie
/rel
+/config.exs
4 Makefile
View
@@ -9,8 +9,8 @@ expm: ebin
@mix escriptize
@cp ./expm priv/static
-sys.config: sys.config.exs
- @mix run "{:ok, b} = File.read \"sys.config.exs\"; {v, _} = Code.eval(b); :io.format(\"~p.~n\", [v])" > sys.config
+sys.config: config.exs
+ @ERL_LIBS=deps elixir -pa ebin -e "config = Expm.Config.file!(%b{config.exs}); config.sys_config!(%b{sys.config})"
start: expm sys.config
@ERL_LIBS=deps elixir --sname expm --erl "-pa ebin -config sys -s Elixir-Expm" --no-halt
7 config.exs.sample
View
@@ -0,0 +1,7 @@
+Expm.Config.config do
+ config.repository quote do: Expm.Repository.DETS.new(filename: "expm.dat")
+ # config.http_port 8080
+ # config.site_title ""
+ # config.site_subtitle ""
+ # config.log_dir "/path/to/logdir"
+end
40 lib/config.ex
View
@@ -0,0 +1,40 @@
+defmodule Expm.Config do
+ use ExConfig.Object
+
+ defproperty http_port, default: 8080
+ defproperty site_title, default: "Elixir Packages"
+ defproperty site_subtitle, default: %b{<small>A repository for publishing <a href="http://elixir-lang.org">Elixir</a> & <a href="http://erlang.org">Erlang</a> packages</small>}
+ defproperty repository
+
+ defproperty log_dir, default: "log"
+
+ def sys_config(config) do
+ [
+ expm: [
+ app_module: Expm.Server,
+ site_title: config.site_title,
+ site_subtitle: config.site_subtitle,
+ repository: config.repository,
+ http_port: config.http_port
+ ],
+ lager:
+ [handlers: [
+ {:lager_console_backend, :info},
+ {:lager_file_backend, [
+ {to_char_list(File.join(config.log_dir, "debug.log")), :debug, 10485760, '$D0', 5},
+ {to_char_list(File.join(config.log_dir, "error.log")), :error, 10485760, '$D0', 5},
+ {to_char_list(File.join(config.log_dir, "console.log")), :info, 10485760, '$D0', 5},
+ ]
+ }
+ ],
+ error_logger_redirect: true
+ ],
+ kernel: [error_logger: false],
+ sasl: [sasl_error_logger: false]
+ ]
+ end
+
+ def sys_config!(filename, config) do
+ File.write!(filename, :io_lib.format("~p.~n",[sys_config(config)]))
+ end
+end
3  mix.exs
View
@@ -15,7 +15,7 @@ defmodule Expm.Mixfile do
# Configuration for the OTP application
def application do
[applications: [:lager, :lagerex, :hackney, :ranch, :cowboy, :mimetypes, :inets,
- :genx, :crypto, :exreloader, :erlpass],
+ :genx, :crypto, :exreloader, :erlpass, :exconfig],
mod: {Expm, []}]
end
@@ -34,6 +34,7 @@ defmodule Expm.Mixfile do
{:proper, github: "manopapad/proper"},
{:bcrypt, github: "spawngrid/erlang-bcrypt"},
{:relex, github: "yrashk/relex"},
+ {:exconfig, github: "yrashk/exconfig"},
]
end
1  mix.lock
View
@@ -2,6 +2,7 @@
"cowboy": "0b82eebed654bd894802acb52697a4d4187cb228",
"edown": "35f8296a25d14c5c1e3209399a2c1856700d9d5b",
"erlpass": "9df3643db39b5acad44643ddbcabb090437c8519",
+ "exconfig": "c6401a041bac19f53d0afd1f839e19347eded209",
"exreloader": "82e1bd157b75ed4a362f128d9d24646f36a586ba",
"genx": "da972d408887c137a538430f0f5b65c1ff2bbf69",
"hackney": "896fc24e8efb4a5a6966cae13e749ab7cf1f73e2",
20 sys.config.sample.exs
View
@@ -1,20 +0,0 @@
-[expm:
- [app_module: Expm.Server,
- http_port: 8080,
- site_title: "Elixir Packages",
- site_subtitle: %b{<small>A repository for publishing <a href="http://elixir-lang.org">Elixir</a> & <a href="http://erlang.org">Erlang</a> packages</small>},
- repository: quote do: Expm.Repository.DETS.new(filename: "expm.dat")],
- lager:
- [handlers: [
- {:lager_console_backend, :info},
- {:lager_file_backend, [
- {'log/debug.log', :debug, 10485760, '$D0', 5},
- {'log/error.log', :error, 10485760, '$D0', 5},
- {'log/console.log', :info, 10485760, '$D0', 5},
- ]
- }
- ],
- error_logger_redirect: true
- ],
- kernel: [error_logger: false],
- sasl: [sasl_error_logger: false]]
Please sign in to comment.
Something went wrong with that request. Please try again.