initial commit
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
# Used by "mix format"
|
||||
[
|
||||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
|
||||
]
|
||||
@@ -0,0 +1,27 @@
|
||||
# The directory Mix will write compiled artifacts to.
|
||||
/_build/
|
||||
|
||||
# If you run "mix test --cover", coverage assets end up here.
|
||||
/cover/
|
||||
|
||||
# The directory Mix downloads your dependencies sources to.
|
||||
/deps/
|
||||
|
||||
# Where third-party dependencies like ExDoc output generated docs.
|
||||
/doc/
|
||||
|
||||
# Ignore .fetch files in case you like to edit your project deps locally.
|
||||
/.fetch
|
||||
|
||||
# If the VM crashes, it generates a dump, let's ignore it too.
|
||||
erl_crash.dump
|
||||
|
||||
# Also ignore archive artifacts (built via "mix archive.build").
|
||||
*.ez
|
||||
|
||||
# Ignore package tarball (built via "mix hex.build").
|
||||
bwc-*.tar
|
||||
|
||||
|
||||
# Temporary files for e.g. tests
|
||||
/tmp
|
||||
@@ -0,0 +1,21 @@
|
||||
# Bwc
|
||||
|
||||
**TODO: Add description**
|
||||
|
||||
## Installation
|
||||
|
||||
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
|
||||
by adding `bwc` to your list of dependencies in `mix.exs`:
|
||||
|
||||
```elixir
|
||||
def deps do
|
||||
[
|
||||
{:bwc, "~> 0.1.0"}
|
||||
]
|
||||
end
|
||||
```
|
||||
|
||||
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
|
||||
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
|
||||
be found at [https://hexdocs.pm/bwc](https://hexdocs.pm/bwc).
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
defmodule Bwc do
|
||||
@moduledoc """
|
||||
The core module for the Blank White Cards game.
|
||||
"""
|
||||
|
||||
alias Bwc.{Repo, Card}
|
||||
|
||||
@repo Repo
|
||||
|
||||
@doc """
|
||||
List all cards.
|
||||
"""
|
||||
def list_cards, do: @repo.all(Card)
|
||||
|
||||
def get_card(id), do: @repo.get!(Card, id)
|
||||
|
||||
def get_card_by(attrs), do: @repo.get_by(Card, attrs)
|
||||
|
||||
def create_card(attrs), do: Card.changeset(%Card{},attrs) |> @repo.insert()
|
||||
|
||||
def new_card, do: Card.changeset(%Card{})
|
||||
|
||||
def size, do: Bwc.list_cards |> length
|
||||
|
||||
def draw_card, do: Bwc.list_cards |> Enum.random
|
||||
def draw, do: draw_card()
|
||||
|
||||
def delete_card(%Bwc.Card{} = card), do: @repo.delete(card)
|
||||
def delete_card!(%Bwc.Card{} = card), do: @repo.delete!(card)
|
||||
|
||||
def update_card(%Bwc.Card{} = card, updates) do
|
||||
card
|
||||
|> Card.changeset(updates)
|
||||
|> @repo.update
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,20 @@
|
||||
defmodule Bwc do
|
||||
@moduledoc """
|
||||
The core module for the Blank White Cards game.
|
||||
"""
|
||||
|
||||
alias Bwc.{TestRepo, Card}
|
||||
|
||||
@repo TestRepo
|
||||
|
||||
@doc """
|
||||
List all cards.
|
||||
"""
|
||||
def list_cards, do: @repo.all(Card)
|
||||
|
||||
def get_card(id), do: @repo.get!(Card, id)
|
||||
|
||||
def get_card_by(attrs), do: @repo.get_by(Card, attrs)
|
||||
|
||||
|
||||
end
|
||||
@@ -0,0 +1,21 @@
|
||||
defmodule Bwc.Application do
|
||||
# See https://hexdocs.pm/elixir/Application.html
|
||||
# for more information on OTP Applications
|
||||
@moduledoc false
|
||||
|
||||
use Application
|
||||
|
||||
@impl true
|
||||
def start(_type, _args) do
|
||||
children = [
|
||||
# Starts a worker by calling: Bwc.Worker.start_link(arg)
|
||||
# {Bwc.Worker, arg}
|
||||
{Bwc.Repo, []}
|
||||
]
|
||||
|
||||
# See https://hexdocs.pm/elixir/Supervisor.html
|
||||
# for other strategies and supported options
|
||||
opts = [strategy: :one_for_one, name: Bwc.Supervisor]
|
||||
Supervisor.start_link(children, opts)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,21 @@
|
||||
defmodule Bwc.Application do
|
||||
# See https://hexdocs.pm/elixir/Application.html
|
||||
# for more information on OTP Applications
|
||||
@moduledoc false
|
||||
|
||||
use Application
|
||||
|
||||
@impl true
|
||||
def start(_type, _args) do
|
||||
children = [
|
||||
# Starts a worker by calling: Bwc.Worker.start_link(arg)
|
||||
# {Bwc.Worker, arg}
|
||||
{Phoenix.PubSub, name: BwcWeb.PubSub}
|
||||
]
|
||||
|
||||
# See https://hexdocs.pm/elixir/Supervisor.html
|
||||
# for other strategies and supported options
|
||||
opts = [strategy: :one_for_one, name: Bwc.Supervisor]
|
||||
Supervisor.start_link(children, opts)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,26 @@
|
||||
defmodule Bwc.Card do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "cards" do
|
||||
field :title, :string
|
||||
field :description, :string
|
||||
field :picture, :string
|
||||
field :played, :boolean
|
||||
timestamps()
|
||||
end
|
||||
|
||||
def delete(%Bwc.Card{} = card), do: Bwc.delete_card(card)
|
||||
|
||||
def changeset(card, attrs \\ %{}) do
|
||||
card
|
||||
|> cast(attrs, [:title, :picture, :description, :played])
|
||||
|> validate_required(:title)
|
||||
|> validate_length(:title, min: 3)
|
||||
end
|
||||
|
||||
def format_description(card) do
|
||||
card.description
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
defmodule Bwc.Card do
|
||||
defstruct [:id, :title, :picture, :description]
|
||||
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
defmodule Bwc.Repo do
|
||||
use Ecto.Repo,
|
||||
otp_app: :bwc,
|
||||
adapter: Ecto.Adapters.Postgres
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
defmodule Auction.Repo do
|
||||
use Ecto.Repo,
|
||||
otp_app: :bwc,
|
||||
adapter: Ecto.Adapters.Postgres
|
||||
end
|
||||
@@ -0,0 +1,23 @@
|
||||
defmodule Bwc.TestRepo do
|
||||
alias Bwc.Card
|
||||
|
||||
@cards [
|
||||
%Card{id: 0, title: "Baby's First Card", picture: "0.jpg", description: "This card does nothing."},
|
||||
%Card{id: 0, title: "YUGE", picture: "1.jpg", description: ""},
|
||||
%Card{id: 0, title: "Test Card", picture: "2.jpg", description: "Angelica approves."}
|
||||
]
|
||||
|
||||
def all(Card), do: @cards
|
||||
|
||||
def get!(Card, id), do: Enum.find(@cards,fn(card) -> card.id == id end)
|
||||
|
||||
def get_by(Card, attrs) do
|
||||
Enum.find(@cards, fn(card) ->
|
||||
|
||||
Enum.all?(Map.keys(attrs), fn(key) ->
|
||||
Map.get(card,key) == attrs[key]
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
defmodule Bwc.TestRepo do
|
||||
alias Bwc.Card
|
||||
|
||||
@cards = [
|
||||
%Card{id: 0, title: "Baby's First Card", picture: "0.jpg", description: "This card does nothing."},
|
||||
%Card{id: 0, title: "YUGE", picture: "1.jpg", description: ""},
|
||||
%Card{id: 0, title: "Test Card", picture: "2.jpg", description: "Angelica approves."}
|
||||
]
|
||||
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
defmodule Bwc.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
[
|
||||
app: :bwc,
|
||||
version: "0.1.0",
|
||||
build_path: "../../_build",
|
||||
config_path: "../../config/config.exs",
|
||||
deps_path: "../../deps",
|
||||
lockfile: "../../mix.lock",
|
||||
elixir: "~> 1.11",
|
||||
start_permanent: Mix.env() == :prod,
|
||||
deps: deps()
|
||||
]
|
||||
end
|
||||
|
||||
# Run "mix help compile.app" to learn about applications.
|
||||
def application do
|
||||
[
|
||||
extra_applications: [:logger],
|
||||
mod: {Bwc.Application, []}
|
||||
]
|
||||
end
|
||||
|
||||
# Run "mix help deps" to learn about dependencies.
|
||||
defp deps do
|
||||
[
|
||||
# {:dep_from_hexpm, "~> 0.3.0"},
|
||||
{:ecto_sql, "~> 3.5.3"},
|
||||
{:postgrex, "~> 0.15.7"}
|
||||
]
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
defmodule Bwc.MixProject do
|
||||
use Mix.Project
|
||||
|
||||
def project do
|
||||
[
|
||||
app: :bwc,
|
||||
version: "0.1.0",
|
||||
build_path: "../../_build",
|
||||
config_path: "../../config/config.exs",
|
||||
deps_path: "../../deps",
|
||||
lockfile: "../../mix.lock",
|
||||
elixir: "~> 1.11",
|
||||
start_permanent: Mix.env() == :prod,
|
||||
deps: deps()
|
||||
]
|
||||
end
|
||||
|
||||
# Run "mix help compile.app" to learn about applications.
|
||||
def application do
|
||||
[
|
||||
extra_applications: [:logger],
|
||||
mod: {Bwc.Application, []}
|
||||
]
|
||||
end
|
||||
|
||||
# Run "mix help deps" to learn about dependencies.
|
||||
defp deps do
|
||||
[
|
||||
# {:dep_from_hexpm, "~> 0.3.0"},
|
||||
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"},
|
||||
# {:sibling_app_in_umbrella, in_umbrella: true}
|
||||
]
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
defmodule Bwc.Repo.Migrations.CreateCards do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table("cards") do
|
||||
add :title, :string
|
||||
add :picture, :string
|
||||
add :description, :string
|
||||
timestamps()
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
defmodule Bwc.Repo.Migrations.CreateCards do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
defmodule Bwc.Repo.Migrations.AddPlayed do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table("cards") do
|
||||
add :played, :boolean, default: false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
defmodule BwcTest do
|
||||
use ExUnit.Case
|
||||
doctest Bwc
|
||||
|
||||
test "greets the world" do
|
||||
assert Bwc.hello() == :world
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1 @@
|
||||
ExUnit.start()
|
||||
Reference in New Issue
Block a user