diff --git a/.formatter.exs b/.formatter.exs index ed93f21..fe7b600 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,3 +1,5 @@ +# Used by "mix format" [ - import_deps: [:ecto] + import_deps: [:ecto], + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] ] diff --git a/.gitignore b/.gitignore index a0ad33a..6bf5ecb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,14 @@ # The directory Mix will write compiled artifacts to. -/_build +/_build/ # If you run "mix test --cover", coverage assets end up here. -/cover +/cover/ # The directory Mix downloads your dependencies sources to. -/deps +/deps/ -# Where 3rd-party dependencies like ExDoc output generated docs. -/doc +# Where third-party dependencies like ExDoc output generated docs. +/doc/ # Ignore .fetch files in case you like to edit your project deps locally. /.fetch @@ -18,4 +18,9 @@ erl_crash.dump # Also ignore archive artifacts (built via "mix archive.build"). *.ez -.elixir_ls + +# Ignore package tarball (built via "mix hex.build"). +ecto_ranked-*.tar + +# Temporary files, for example, from tests. +/tmp/ diff --git a/LICENSE b/LICENSE.md similarity index 98% rename from LICENSE rename to LICENSE.md index c050590..7162005 100644 --- a/LICENSE +++ b/LICENSE.md @@ -1,4 +1,4 @@ -MIT License +# The MIT License Copyright (c) 2017 Dylan Markow diff --git a/README.md b/README.md old mode 100755 new mode 100644 index b60034e..a5e121f --- a/README.md +++ b/README.md @@ -1,15 +1,23 @@ # EctoRanked +[![Module Version](https://img.shields.io/hexpm/v/ecto_ranked.svg)](https://hex.pm/packages/ecto_ranked) +[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/ecto_ranked/) +[![Total Download](https://img.shields.io/hexpm/dt/ecto_ranked.svg)](https://hex.pm/packages/ecto_ranked) +[![License](https://img.shields.io/hexpm/l/ecto_ranked.svg)](https://github.com/dmarkow/ecto_ranked/blob/master/LICENSE.md) +[![Last Updated](https://img.shields.io/github/last-commit/dmarkow/ecto_ranked.svg)](https://github.com/dmarkow/ecto_ranked/commits/master) + This package adds automatic ranking to your Ecto models. It's heavily based on the Rails [ranked-model](https://github.com/mixonic/ranked-model) gem. ## Installation -The package can be installed by adding `ecto_ranked` to your list of dependencies in `mix.exs`: +The package can be installed by adding `:ecto_ranked` to your list of dependencies in `mix.exs`: ```elixir def deps do - [{:ecto_ranked, "~> 0.4.0"}] + [ + {:ecto_ranked, "~> 0.4.0"} + ] end ``` @@ -132,3 +140,10 @@ Documentation can be found at [https://hexdocs.pm/ecto_ranked](https://hexdocs.p - Everyone who contributed to [ranked-model](https://github.com/mixonic/ranked-model/graphs/contributors), of which this package is a rough clone. - [EctoOrdered](https://github.com/zovafit/ecto-ordered), which provided a great starting point. + +## Copyright and License + +Copyright (c) 2017 Dylan Markow + +This work is free. You can redistribute it and/or modify it under the +terms of the MIT License. See the [LICENSE.md](./LICENSE.md) file for more details. diff --git a/lib/ecto_ranked.ex b/lib/ecto_ranked.ex index 7cf0f50..eb8f8d5 100644 --- a/lib/ecto_ranked.ex +++ b/lib/ecto_ranked.ex @@ -1,6 +1,6 @@ defmodule EctoRanked do @moduledoc """ - This module provides support for automatic ranking of your Ecto models. + This module provides support for automatic ranking of your `Ecto` models. """ import Ecto.Changeset import Ecto.Query @@ -13,6 +13,7 @@ defmodule EctoRanked do the other items in the list as necessary. ## Options + * `:rank` - the field to store the actual ranking in. Defaults to `:rank` * `:position` - the field to use for positional changes. Defaults to `:position` * `:scope` - the field(s) to scope all rankings to. Defaults to `nil` (no scoping). diff --git a/lib/ecto_ranked/utils.ex b/lib/ecto_ranked/utils.ex index f0b1d1b..9baf957 100644 --- a/lib/ecto_ranked/utils.ex +++ b/lib/ecto_ranked/utils.ex @@ -1,10 +1,10 @@ defmodule EctoRanked.Utils do @moduledoc """ - Provides utilities for EctoRanked + Provides utilities for `EctoRanked`. """ @doc """ - Returns the first integer greater or equal than the provided value + Returns the first integer greater or equal than the provided value. ## Examples diff --git a/mix.exs b/mix.exs index 3c0c29d..1bbc2ab 100644 --- a/mix.exs +++ b/mix.exs @@ -1,18 +1,21 @@ defmodule EctoRanked.Mixfile do use Mix.Project + @source_url "https://github.com/dmarkow/ecto_ranked" + @version "0.5.0" + def project do [ app: :ecto_ranked, - version: "0.5.0", + version: @version, elixir: "~> 1.4", build_embedded: Mix.env() == :prod, start_permanent: Mix.env() == :prod, elixirc_paths: elixirc_paths(Mix.env()), - docs: [main: "readme", extras: ["README.md"]], aliases: aliases(), package: package(), - deps: deps() + deps: deps(), + docs: docs() ] end @@ -22,13 +25,10 @@ defmodule EctoRanked.Mixfile do files: ["lib", "mix.exs", "README*"], maintainers: ["Dylan Markow"], licenses: ["MIT"], - links: %{github: "https://github.com/dmarkow/ecto_ranked"} + links: %{GitHub: @source_url} ] end - # Configuration for the OTP application - # - # Type "mix help compile.app" for more information def application do # Specify extra applications you'll use from Erlang/Elixir [extra_applications: [:logger]] @@ -41,20 +41,25 @@ defmodule EctoRanked.Mixfile do [test: ["ecto.create --quiet", "ecto.migrate", "test"]] end - # Dependencies can be Hex packages: - # - # {:my_dep, "~> 0.3.0"} - # - # Or git/path repositories: - # - # {:my_dep, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} - # - # Type "mix help deps" for more examples and options defp deps do [ {:ecto_sql, "~> 3.0"}, {:postgrex, "~> 0.14", only: :test}, - {:ex_doc, "~> 0.15", only: :dev, runtime: false} + {:ex_doc, ">= 0.0.0", only: :dev, runtime: false} + ] + end + + defp docs do + [ + extras: [ + "CODE_OF_CONDUCT.md": [title: "Code of Conduct"], + "LICENSE.md": [title: "License"], + "README.md": [title: "Overview"] + ], + main: "readme", + source_url: @source_url, + source_ref: "v#{@version}", + formatters: ["html"] ] end end diff --git a/mix.lock b/mix.lock index 33147c0..02431ba 100644 --- a/mix.lock +++ b/mix.lock @@ -3,14 +3,14 @@ "db_connection": {:hex, :db_connection, "2.4.0", "d04b1b73795dae60cead94189f1b8a51cc9e1f911c234cc23074017c43c031e5", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ad416c21ad9f61b3103d254a71b63696ecadb6a917b36f563921e0de00d7d7c8"}, "decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"}, "earmark": {:hex, :earmark, "1.3.1", "73812f447f7a42358d3ba79283cfa3075a7580a3a2ed457616d6517ac3738cb9", [:mix], [], "hexpm", "000aaeff08919e95e7aea13e4af7b2b9734577b3e6a7c50ee31ee88cab6ec4fb"}, - "earmark_parser": {:hex, :earmark_parser, "1.4.13", "0c98163e7d04a15feb62000e1a891489feb29f3d10cb57d4f845c405852bbef8", [:mix], [], "hexpm", "d602c26af3a0af43d2f2645613f65841657ad6efc9f0e361c3b6c06b578214ba"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.17", "6f3c7e94170377ba45241d394389e800fb15adc5de51d0a3cd52ae766aafd63f", [:mix], [], "hexpm", "f93ac89c9feca61c165b264b5837bf82344d13bebc634cd575cb711e2e342023"}, "ecto": {:hex, :ecto, "3.6.2", "efdf52acfc4ce29249bab5417415bd50abd62db7b0603b8bab0d7b996548c2bc", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "efad6dfb04e6f986b8a3047822b0f826d9affe8e4ebdd2aeedbfcb14fd48884e"}, "ecto_sql": {:hex, :ecto_sql, "3.6.2", "9526b5f691701a5181427634c30655ac33d11e17e4069eff3ae1176c764e0ba3", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.6.2", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.4.0 or ~> 0.5.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "5ec9d7e6f742ea39b63aceaea9ac1d1773d574ea40df5a53ef8afbd9242fdb6b"}, - "ex_doc": {:hex, :ex_doc, "0.24.2", "e4c26603830c1a2286dae45f4412a4d1980e1e89dc779fcd0181ed1d5a05c8d9", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "e134e1d9e821b8d9e4244687fb2ace58d479b67b282de5158333b0d57c6fb7da"}, + "ex_doc": {:hex, :ex_doc, "0.25.5", "ac3c5425a80b4b7c4dfecdf51fa9c23a44877124dd8ca34ee45ff608b1c6deb9", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "688cfa538cdc146bc4291607764a7f1fcfa4cce8009ecd62de03b27197528350"}, "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.15.2", "dc72dfe17eb240552857465cc00cce390960d9a0c055c4ccd38b70629227e97c", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "fd23ae48d09b32eff49d4ced2b43c9f086d402ee4fd4fcb2d7fad97fa8823e75"}, "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, - "nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.2.0", "b44d75e2a6542dcb6acf5d71c32c74ca88960421b6874777f79153bbbbd7dccc", [:mix], [], "hexpm", "52b2871a7515a5ac49b00f214e4165a40724cf99798d8e4a65e4fd64ebd002c1"}, "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"}, "postgrex": {:hex, :postgrex, "0.15.9", "46f8fe6f25711aeb861c4d0ae09780facfdf3adbd2fb5594ead61504dd489bda", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "610719103e4cb2223d4ab78f9f0f3e720320eeca6011415ab4137ddef730adee"}, "telemetry": {:hex, :telemetry, "0.4.3", "a06428a514bdbc63293cd9a6263aad00ddeb66f608163bdec7c8995784080818", [:rebar3], [], "hexpm", "eb72b8365ffda5bed68a620d1da88525e326cb82a75ee61354fc24b844768041"},