Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add load_mapping function to hide code generation

  • Loading branch information...
commit ec5ad7800349f81bdc061db3ebb3a21a5c89dd48 1 parent c006ad8
Magnus Klaar authored

Showing 1 changed file with 9 additions and 2 deletions. Show diff stats Hide diff stats

  1. +9 2 src/mimetypes.erl
11 src/mimetypes.erl
@@ -11,6 +11,7 @@
11 11 terminate/2, code_change/3]).
12 12
13 13 -define(SERVER, ?MODULE).
  14 +-define(MAPMOD, mimetypes_map).
14 15
15 16 -record(state, {
16 17 mime_types,
@@ -202,6 +203,13 @@ aggregate_extensions_1([{Ext, Type1},{Ext, Type2}|Rest]) when is_list(Type1) ->
202 203 aggregate_extensions_1([H|T]) ->
203 204 [H|aggregate_extensions_1(T)].
204 205
  206 +%% @private Load a list of mimetype-extension pairs.
  207 +-spec load_mapping([{binary(), binary()}]) -> ok.
  208 +load_mapping(Pairs) ->
  209 + Module = ?MAPMOD,
  210 + AbsCode = map_to_abstract(Module, Pairs),
  211 + compile_and_load_forms(AbsCode, []).
  212 +
205 213
206 214 %% @private Generate an abstract mimtype mapping module.
207 215 -spec map_to_abstract(atom(), [{binary(), binary()}]) -> [erl_syntax:syntaxTree()].
@@ -282,8 +290,7 @@ load_binary(Name, Binary) ->
282 290 -include_lib("eunit/include/eunit.hrl").
283 291
284 292 codegen_test() ->
285   - AbsCode = map_to_abstract(mimetypes_map, [{<<"a">>, <<"b">>}]),
286   - ok = compile_and_load_forms(AbsCode, []),
  293 + ok = load_mapping([{<<"a">>, <<"b">>}]),
287 294 mimetypes_map:module_info(),
288 295 ?assertEqual([<<"a">>], mimetypes_map:ext_to_mimes(<<"b">>)),
289 296 ?assertEqual([<<"b">>], mimetypes_map:mime_to_exts(<<"a">>)).

0 comments on commit ec5ad78

Please sign in to comment.
Something went wrong with that request. Please try again.