Skip to content

Commit

Permalink
Merge pull request #107 from paulo-ferraz-oliveira/feature/minor-main…
Browse files Browse the repository at this point in the history
…tenance-updates

Maintenance updates
  • Loading branch information
elbrujohalcon authored Aug 7, 2023
2 parents 8bd861f + a3436a9 commit 3b223f2
Show file tree
Hide file tree
Showing 21 changed files with 615 additions and 688 deletions.
36 changes: 17 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,36 @@
---
name: build
on:
push:
branches:
- master
pull_request:
branches:
- master
on: [push, pull_request]
jobs:
ci:
name: Run checks and tests over ${{matrix.otp_vsn}} and ${{matrix.os}}
runs-on: ${{matrix.os}}
name: Run checks and tests over ${{matrix.otp_vsn}}
runs-on: ubuntu-22.04
strategy:
matrix:
otp_vsn: [21, 22, 23, 24]
os: [ubuntu-latest]
otp_vsn: ['24', '25', '26']
rebar3_vsn: ['3.22']
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp_vsn}}
rebar3-version: '3.14'
rebar3-version: ${{matrix.rebar3_vsn}}
- run: |
rm -rf example/_checkouts # Prevent long running analysis
rebar3 test
example:
name: Makes sure our example run over ${{matrix.otp_vsn}} and ${{matrix.os}}
runs-on: ${{matrix.os}}
name: Makes sure our example run over ${{matrix.otp_vsn}}
runs-on: ubuntu-22.04
strategy:
matrix:
otp_vsn: [21, 22, 23, 24]
os: [ubuntu-latest]
otp_vsn: ['24', '25', '26']
rebar3_vsn: ['3.22']
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp_vsn}}
rebar3-version: '3.14'
rebar3-version: ${{matrix.rebar3_vsn}}
- name: test our example
run: |
cd example
Expand All @@ -53,6 +47,10 @@ jobs:
R=$(curl -s -w "%{http_code}" -XDELETE "localhost:8080/poor-kv/some-key" -H "content-type: text/plain")
[[ $R == "404" ]] || exit 1
_build/default/rel/example/bin/example stop
- name: Format check
run: |
cd example
rebar3 format --verify
- name: check our example
run: |
cd example
Expand Down
22 changes: 5 additions & 17 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
logs/
.eunit
deps
*.o
*.beam
*.plt
erl_crash.dump
ebin
rel/example_project
.concrete/DEV_MODE
.rebar
.erlang.mk*
elvis
*.d
_build
/rebar.lock
doc
rebar3.crashdump
_*
doc/
rebar3.crashdump
.rebar3
logs
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
https://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

Expand Down Expand Up @@ -192,7 +192,7 @@
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0
https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If you find any **bugs** or have a **problem** while using this library, please
[open an issue](https://github.com/inaka/cowboy-trails/issues/new) in this repo
(or a pull request 😄).

And you can check out all of our open-source projects at [inaka.github.io](http://inaka.github.io).
And you can check out all of our open-source projects at [inaka.github.io](https://inaka.github.io).

## Why Cowboy Trails?

Expand Down Expand Up @@ -104,11 +104,13 @@ Dispatch = cowboy_router:compile(Routes),

But now, with `trails`, you're able to define the routes on each of your resource handlers,
separately.
These handlers must implement callback `trails/0` or `trails/1` and return the specific
These handlers must implement callback `c:trails_handler:trails/0` or `c:trails_handler:trails/1`
and return the specific
routes that define them. For a better understanding, you can check out the
examples in the `test` folder ([trails_test_handler](./test/trails_test_handler.erl)).
examples in the `test` folder ([trails_test_handler](https://github.com/inaka/cowboy-trails/blob/master/test/trails_test_handler.erl)).

Once you have implemented the `trails/0` or `trails/1` callback on your handlers, you can do
Once you have implemented the `c:trails_handler:trails/0` or `c:trails_handler:trails/1` callback
on your handlers, you can do
something like this:

```erlang
Expand Down Expand Up @@ -137,4 +139,4 @@ merge them easily.
## Example

For more information about `cowboy_trails`, how to use it and the different
functions that it exposes, please check this [example](./example).
functions that it exposes, please check this [example](https://github.com/inaka/cowboy-trails/blob/master/example).
40 changes: 15 additions & 25 deletions elvis.config
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
[
{
elvis,
[
{config,
[#{dirs => ["src", "test"],
filter => "*.erl",
rules => [{elvis_style, invalid_dynamic_call, #{ignore => [trails_handler]}},
{elvis_style, dont_repeat_yourself, #{min_complexity => 14}},
{elvis_style, god_modules, #{ ignore => [trails_SUITE]}}],
ruleset => erl_files
},
#{dirs => ["."],
filter => "rebar.config",
ruleset => rebar_config
},
#{dirs => ["."],
filter => "elvis.config",
ruleset => elvis_config
}
]
}
]
}
].
[{elvis,
[{config,
[#{dirs => ["src", "test"],
filter => "*.erl",
rules =>
[{elvis_style, invalid_dynamic_call, #{ignore => [trails_handler]}},
{elvis_style, dont_repeat_yourself, #{min_complexity => 14}},
{elvis_style, god_modules, #{ignore => [trails_SUITE]}}],
ruleset => erl_files},
#{dirs => ["."],
filter => "rebar.config",
ruleset => rebar_config},
#{dirs => ["."],
filter => "elvis.config",
ruleset => elvis_config}]}]}].
74 changes: 33 additions & 41 deletions example/rebar.config
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
%% -*- mode: erlang;erlang-indent-level: 2;indent-tabs-mode: nil -*-
%% ex: ts=4 sw=4 ft=erlang et
%% == Compiler and Profiles ==

%% == Erlang Compiler ==

%% Erlang compiler options
{erl_opts,
[warn_unused_vars,
warn_export_all,
warn_shadow_vars,
warn_unused_import,
warn_unused_function,
warn_bif_clash,
warn_unused_record,
warn_deprecated_function,
warn_obsolete_guard,
strict_validation,
warn_export_vars,
warn_exported_vars,
warn_untyped_record,
debug_info]}.

%% == Dependencies ==

{deps,
[{mixer, "1.2.0", {pkg, inaka_mixer}},
trails]}. % checked out

{project_plugins, [rebar3_lint, rebar3_hank, rebar3_format]}.
[warn_unused_import, warn_export_vars, warnings_as_errors, verbose, report, debug_info]}.

{minimum_otp_vsn, "23"}.

{alias, [{test, [compile, format, hank, lint, xref, dialyzer]}]}.

%% == Dependencies and plugins ==

{deps, [{mixer, "1.2.0", {pkg, inaka_mixer}}, trails]}. % checked out

{project_plugins,
[{rebar3_hank, "~> 1.4.0"}, {rebar3_format, "~> 1.3.0"}, {rebar3_lint, "~> 3.0.1"}]}.

%% == Format ==

{format, [{files, ["*.config", "src/*"]}]}.

%% == Hank ==

{hank, [{ignore, ["_build/**", "_checkouts"]}]}.

%% == Dialyzer + XRef ==

{dialyzer,
[{warnings, [no_return, underspecs, unmatched_returns, error_handling, unknown]}]}.

{xref_checks,
[undefined_function_calls, deprecated_function_calls, deprecated_functions]}.

{xref_extra_paths, ["test/**"]}.

%% == Shell (for interactive example) ==

Expand All @@ -38,17 +42,5 @@
[{include_src, false},
{extended_start_script, true},
{release, {example, "0.1"}, [example, sasl]},
{sys_config, "rel/sys.config"}]}.

%% == Alias ==

{alias, [{test, [dialyzer, lint, hank]}]}.

%% == hank ==

{hank, [
{ignore, [
"_build/**",
"_checkouts/**"
]}
]}.
{sys_config, "rel/sys.config"},
{vm_args, "rel/vm.args"}]}.
5 changes: 1 addition & 4 deletions example/rel/sys.config
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
[{example,
[{http_port, 8080},
{http_listener_count, 10}]}
].
[{example, [{http_port, 8080}, {http_listener_count, 10}]}].
2 changes: 2 additions & 0 deletions example/rel/vm.args
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-name [email protected]
-setcookie bogus
2 changes: 1 addition & 1 deletion example/src/example.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ stop(_State) ->
ok = cowboy:stop_listener(example_http).

% start_listeners() ->
-spec start_phase(atom(), application:start_type(), []) -> ok | {error, term()}.
-spec start_phase(atom(), application:start_type(), []) -> ok.
start_phase(start_trails_http, _StartType, []) ->
{ok, Port} = application:get_env(example, http_port),
{ok, ListenerCount} = application:get_env(example, http_listener_count),
Expand Down
Loading

0 comments on commit 3b223f2

Please sign in to comment.