Functions are a series of transformations on the connection. A connection will have some convenience areas for a problem domain (initially, web servers), and a dictionary for user data. There will also be an API for conveniently transforming the connection.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule App do | |
use Plug | |
# I use power_strip as a collection of plugs... could use stack | |
# I use spark to actually fire a connection | |
# alternatives source, | |
use Authentication.Appliance | |
power_strip Request #defaults to :request |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Plug | |
## Plugs are wrappers around functions | |
```elixir | |
defmodule HelloWorld | |
use Plug | |
plug :hello | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def recv(%{"type" => "start", "room" => room_name, "email" => email}, conn, s) do | |
# ... | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
receive :start, %{room: room_name, email: email} do | |
# ... | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Chat.Mixfile do | |
defp deps do | |
[{:excoveralls, only: :test}] | |
end | |
defp test(args) do | |
... | |
Mix.Task.run("test") | |
Mix.shell.info("") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setup do | |
# universal setup | |
end | |
test "a get" do | |
... | |
end | |
test "logged in get" do | |
login_user |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test "chat" do | |
chat = Chat.create(...) | |
assert chat != nil | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test "chat" do | |
bucket = create_bucket | |
assert %{__struct__: "Bucket"} = bucket | |
assert Bucket.empty?(bucket) | |
Bucket.add(bucket, 1) | |
assert bucket.contents == [1] | |
end | |
# instead |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* caller must hold instance lock */ | |
static int reset_hardware(...) {...} | |
static_int_in2000_bus_reset(...) { | |
... | |
reset_hardware( … ); | |
... | |
} | |
OlderNewer