Skip to content

Instantly share code, notes, and snippets.

defmodule Monitoring.Decorator do
@moduledoc """
`Decorator` functions for doing monitoring.
"""
use Decorator.Define, [measure: 0, measure: 1]
alias Monitoring.Statix
require Logger
@cjbell
cjbell / plugs.ex
Last active March 9, 2018 23:08
Authorization Plugs
# Usage in a controller
plug :load_and_authorize, [
params: "account_id",
loader: &Accounts.get_account/1,
policy: AccountPolicy,
assign: :account
] when action in [:index]
# The plugs themselves

Keybase proof

I hereby claim:

  • I am cjbell on github.
  • I am cjbell (https://keybase.io/cjbell) on keybase.
  • I have a public key ASByIAdUbSnPWd2v7tOLX7dqM8v6XCcQxGY3Hfb5wTcL7Ao

To claim this, I am signing this object:

defmodule MyApp.PostController do
use MyApp.Web, :controller
import MyApp.Controllers.Helpers # this will bring in all of the helper methods into this controller
end
defmodule MyApp.Web do
# ... Other lines removed for brevity
def controller do
quote do
use Phoenix.Controller
alias MyApp.Repo
import Ecto.Model
import Ecto.Query, only: [from: 2]
defmodule MyApp.Controllers.Helpers do
import Plug.Conn
import Phoenix.Controller
def render_blank(conn) do
conn
|> send_resp(204, "")
end
def render_error(conn, status, opts) do
defmodule Shop.Order do
use Shop.Web, :model
schema "orders" do
field :email, :string
has_one :address, Shop.Address
timestamps
end
<div class="article-43afx flex-3aS32 vertical-2asd4 centered-1xa1d">
</div>
<% styles = import_css("components/article") %>
<div class="<%= styles[:article] %>">
<!-- ... more -->
</div>
import articleStyles from '../../styles/components/article';
class Article extends Component {
render() {
return (
<div className={articleStyles.article}>
// ... more
</div>
);
}