hexsha
stringlengths 40
40
| size
int64 2
991k
| ext
stringclasses 2
values | lang
stringclasses 1
value | max_stars_repo_path
stringlengths 4
208
| max_stars_repo_name
stringlengths 6
106
| max_stars_repo_head_hexsha
stringlengths 40
40
| max_stars_repo_licenses
sequence | max_stars_count
int64 1
33.5k
⌀ | max_stars_repo_stars_event_min_datetime
stringlengths 24
24
⌀ | max_stars_repo_stars_event_max_datetime
stringlengths 24
24
⌀ | max_issues_repo_path
stringlengths 4
208
| max_issues_repo_name
stringlengths 6
106
| max_issues_repo_head_hexsha
stringlengths 40
40
| max_issues_repo_licenses
sequence | max_issues_count
int64 1
16.3k
⌀ | max_issues_repo_issues_event_min_datetime
stringlengths 24
24
⌀ | max_issues_repo_issues_event_max_datetime
stringlengths 24
24
⌀ | max_forks_repo_path
stringlengths 4
208
| max_forks_repo_name
stringlengths 6
106
| max_forks_repo_head_hexsha
stringlengths 40
40
| max_forks_repo_licenses
sequence | max_forks_count
int64 1
6.91k
⌀ | max_forks_repo_forks_event_min_datetime
stringlengths 24
24
⌀ | max_forks_repo_forks_event_max_datetime
stringlengths 24
24
⌀ | content
stringlengths 2
991k
| avg_line_length
float64 1
36k
| max_line_length
int64 1
977k
| alphanum_fraction
float64 0
1
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
f716f2355663f7f32f509ca76e0b250e76a8b848 | 2,111 | ex | Elixir | unsilo/lib/unsilo_web/controllers/story_controller.ex | TehSnappy/unsilo_elixir | d0dd592dee71ed5b994ac08cd347aa357d5845f4 | [
"MIT"
] | 1 | 2019-03-21T02:43:06.000Z | 2019-03-21T02:43:06.000Z | unsilo/lib/unsilo_web/controllers/story_controller.ex | TehSnappy/unsilo_elixir | d0dd592dee71ed5b994ac08cd347aa357d5845f4 | [
"MIT"
] | 3 | 2021-03-09T01:43:16.000Z | 2022-02-10T17:04:55.000Z | unsilo/lib/unsilo_web/controllers/story_controller.ex | TehSnappy/unsilo_elixir | d0dd592dee71ed5b994ac08cd347aa357d5845f4 | [
"MIT"
] | null | null | null | defmodule UnsiloWeb.StoryController do
use UnsiloWeb, :controller
require Logger
alias Unsilo.Feeds
alias Unsilo.Feeds.Story
alias Plug.Conn
plug :assign_sub_title
plug :load_and_authorize_resource,
model: Story,
preload: :archive,
only: [:index, :update, :delete]
action_fallback UnsiloWeb.FallbackController
use UnsiloWeb.AssignableController, assignable: :story
def assign_sub_title(conn, _) do
conn
|> Conn.assign(:page_sub_title, "rivers")
|> Conn.assign(:page_sub_title_url, Routes.river_path(conn, :index))
|> Conn.assign(:new_item_url, Routes.river_path(conn, :new))
end
def index(conn, %{"mode" => story_mode}, user) do
stories = Feeds.list_stories(story_mode, user)
render(conn, "index.html", stories: stories, user: user, story_mode: story_mode)
end
def update(conn, %{"cmd" => story_cmd}, _user, story) do
case story_cmd do
"mark_read" ->
story
|> Feeds.update_story(%{read_at: DateTime.utc_now(), deleted_at: nil})
|> case do
{:ok, _story} ->
render_success(conn, "empty.html", [])
{:error, %Ecto.Changeset{} = _changeset} ->
render_error(conn, "empty.html", [])
end
"mark_delete" ->
story
|> Feeds.update_story(%{deleted_at: DateTime.utc_now(), read_at: nil, archived_at: nil})
|> case do
{:ok, _story} ->
render_success(conn, "empty.html", [])
{:error, %Ecto.Changeset{} = _changeset} ->
render_error(conn, "empty.html", [])
end
"mark_archive" ->
story
|> Feeds.create_archive()
|> Feeds.update_story(%{archived_at: DateTime.utc_now()})
|> case do
{:ok, _story} ->
render_success(conn, "empty.html", [])
{:error, %Ecto.Changeset{} = _changeset} ->
render_error(conn, "empty.html", [])
end
unknown_command ->
Logger.error("unknown command in StoryController - #{unknown_command}")
render_error(conn, "empty.html", [])
end
end
end
| 27.776316 | 96 | 0.604453 |
f716f7b96371a06cbc5bb727d5d7ab50dd0188f2 | 359 | ex | Elixir | lib/blog_web/views/page_view.ex | mmmries/blog | b65bc86575145b6dc97e344bb55527bf7b0303fa | [
"MIT"
] | null | null | null | lib/blog_web/views/page_view.ex | mmmries/blog | b65bc86575145b6dc97e344bb55527bf7b0303fa | [
"MIT"
] | 11 | 2015-09-10T02:03:49.000Z | 2021-11-25T11:38:59.000Z | lib/blog_web/views/page_view.ex | mmmries/blog | b65bc86575145b6dc97e344bb55527bf7b0303fa | [
"MIT"
] | null | null | null | defmodule BlogWeb.PageView do
use BlogWeb, :view
def post_link(post, content \\ nil) do
post_url = "/" <> (Date.to_iso8601(post.date) |> String.replace("-", "/")) <> "/#{post.slug}.html"
if content == nil do
link(post.title, to: post_url, class: "post-link")
else
link(content, to: post_url, class: "post-link")
end
end
end
| 27.615385 | 102 | 0.612813 |
f716ffe38329728ef6a868a46246a7897e35265a | 1,459 | ex | Elixir | lib/loom_web/endpoint.ex | simonfraserduncan/my-copy | 03c618035a06a63d8fcf9f6511ef59d3e4cf2da9 | [
"Apache-2.0"
] | 4 | 2021-02-20T02:47:36.000Z | 2021-06-08T18:42:40.000Z | lib/loom_web/endpoint.ex | DataStax-Examples/astra-loom | 767c55200d08a6c592773d7af7da95873c4c3445 | [
"Apache-2.0"
] | null | null | null | lib/loom_web/endpoint.ex | DataStax-Examples/astra-loom | 767c55200d08a6c592773d7af7da95873c4c3445 | [
"Apache-2.0"
] | 1 | 2021-02-17T18:28:35.000Z | 2021-02-17T18:28:35.000Z | defmodule LoomWeb.Endpoint do
use Phoenix.Endpoint, otp_app: :loom
@session_options [
store: :cookie,
key: "_loom_key",
signing_salt: "1h1IY2+/"
]
socket "/live", Phoenix.LiveView.Socket,
websocket: [connect_info: [session: @session_options]]
# Serve at "/" the static files from "priv/static" directory.
#
# You should set gzip to true if you are running phx.digest
# when deploying your static files in production.
plug Plug.Static,
at: "/",
from: :loom,
gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt)
# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
if code_reloading? do
socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket
plug Phoenix.LiveReloader
plug Phoenix.CodeReloader
end
plug Phoenix.LiveDashboard.RequestLogger,
param_key: "request_logger",
cookie_key: "request_logger"
plug Plug.RequestId
plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint]
plug Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
pass: ["*/*"],
json_decoder: Phoenix.json_library()
plug Plug.MethodOverride
plug Plug.Head
# The session will be stored in the cookie and signed,
# this means its contents can be read but not tampered with.
# Set :encryption_salt if you would also like to encrypt it.
plug Plug.Session, @session_options
plug LoomWeb.Router
end
| 27.528302 | 69 | 0.711446 |
f717099b14189e1d9bcc76024719acb4d1e64057 | 6,971 | ex | Elixir | lib/remote_ip.ex | inside-track/remote_ip | fbced21bc698c06fd2307a1a031ec5d9909d605c | [
"MIT"
] | null | null | null | lib/remote_ip.ex | inside-track/remote_ip | fbced21bc698c06fd2307a1a031ec5d9909d605c | [
"MIT"
] | null | null | null | lib/remote_ip.ex | inside-track/remote_ip | fbced21bc698c06fd2307a1a031ec5d9909d605c | [
"MIT"
] | null | null | null | defmodule RemoteIp do
@moduledoc """
A plug to overwrite the `Plug.Conn`'s `remote_ip` based on request headers.
To use, add the `RemoteIp` plug to your app's plug pipeline:
```elixir
defmodule MyApp do
use Plug.Builder
plug RemoteIp
end
```
Keep in mind the order of plugs in your pipeline and place `RemoteIp` as
early as possible. For example, if you were to add `RemoteIp` *after* [the
Plug Router](https://github.com/elixir-lang/plug#the-plug-router), your route
action's logic would be executed *before* the `remote_ip` actually gets
modified - not very useful!
There are 3 options that can be passed in:
* `:headers` - A list of strings naming the `req_headers` to use when
deriving the `remote_ip`. Order does not matter. Defaults to `~w[forwarded
x-forwarded-for x-client-ip x-real-ip]`.
* `:proxies` - A list of strings in
[CIDR](https://en.wikipedia.org/wiki/CIDR) notation specifying the IPs of
known proxies. Defaults to `[]`.
[Loopback](https://en.wikipedia.org/wiki/Loopback) and
[private](https://en.wikipedia.org/wiki/Private_network) IPs are always
appended to this list:
* 127.0.0.0/8
* ::1/128
* fc00::/7
* 10.0.0.0/8
* 172.16.0.0/12
* 192.168.0.0/16
Since these IPs are internal, they often are not the actual client
address in production, so we add them by default. To override this
behavior, whitelist known client IPs using the `:clients` option.
* `:clients` - A list of strings in
[CIDR](https://en.wikipedia.org/wiki/CIDR) notation specifying the IPs of
known clients. Defaults to `[]`.
An IP in any of the ranges listed here will never be considered a proxy.
This takes precedence over the `:proxies` option, including
loopback/private addresses. Any IP that is **not** covered by `:clients`
or `:proxies` is assumed to be a client IP.
For example, suppose you know:
* you are behind proxies in the 1.2.x.x block
* the proxies use the `X-Foo`, `X-Bar`, and `X-Baz` headers
* but the IP 1.2.3.4 is actually a client, not one of the proxies
Then you could say
```elixir
defmodule MyApp do
use Plug.Builder
plug RemoteIp,
headers: ~w[x-foo x-bar x-baz],
proxies: ~w[1.2.0.0/16],
clients: ~w[1.2.3.4/32]
end
```
Note that, due to limitations in the
[inet_cidr](https://github.com/Cobenian/inet_cidr) library used to parse
them, `:proxies` and `:clients` **must** be written in full CIDR notation,
even if specifying just a single IP. So instead of `"127.0.0.1"` and
`"a:b::c:d"`, you would use `"127.0.0.1/32"` and `"a:b::c:d/128"`.
For more details, refer to the
[README](https://github.com/ajvondrak/remote_ip/blob/master/README.md) on
GitHub.
"""
require Logger
@behaviour Plug
@headers ~w[
forwarded
x-forwarded-for
x-client-ip
x-real-ip
]
@debug
@proxies []
@clients []
# https://en.wikipedia.org/wiki/Loopback
# https://en.wikipedia.org/wiki/Private_network
@reserved ~w[
127.0.0.0/8
::1/128
fc00::/7
10.0.0.0/8
172.16.0.0/12
192.168.0.0/16
]
def init(opts \\ []) do
headers = Keyword.get(opts, :headers, @headers)
headers = MapSet.new(headers)
proxies = Keyword.get(opts, :proxies, @proxies) ++ @reserved
proxies = proxies |> Enum.map(&InetCidr.parse/1)
clients = Keyword.get(opts, :clients, @clients)
clients = clients |> Enum.map(&InetCidr.parse/1)
%RemoteIp.Config{headers: headers, proxies: proxies, clients: clients}
end
def call(conn, %RemoteIp.Config{} = config) do
case last_forwarded_ip(conn.req_headers, config) do
nil -> conn
ip -> %{conn | remote_ip: ip}
end
end
@doc """
Standalone function to extract the remote IP from a list of headers.
It's possible to get a subset of headers without access to a full `Plug.Conn`
struct. For instance, when [using Phoenix
sockets](https://hexdocs.pm/phoenix/Phoenix.Endpoint.html), your socket's
`connect/3` callback may only be receiving `:x_headers` in the
`connect_info`. Such situations make it inconvenient to use `RemoteIp`
outside of a plug pipeline.
Therefore, this function will fetch the remote IP from a plain list of header
key-value pairs (just as you'd have in the `req_headers` of a `Plug.Conn`).
You may optionally specify the same options as if you were using `RemoteIp`
as a plug: they'll be processed by `RemoteIp.init/1` each time you call this
function.
If a remote IP cannot be parsed from the given headers (e.g., if the list is
empty), this function will return `nil`.
## Examples
iex> RemoteIp.from([{"x-forwarded-for", "1.2.3.4"}])
{1, 2, 3, 4}
iex> [{"x-foo", "1.2.3.4"}, {"x-bar", "2.3.4.5"}]
...> |> RemoteIp.from(headers: ~w[x-foo])
{1, 2, 3, 4}
iex> [{"x-foo", "1.2.3.4"}, {"x-bar", "2.3.4.5"}]
...> |> RemoteIp.from(headers: ~w[x-bar])
{2, 3, 4, 5}
iex> [{"x-foo", "1.2.3.4"}, {"x-bar", "2.3.4.5"}]
...> |> RemoteIp.from(headers: ~w[x-baz])
nil
"""
@spec from([{String.t, String.t}], keyword) :: :inet.ip_address | nil
def from(req_headers, opts \\ []) do
last_forwarded_ip(req_headers, init(opts))
end
def debug(true, any) do
Logger.debug(any)
end
def debug(false, _any), do: :ok
defp last_forwarded_ip(req_headers, config) do
debug(false, fn -> start(config) end)
ip = req_headers |> ips_given(config) |> most_recent_client_given(config)
debug(false, fn -> stop(ip) end)
ip
end
defp ips_given(req_headers, %RemoteIp.Config{headers: headers}) do
RemoteIp.Headers.parse(req_headers, headers)
end
defp most_recent_client_given(ips, config) do
Enum.reverse(ips) |> Enum.find(&client?(&1, config))
end
defp client?(ip, %RemoteIp.Config{clients: clients, proxies: proxies}) do
cond do
clients |> contains?(ip) ->
debug(false, fn -> known_client(ip) end)
true
proxies |> contains?(ip) ->
debug(false, fn -> known_proxy(ip) end)
false
true ->
debug(false, fn -> presumably_client(ip) end)
true
end
end
defp contains?(cidrs, ip) do
Enum.any?(cidrs, &InetCidr.contains?(&1, ip))
end
defp start(config) do
[inspect(__MODULE__), " is configured with ", inspect(config, pretty: true)]
end
defp stop(ip) do
if ip do
[inspect(__MODULE__), " determined the remote IP is ", inspect(ip)]
else
[inspect(__MODULE__), " could not determine the remote IP"]
end
end
defp known_client(ip) do
[inspect(__MODULE__), " thinks ", inspect(ip), " is a known client IP"]
end
defp known_proxy(ip) do
[inspect(__MODULE__), " thinks ", inspect(ip), " is a known proxy IP"]
end
defp presumably_client(ip) do
[inspect(__MODULE__), " assumes ", inspect(ip), " is a client IP"]
end
end
| 29.045833 | 80 | 0.643954 |
f71712780fe4fb66b5c213dbbc6e1badad42023e | 2,589 | ex | Elixir | lib/rdf/blank_node/generator.ex | rdf-elixir/rdf-ex | 7d4280ec9a912ef6ee9fc96ecdfdf26647016d6a | [
"MIT"
] | 19 | 2020-06-05T16:55:54.000Z | 2022-03-22T10:30:11.000Z | lib/rdf/blank_node/generator.ex | rdf-elixir/rdf-ex | 7d4280ec9a912ef6ee9fc96ecdfdf26647016d6a | [
"MIT"
] | 4 | 2020-07-03T21:02:55.000Z | 2021-11-18T07:22:06.000Z | lib/rdf/blank_node/generator.ex | rdf-elixir/rdf-ex | 7d4280ec9a912ef6ee9fc96ecdfdf26647016d6a | [
"MIT"
] | 3 | 2020-07-03T13:25:36.000Z | 2021-04-04T12:33:51.000Z | defmodule RDF.BlankNode.Generator do
@moduledoc """
A GenServer generates `RDF.BlankNode`s using a `RDF.BlankNode.Generator.Algorithm`.
"""
use GenServer
# Client API ###############################################################
@doc """
Starts a blank node generator linked to the current process.
The state will be initialized according to the given `RDF.BlankNode.Generator.Algorithm`.
"""
def start_link(generation_mod, init_opts \\ %{}) do
GenServer.start_link(__MODULE__, {generation_mod, convert_opts(init_opts)})
end
@doc """
Starts a blank node generator process without links (outside of a supervision tree).
The state will be initialized according to the given `RDF.BlankNode.Generator.Algorithm`.
"""
def start(generation_mod, init_opts \\ %{}) do
GenServer.start(__MODULE__, {generation_mod, convert_opts(init_opts)})
end
defp convert_opts(nil), do: %{}
defp convert_opts(opts) when is_list(opts), do: Map.new(opts)
defp convert_opts(opts) when is_map(opts), do: opts
@doc """
Synchronously stops the blank node generator with the given `reason`.
It returns `:ok` if the agent terminates with the given reason. If the agent
terminates with another reason, the call will exit.
This function keeps OTP semantics regarding error reporting.
If the reason is any other than `:normal`, `:shutdown` or `{:shutdown, _}`, an
error report will be logged.
"""
def stop(pid, reason \\ :normal, timeout \\ :infinity) do
GenServer.stop(pid, reason, timeout)
end
@doc """
Generates a new blank node according to the `RDF.BlankNode.Generator.Algorithm` set up.
"""
def generate(pid) do
GenServer.call(pid, :generate)
end
@doc """
Generates a blank node for a given value according to the `RDF.BlankNode.Generator.Algorithm` set up.
"""
def generate_for(pid, value) do
GenServer.call(pid, {:generate_for, value})
end
# Server Callbacks #########################################################
@impl GenServer
def init({generation_mod, init_opts}) do
{:ok, {generation_mod, generation_mod.init(init_opts)}}
end
@impl GenServer
def handle_call(:generate, _from, {generation_mod, state}) do
with {bnode, new_state} = generation_mod.generate(state) do
{:reply, bnode, {generation_mod, new_state}}
end
end
@impl GenServer
def handle_call({:generate_for, string}, _from, {generation_mod, state}) do
with {bnode, new_state} = generation_mod.generate_for(string, state) do
{:reply, bnode, {generation_mod, new_state}}
end
end
end
| 31.962963 | 103 | 0.678254 |
f717730abf77cd0dc93ea247e06bdb1d316f0055 | 512 | exs | Elixir | test/controllers/user_controller_test.exs | usecanvas/api-v2 | 59214db3a2cf12eb939f22fed320fd10cb47cdfe | [
"Apache-2.0"
] | 123 | 2017-04-04T18:15:48.000Z | 2021-04-26T08:04:22.000Z | test/controllers/user_controller_test.exs | usecanvas/api-v2 | 59214db3a2cf12eb939f22fed320fd10cb47cdfe | [
"Apache-2.0"
] | null | null | null | test/controllers/user_controller_test.exs | usecanvas/api-v2 | 59214db3a2cf12eb939f22fed320fd10cb47cdfe | [
"Apache-2.0"
] | 17 | 2017-04-04T18:58:29.000Z | 2021-05-10T21:39:16.000Z | defmodule CanvasAPI.UserControllerTest do
use CanvasAPI.ConnCase
import CanvasAPI.Factory
@valid_attrs %{}
@invalid_attrs %{}
setup %{conn: conn} do
{:ok, conn: put_req_header(conn, "accept", "application/json")}
end
test "shows chosen resource", %{conn: conn} do
user = insert(:user)
conn =
conn
|> put_private(:current_account, user.account)
|> get(team_user_path(conn, :show, user.team))
assert json_response(conn, 200)["data"]["id"] == user.id
end
end
| 21.333333 | 67 | 0.65625 |
f7178fb183c6973bfd433192d892259a3b4fc6e5 | 2,249 | ex | Elixir | clients/service_networking/lib/google_api/service_networking/v1/model/add_dns_record_set_request.ex | MasashiYokota/elixir-google-api | 975dccbff395c16afcb62e7a8e411fbb58e9ab01 | [
"Apache-2.0"
] | null | null | null | clients/service_networking/lib/google_api/service_networking/v1/model/add_dns_record_set_request.ex | MasashiYokota/elixir-google-api | 975dccbff395c16afcb62e7a8e411fbb58e9ab01 | [
"Apache-2.0"
] | 1 | 2020-12-18T09:25:12.000Z | 2020-12-18T09:25:12.000Z | clients/service_networking/lib/google_api/service_networking/v1/model/add_dns_record_set_request.ex | MasashiYokota/elixir-google-api | 975dccbff395c16afcb62e7a8e411fbb58e9ab01 | [
"Apache-2.0"
] | 1 | 2020-10-04T10:12:44.000Z | 2020-10-04T10:12:44.000Z | # Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE: This file is auto generated by the elixir code generator program.
# Do not edit this file manually.
defmodule GoogleApi.ServiceNetworking.V1.Model.AddDnsRecordSetRequest do
@moduledoc """
Request to add a record set to a private managed DNS zone in the shared producer host project.
## Attributes
* `consumerNetwork` (*type:* `String.t`, *default:* `nil`) - Required. The network that the consumer is using to connect with services. Must be in the form of projects/{project}/global/networks/{network} {project} is the project number, as in '12345' {network} is the network name.
* `dnsRecordSet` (*type:* `GoogleApi.ServiceNetworking.V1.Model.DnsRecordSet.t`, *default:* `nil`) - Required. The DNS record set to add.
* `zone` (*type:* `String.t`, *default:* `nil`) - Required. The name of the private DNS zone in the shared producer host project to which the record set will be added.
"""
use GoogleApi.Gax.ModelBase
@type t :: %__MODULE__{
:consumerNetwork => String.t(),
:dnsRecordSet => GoogleApi.ServiceNetworking.V1.Model.DnsRecordSet.t(),
:zone => String.t()
}
field(:consumerNetwork)
field(:dnsRecordSet, as: GoogleApi.ServiceNetworking.V1.Model.DnsRecordSet)
field(:zone)
end
defimpl Poison.Decoder, for: GoogleApi.ServiceNetworking.V1.Model.AddDnsRecordSetRequest do
def decode(value, options) do
GoogleApi.ServiceNetworking.V1.Model.AddDnsRecordSetRequest.decode(value, options)
end
end
defimpl Poison.Encoder, for: GoogleApi.ServiceNetworking.V1.Model.AddDnsRecordSetRequest do
def encode(value, options) do
GoogleApi.Gax.ModelBase.encode(value, options)
end
end
| 42.433962 | 285 | 0.739884 |
f7179d338490c31646859de08aa045c1c6cf5f01 | 2,694 | exs | Elixir | test/changes_test.exs | point/rethinkdb-elixir | 0549902e5060e75b0942716befc16db984a14b76 | [
"MIT"
] | 530 | 2015-05-12T21:06:49.000Z | 2021-07-29T01:06:43.000Z | test/changes_test.exs | point/rethinkdb-elixir | 0549902e5060e75b0942716befc16db984a14b76 | [
"MIT"
] | 122 | 2015-05-12T03:12:50.000Z | 2019-11-11T11:21:10.000Z | test/changes_test.exs | point/rethinkdb-elixir | 0549902e5060e75b0942716befc16db984a14b76 | [
"MIT"
] | 79 | 2015-05-14T17:14:52.000Z | 2022-02-14T07:00:00.000Z | defmodule ChangesTest do
use ExUnit.Case, async: true
alias RethinkDB.Feed
use RethinkDB.Connection
import RethinkDB.Query
@table_name "changes_test_table_1"
setup_all do
start_link
table_create(@table_name) |> run
on_exit fn ->
start_link
table_drop(@table_name) |> run
end
:ok
end
setup do
table(@table_name) |> delete |> run
:ok
end
test "first change" do
q = table(@table_name) |> changes
{:ok, changes = %Feed{}} = run(q)
t = Task.async fn ->
changes |> Enum.take(1)
end
data = %{"test" => "d"}
table(@table_name) |> insert(data) |> run
[h|[]] = Task.await(t)
assert %{"new_val" => %{"test" => "d"}} = h
end
test "changes" do
q = table(@table_name) |> changes
{:ok, changes} = {:ok, %Feed{}} = run(q)
t = Task.async fn ->
RethinkDB.Connection.next(changes)
end
data = %{"test" => "data"}
q = table(@table_name) |> insert(data)
{:ok, res} = run(q)
expected = res.data["id"]
{:ok, changes} = Task.await(t)
^expected = changes.data |> hd |> Map.get("id")
# test Enumerable
t = Task.async fn ->
changes |> Enum.take(5)
end
1..6 |> Enum.each(fn _ ->
q = table(@table_name) |> insert(data)
run(q)
end)
data = Task.await(t)
5 = Enum.count(data)
end
test "point_changes" do
q = table(@table_name) |> get("0") |> changes
{:ok, changes} = {:ok, %Feed{}} = run(q)
t = Task.async fn ->
changes |> Enum.take(1)
end
data = %{"id" => "0"}
q = table(@table_name) |> insert(data)
{:ok, res} = run(q)
expected = res.data["id"]
[h|[]] = Task.await(t)
assert %{"new_val" => %{"id" => "0"}} = h
end
test "changes opts binary native" do
q = table(@table_name) |> get("0") |> changes
{:ok, changes} = {:ok, %Feed{}} = run(q)
t = Task.async fn ->
changes |> Enum.take(1)
end
data = %{"id" => "0", "binary" => binary(<<1>>)}
q = table(@table_name) |> insert(data)
{:ok, res} = run(q)
expected = res.data["id"]
[h|[]] = Task.await(t)
assert %{"new_val" => %{"id" => "0", "binary" => <<1>>}} = h
end
test "changes opts binary raw" do
q = table(@table_name) |> get("0") |> changes
{:ok, changes} = {:ok, %Feed{}} = run(q, [binary_format: :raw])
t = Task.async fn ->
changes |> Enum.take(1)
end
data = %{"id" => "0", "binary" => binary(<<1>>)}
q = table(@table_name) |> insert(data)
{:ok, res} = run(q)
expected = res.data["id"]
[h|[]] = Task.await(t)
assert %{"new_val" => %{"id" => "0", "binary" => %RethinkDB.Pseudotypes.Binary{data: "AQ=="}}} = h
end
end
| 26.15534 | 102 | 0.528211 |
f717a2b968e824a18cab2a325f74a419187704ec | 1,176 | ex | Elixir | lib/openflow/get_config/reply.ex | shun159/tres | 1e3e7f78ba1aa4f184d4be70300e5f4703d50a2f | [
"Beerware"
] | 5 | 2019-05-25T02:25:13.000Z | 2020-10-06T17:00:03.000Z | lib/openflow/get_config/reply.ex | shun159/tres | 1e3e7f78ba1aa4f184d4be70300e5f4703d50a2f | [
"Beerware"
] | 5 | 2018-03-29T14:42:10.000Z | 2019-11-19T07:03:09.000Z | lib/openflow/get_config/reply.ex | shun159/tres | 1e3e7f78ba1aa4f184d4be70300e5f4703d50a2f | [
"Beerware"
] | 1 | 2019-03-30T20:48:27.000Z | 2019-03-30T20:48:27.000Z | defmodule Openflow.GetConfig.Reply do
defstruct(
version: 4,
xid: 0,
datapath_id: "",
aux_id: 0,
# default = "normal" is no special handling
flags: [],
miss_send_len: 128
)
alias __MODULE__
@type flags :: [:drop | :reasm]
@type max_len :: :max | :no_buffer | 0..0xFFFF
@type t :: %Reply{
version: 4,
xid: 0..0xFFFFFFFF,
datapath_id: String.t() | nil,
aux_id: 0..0xF | nil,
flags: flags(),
miss_send_len: max_len()
}
@spec ofp_type() :: t()
def ofp_type, do: 8
@spec read(<<_::32>>) :: t()
def read(<<flags_int::16, miss_send_len0::16>>) do
flags = Openflow.Enums.int_to_flags(flags_int, :config_flags)
miss_send_len = Openflow.Utils.get_enum(miss_send_len0, :controller_max_len)
%Reply{flags: flags, miss_send_len: miss_send_len}
end
@spec to_binary(t()) :: <<_::32>>
def to_binary(%Reply{flags: flags, miss_send_len: miss_send_len0}) do
flags_int = Openflow.Enums.flags_to_int(flags, :config_flags)
miss_send_len = Openflow.Utils.get_enum(miss_send_len0, :controller_max_len)
<<flags_int::16, miss_send_len::16>>
end
end
| 27.348837 | 80 | 0.630952 |
f717ea1960e64b2142cc372c2e2d4d75a05f630b | 4,299 | ex | Elixir | lib/geocoder/providers/google_maps.ex | foggy1/geocoder | 80a5b8c2b43fe5b1ec4277782b33354e1c675f14 | [
"MIT"
] | null | null | null | lib/geocoder/providers/google_maps.ex | foggy1/geocoder | 80a5b8c2b43fe5b1ec4277782b33354e1c675f14 | [
"MIT"
] | null | null | null | lib/geocoder/providers/google_maps.ex | foggy1/geocoder | 80a5b8c2b43fe5b1ec4277782b33354e1c675f14 | [
"MIT"
] | null | null | null | defmodule Geocoder.Providers.GoogleMaps do
use HTTPoison.Base
use Towel
@endpoint "https://maps.googleapis.com/"
def geocode(opts) do
request("maps/api/geocode/json", extract_opts(opts))
|> fmap(&parse_geocode/1)
end
def geocode_list(opts) do
request_all("maps/api/geocode/json", extract_opts(opts))
|> fmap(fn r -> Enum.map(r, &parse_geocode/1) end)
end
def reverse_geocode(opts) do
request("maps/api/geocode/json", extract_opts(opts))
|> fmap(&parse_reverse_geocode/1)
end
def reverse_geocode_list(opts) do
request_all("maps/api/geocode/json", extract_opts(opts))
|> fmap(fn r -> Enum.map(r, &parse_reverse_geocode/1) end)
end
defp extract_opts(opts) do
opts
|> Keyword.take([
:key,
:address,
:components,
:bounds,
:language,
:region,
:latlng,
:placeid,
:result_type,
:location_type
])
|> Keyword.update(:latlng, nil, fn
{lat, lng} -> "#{lat},#{lng}"
q -> q
end)
|> Keyword.delete(:latlng)
end
defp parse_geocode(response) do
coords = geocode_coords(response)
bounds = geocode_bounds(response)
location = geocode_location(response)
%{coords | bounds: bounds, location: location}
end
defp parse_reverse_geocode(response) do
coords = geocode_coords(response)
location = geocode_location(response)
%{coords | location: location}
end
defp geocode_coords(%{"geometry" => %{"location" => coords}}) do
%{"lat" => lat, "lng" => lon} = coords
%Geocoder.Coords{lat: lat, lon: lon}
end
defp geocode_bounds(%{"geometry" => %{"bounds" => bounds}}) do
%{
"northeast" => %{"lat" => north, "lng" => east},
"southwest" => %{"lat" => south, "lng" => west}
} = bounds
%Geocoder.Bounds{top: north, right: east, bottom: south, left: west}
end
defp geocode_bounds(_), do: %Geocoder.Bounds{}
@components [
"locality",
"administrative_area_level_1",
"administrative_area_level_2",
"country",
"postal_code",
"street",
"street_number",
"route"
]
@map %{
"street_number" => :street_number,
"route" => :street,
"street_address" => :street,
"locality" => :city,
"administrative_area_level_1" => :state,
"administrative_area_level_2" => :county,
"postal_code" => :postal_code,
"country" => :country
}
defp geocode_location(%{
"address_components" => components,
"formatted_address" => formatted_address
}) do
name = &Map.get(&1, "long_name")
type = fn component ->
component |> Map.get("types") |> Enum.find(&Enum.member?(@components, &1))
end
map = &{type.(&1), name.(&1)}
reduce = fn {type, name}, location ->
struct(location, [{@map[type], name}])
end
country =
Enum.find(components, fn component ->
component |> Map.get("types") |> Enum.member?("country")
end)
country_code =
case country do
nil ->
nil
%{"short_name" => name} ->
name
end
location = %Geocoder.Location{
country_code: country_code,
formatted_address: formatted_address
}
components
|> Enum.filter(type)
|> Enum.map(map)
|> Enum.reduce(location, reduce)
end
defp request_all(path, params) do
params =
Keyword.merge(params, key: params[:key] || Application.get_env(:geocoder, :worker)[:key])
httpoison_options = Application.get_env(:geocoder, Geocoder.Worker)[:httpoison_options] || []
case get(path, [], Keyword.merge(httpoison_options, params: Enum.into(params, %{}))) do
# API does not return a non-200 code when there is an error!
{:ok,
%{
status_code: 200,
body: %{"results" => [], "error_message" => error_message, "status" => _status}
}} ->
{:error, error_message}
{:ok, %{status_code: 200, body: %{"status" => "OK", "results" => results}}} ->
{:ok, List.wrap(results)}
{_, response} ->
{:error, response}
end
end
def request(path, params) do
request_all(path, params)
|> fmap(&List.first/1)
end
def process_url(url) do
@endpoint <> url
end
def process_response_body(body) do
body |> Jason.decode!()
end
end
| 24.706897 | 97 | 0.602466 |
f7182bb91045d8188091ee2224034c2425726c19 | 7,528 | ex | Elixir | lib/eex/lib/eex.ex | spencerdcarlson/elixir | 23d75ecdf58df80969e12f4420282238e19219a1 | [
"Apache-2.0"
] | null | null | null | lib/eex/lib/eex.ex | spencerdcarlson/elixir | 23d75ecdf58df80969e12f4420282238e19219a1 | [
"Apache-2.0"
] | 1 | 2020-09-14T16:23:33.000Z | 2021-03-25T17:38:59.000Z | lib/eex/lib/eex.ex | spencerdcarlson/elixir | 23d75ecdf58df80969e12f4420282238e19219a1 | [
"Apache-2.0"
] | null | null | null | defmodule EEx.SyntaxError do
defexception [:message, :file, :line, :column]
@impl true
def message(exception) do
"#{exception.file}:#{exception.line}:#{exception.column}: #{exception.message}"
end
end
defmodule EEx do
@moduledoc ~S"""
EEx stands for Embedded Elixir. It allows you to embed
Elixir code inside a string in a robust way.
iex> EEx.eval_string("foo <%= bar %>", bar: "baz")
"foo baz"
## API
This module provides 3 main APIs for you to use:
1. Evaluate a string (`eval_string/3`) or a file (`eval_file/3`)
directly. This is the simplest API to use but also the
slowest, since the code is evaluated and not compiled before.
2. Define a function from a string (`function_from_string/5`)
or a file (`function_from_file/5`). This allows you to embed
the template as a function inside a module which will then
be compiled. This is the preferred API if you have access
to the template at compilation time.
3. Compile a string (`compile_string/2`) or a file (`compile_file/2`)
into Elixir syntax tree. This is the API used by both functions
above and is available to you if you want to provide your own
ways of handling the compiled template.
## Options
All functions in this module accept EEx-related options.
They are:
* `:file` - the file to be used in the template. Defaults to the given
file the template is read from or to "nofile" when compiling from a string.
* `:line` - the line to be used as the template start. Defaults to 1.
* `:indentation` - (since v1.11.0) an integer added to the column after every
new line. Defaults to 0.
* `:engine` - the EEx engine to be used for compilation.
* `:trim` - if true, trims whitespace left/right of quotation tags up until
newlines. At least one newline is retained. Defaults to false.
## Engine
EEx has the concept of engines which allows you to modify or
transform the code extracted from the given string or file.
By default, `EEx` uses the `EEx.SmartEngine` that provides some
conveniences on top of the simple `EEx.Engine`.
### Tags
`EEx.SmartEngine` supports the following tags:
<% Elixir expression - inline with output %>
<%= Elixir expression - replace with result %>
<%% EEx quotation - returns the contents inside %>
<%# Comments - they are discarded from source %>
All expressions that output something to the template
**must** use the equals sign (`=`). Since everything in
Elixir is an expression, there are no exceptions for this rule.
For example, while some template languages would special-case
`if` clauses, they are treated the same in EEx and
also require `=` in order to have their result printed:
<%= if true do %>
It is obviously true
<% else %>
This will never appear
<% end %>
To escape an EEx expression in EEx use `<%% content %>`. For example:
<%%= x + 3 %>
will be rendered as `<%= x + 3 %>`.
Note that different engines may have different rules
for each tag. Other tags may be added in future versions.
### Macros
`EEx.SmartEngine` also adds some macros to your template.
An example is the `@` macro which allows easy data access
in a template:
iex> EEx.eval_string("<%= @foo %>", assigns: [foo: 1])
"1"
In other words, `<%= @foo %>` translates to:
<%= {:ok, v} = Access.fetch(assigns, :foo); v %>
The `assigns` extension is useful when the number of variables
required by the template is not specified at compilation time.
"""
@doc """
Generates a function definition from the string.
The kind (`:def` or `:defp`) must be given, the
function name, its arguments and the compilation options.
## Examples
iex> defmodule Sample do
...> require EEx
...> EEx.function_from_string(:def, :sample, "<%= a + b %>", [:a, :b])
...> end
iex> Sample.sample(1, 2)
"3"
"""
defmacro function_from_string(kind, name, source, args \\ [], options \\ []) do
quote bind_quoted: binding() do
info = Keyword.merge([file: __ENV__.file, line: __ENV__.line], options)
args = Enum.map(args, fn arg -> {arg, [line: info[:line]], nil} end)
compiled = EEx.compile_string(source, info)
case kind do
:def -> def unquote(name)(unquote_splicing(args)), do: unquote(compiled)
:defp -> defp unquote(name)(unquote_splicing(args)), do: unquote(compiled)
end
end
end
@doc """
Generates a function definition from the file contents.
The kind (`:def` or `:defp`) must be given, the
function name, its arguments and the compilation options.
This function is useful in case you have templates but
you want to precompile inside a module for speed.
## Examples
# sample.eex
<%= a + b %>
# sample.ex
defmodule Sample do
require EEx
EEx.function_from_file(:def, :sample, "sample.eex", [:a, :b])
end
# iex
Sample.sample(1, 2)
#=> "3"
"""
defmacro function_from_file(kind, name, file, args \\ [], options \\ []) do
quote bind_quoted: binding() do
info = Keyword.merge(options, file: file, line: 1)
args = Enum.map(args, fn arg -> {arg, [line: 1], nil} end)
compiled = EEx.compile_file(file, info)
@external_resource file
@file file
case kind do
:def -> def unquote(name)(unquote_splicing(args)), do: unquote(compiled)
:defp -> defp unquote(name)(unquote_splicing(args)), do: unquote(compiled)
end
end
end
@doc """
Gets a string `source` and generate a quoted expression
that can be evaluated by Elixir or compiled to a function.
"""
@spec compile_string(String.t(), keyword) :: Macro.t()
def compile_string(source, options \\ []) when is_binary(source) and is_list(options) do
EEx.Compiler.compile(source, options)
end
@doc """
Gets a `filename` and generate a quoted expression
that can be evaluated by Elixir or compiled to a function.
"""
@spec compile_file(String.t(), keyword) :: Macro.t()
def compile_file(filename, options \\ []) when is_binary(filename) and is_list(options) do
options = Keyword.merge(options, file: filename, line: 1)
compile_string(File.read!(filename), options)
end
@doc """
Gets a string `source` and evaluate the values using the `bindings`.
## Examples
iex> EEx.eval_string("foo <%= bar %>", bar: "baz")
"foo baz"
"""
@spec eval_string(String.t(), keyword, keyword) :: any
def eval_string(source, bindings \\ [], options \\ [])
when is_binary(source) and is_list(bindings) and is_list(options) do
compiled = compile_string(source, options)
do_eval(compiled, bindings, options)
end
@doc """
Gets a `filename` and evaluate the values using the `bindings`.
## Examples
# sample.eex
foo <%= bar %>
# iex
EEx.eval_file("sample.eex", bar: "baz")
#=> "foo baz"
"""
@spec eval_file(String.t(), keyword, keyword) :: any
def eval_file(filename, bindings \\ [], options \\ [])
when is_binary(filename) and is_list(bindings) and is_list(options) do
options = Keyword.put(options, :file, filename)
compiled = compile_file(filename, options)
do_eval(compiled, bindings, options)
end
### Helpers
defp do_eval(compiled, bindings, options) do
{result, _} = Code.eval_quoted(compiled, bindings, options)
result
end
end
| 31.497908 | 92 | 0.653294 |
f718484587dea114ddd7912b1614bfdb36ab4928 | 1,991 | exs | Elixir | mix.exs | participateapp/participate-api | 35dab43fc456f7e8b8c8479195562baad881aa44 | [
"MIT"
] | 3 | 2015-01-29T19:11:05.000Z | 2015-10-19T02:12:02.000Z | mix.exs | participateapp/participate-api | 35dab43fc456f7e8b8c8479195562baad881aa44 | [
"MIT"
] | 43 | 2015-05-31T00:28:45.000Z | 2017-02-06T20:06:19.000Z | mix.exs | participateapp/participate-api | 35dab43fc456f7e8b8c8479195562baad881aa44 | [
"MIT"
] | 2 | 2015-07-11T14:48:04.000Z | 2015-07-13T06:51:37.000Z | defmodule ParticipateApi.Mixfile do
use Mix.Project
def project do
[app: :participate_api,
version: "0.0.1",
elixir: "~> 1.0",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
aliases: aliases,
deps: deps,
preferred_cli_env: [espec: :test, vcr: :test, "vcr.delete": :test,
"vcr.check": :test, "vcr.show": :test]]
end
# Configuration for the OTP application.
#
# Type `mix help compile.app` for more information.
def application do
[mod: {ParticipateApi, []},
applications: [:phoenix, :cowboy, :logger, :gettext,
:phoenix_ecto, :postgrex, :httpotion]]
end
# Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["lib", "web", "spec/support"]
defp elixirc_paths(_), do: ["lib", "web"]
# Specifies your project dependencies.
#
# Type `mix help deps` for examples and options.
defp deps do
[{:phoenix, "~> 1.2"},
{:postgrex, ">= 0.0.0"},
{:phoenix_ecto, "~> 3.0"},
{:ecto, "~> 2.0", override: true},
{:gettext, "~> 0.9"},
{:cowboy, "~> 1.0"},
{:espec, "~> 0.8.22", only: :test},
{:espec_phoenix, "~> 0.2.1", only: :test, app: false},
{:ja_serializer, github: "AgilionApps/ja_serializer"},
{:guardian, "~> 0.12.0"},
{:exvcr, "~> 0.7", only: :test},
{:httpotion, "~> 3.0"},
{:ex_machina, "~> 1.0", only: :test},
{:plug, "~> 1.0"},
{:corsica, "~> 0.5"}]
end
# Aliases are shortcut or tasks specific to the current project.
# For example, to create, migrate and run the seeds file at once:
#
# $ mix ecto.setup
#
# See the documentation for `Mix` for more info on aliases.
defp aliases do
["ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"]]
end
end
| 31.603175 | 78 | 0.579106 |
f71850d625f90c80c699eb1301538f1330d82913 | 350 | exs | Elixir | bench/vector/take.exs | sabiwara/aja | cde91e4263e54a11a1685a777dbffd4912fe3864 | [
"MIT"
] | 95 | 2020-10-18T09:27:46.000Z | 2022-03-29T20:03:16.000Z | bench/vector/take.exs | sabiwara/aja | cde91e4263e54a11a1685a777dbffd4912fe3864 | [
"MIT"
] | 1 | 2021-09-22T20:30:08.000Z | 2021-10-13T23:55:34.000Z | bench/vector/take.exs | sabiwara/aja | cde91e4263e54a11a1685a777dbffd4912fe3864 | [
"MIT"
] | 1 | 2020-12-15T12:36:16.000Z | 2020-12-15T12:36:16.000Z | list = Enum.to_list(1..100)
vector = Aja.Vector.new(list)
Benchee.run(%{
"Aja.Vector.take/2" => fn -> Aja.Vector.take(vector, 80) end,
"Aja.Vector.slice/3" => fn -> Aja.Vector.slice(vector, 1, 80) end,
"Aja.Vector.slice/3 0-optimization" => fn -> Aja.Vector.slice(vector, 0, 80) end,
"Enum.take/2 (list)" => fn -> Enum.take(list, 80) end
})
| 35 | 83 | 0.634286 |
f7189efca5c31b7ed7dd80bad0c608856f28fd03 | 746 | ex | Elixir | lib/poller/server.ex | Triangle-Elixir/poller | aee63079e9e8e85748c87e04f3607258b10307fc | [
"MIT"
] | 1 | 2020-02-21T15:33:52.000Z | 2020-02-21T15:33:52.000Z | lib/poller/server.ex | Triangle-Elixir/poller | aee63079e9e8e85748c87e04f3607258b10307fc | [
"MIT"
] | null | null | null | lib/poller/server.ex | Triangle-Elixir/poller | aee63079e9e8e85748c87e04f3607258b10307fc | [
"MIT"
] | null | null | null | defmodule Poller.Server do
@moduledoc false
use GenServer
alias Poller.Client
def start_link(args) do
label = Keyword.fetch!(args, :label)
name = name_via_registry(label)
GenServer.start_link(__MODULE__, args, name: name)
end
def init(args) do
client = Client.new(args)
{:ok, client, {:continue, :start_poller}}
end
def handle_continue(:start_poller, client) do
Process.send_after(self(), :poll, client.interval)
{:noreply, client}
end
def handle_info(:poll, client) do
client = Client.notify_next(client)
Process.send_after(self(), :poll, client.interval)
{:noreply, client}
end
defp name_via_registry(label) do
{:via, Registry, {Poller.ServerRegistry, label}}
end
end
| 22.606061 | 54 | 0.693029 |
f718a44d35c238660b3432839f45d4b6309a0c2b | 11,950 | exs | Elixir | test/lib/timber/integrations/phoenix_instrumenter_test.exs | montebrown/timber-elixir | 1e177cc426422be3617479143038f5882037752f | [
"0BSD"
] | null | null | null | test/lib/timber/integrations/phoenix_instrumenter_test.exs | montebrown/timber-elixir | 1e177cc426422be3617479143038f5882037752f | [
"0BSD"
] | null | null | null | test/lib/timber/integrations/phoenix_instrumenter_test.exs | montebrown/timber-elixir | 1e177cc426422be3617479143038f5882037752f | [
"0BSD"
] | null | null | null | if Code.ensure_loaded?(Phoenix) do
defmodule Timber.Integrations.PhoenixInstrumenterTest do
# This test case has to be asynchronous since it modifies and depends on
# the application environment which is global
use Timber.TestCase, async: false
import ExUnit.CaptureLog
alias Timber.Integrations.PhoenixInstrumenter
require Logger
setup do
env = Application.get_env(:timber, PhoenixInstrumenter, [])
on_exit(fn ->
# Restore the saved environment
Application.put_env(:timber, PhoenixInstrumenter, env)
end)
{:ok, env: env}
end
describe "Timber.Integrations.PhoenixInstrumenter.get_unparsed_blacklist/0" do
test "fetches the unparsed blacklist from the Application environment" do
blacklist = [
{A, :action},
{B, :action}
]
Application.put_env(:timber, PhoenixInstrumenter, [
{:controller_actions_blacklist, blacklist}
])
assert [{A, :action}, {B, :action}] = PhoenixInstrumenter.get_unparsed_blacklist()
end
end
describe "Timber.Integrations.PhoenixInstrumenter.parse_blacklist/1" do
test "parses blacklist" do
unparsed_blacklist = [
{A, :action},
{B, :action}
]
parsed_blacklist = PhoenixInstrumenter.parse_blacklist(unparsed_blacklist)
assert MapSet.member?(parsed_blacklist, {A, :action})
assert MapSet.member?(parsed_blacklist, {B, :action})
refute MapSet.member?(parsed_blacklist, {Controller, :action})
end
end
describe "Timber.Integrations.PhoenixInstrumenter.add_controller_action_to_blacklist/2" do
test "adds controller action to the blacklist" do
PhoenixInstrumenter.put_parsed_blacklist(
MapSet.new([
{A, :action},
{B, :action}
])
)
PhoenixInstrumenter.add_controller_action_to_blacklist(Controller, :action)
blacklist = PhoenixInstrumenter.get_parsed_blacklist()
assert PhoenixInstrumenter.controller_action_blacklisted?({A, :action}, blacklist)
assert PhoenixInstrumenter.controller_action_blacklisted?({B, :action}, blacklist)
assert PhoenixInstrumenter.controller_action_blacklisted?(
{Controller, :action},
blacklist
)
end
end
describe "Timber.Integrations.PhoenixInstrumenter.remove_controller_action_from_blacklist/2" do
test "removes controller action from blacklist" do
PhoenixInstrumenter.put_parsed_blacklist(
MapSet.new([
{A, :action},
{B, :action}
])
)
PhoenixInstrumenter.remove_controller_action_from_blacklist(B, :action)
blacklist = PhoenixInstrumenter.get_parsed_blacklist()
assert PhoenixInstrumenter.controller_action_blacklisted?({A, :action}, blacklist)
refute PhoenixInstrumenter.controller_action_blacklisted?({B, :action}, blacklist)
end
end
describe "Timber.Integrations.PhoenixInstrumenter.get_parsed_blacklist/0" do
test "retrieves empty MapSet when blacklist is not in application environment" do
:ok = Application.put_env(:timber, PhoenixInstrumenter, [])
blacklist = PhoenixInstrumenter.get_parsed_blacklist()
assert match?(%MapSet{}, blacklist)
end
test "retrieves the blacklist from the application environment", %{env: env} do
blacklist =
MapSet.new([
{A, :action},
{B, :action}
])
new_env = Keyword.put(env, :parsed_controller_actions_blacklist, blacklist)
:ok = Application.put_env(:timber, PhoenixInstrumenter, new_env)
^blacklist = PhoenixInstrumenter.get_parsed_blacklist()
end
end
describe "Timber.Integrations.PhoenixInstrumenter.put_parsed_blacklist/1" do
test "puts the blacklist in the application environment" do
blacklist =
MapSet.new([
{A, :action},
{B, :action}
])
PhoenixInstrumenter.put_parsed_blacklist(blacklist)
new_env = Application.get_env(:timber, PhoenixInstrumenter, [])
^blacklist = Keyword.get(new_env, :parsed_controller_actions_blacklist, [])
end
end
describe "Timber.Integrations.PhoenixInstrumenter.phoenix_channel_join/3" do
test "logs phoenix_channel_join as configured by the channel" do
log =
capture_log(fn ->
socket = %Phoenix.Socket{channel: :channel, topic: "topic"}
PhoenixInstrumenter.phoenix_channel_join(:start, %{}, %{
socket: socket,
params: %{key: "val"}
})
end)
assert log =~ "Joined channel channel with \"topic\" @metadata "
end
end
describe "Timber.Integrations.PhoenixInstrumenter.phoenix_channel_receive/3" do
test "logs phoenix_channel_receive as configured by the channel" do
log =
capture_log(fn ->
socket = %Phoenix.Socket{channel: :channel, topic: "topic"}
PhoenixInstrumenter.phoenix_channel_receive(:start, %{}, %{
socket: socket,
event: "e",
params: %{}
})
end)
assert log =~ "Received e on \"topic\" to channel @metadata "
end
test "accepts a message where the params is a keyword list" do
log =
capture_log(fn ->
socket = %Phoenix.Socket{channel: :channel, topic: "topic"}
params = [name: "Geoffrey"]
metadata = %{
socket: socket,
event: "e",
params: params
}
PhoenixInstrumenter.phoenix_channel_receive(:start, %{}, metadata)
end)
assert log =~ ~s/Received e on "topic" to channel @metadata /
end
test "accepts a message where the params is a non-Keyword list" do
log =
capture_log(fn ->
socket = %Phoenix.Socket{channel: :channel, topic: "topic"}
params = ["a", "b"]
metadata = %{
socket: socket,
event: "e",
params: params
}
PhoenixInstrumenter.phoenix_channel_receive(:start, %{}, metadata)
end)
assert log =~ ~s/Received e on "topic" to channel @metadata /
end
test "accepts a message where the params is a string" do
log =
capture_log(fn ->
socket = %Phoenix.Socket{channel: :channel, topic: "topic"}
params = "61cf02ad-9509-48be-9b88-edf5e85219fe"
metadata = %{
socket: socket,
event: "e",
params: params
}
PhoenixInstrumenter.phoenix_channel_receive(:start, %{}, metadata)
end)
assert log =~ ~s/Received e on "topic" to channel @metadata /
end
test "accept a message where the params ia numeric value" do
log =
capture_log(fn ->
socket = %Phoenix.Socket{channel: :channel, topic: "topic"}
params = 3.14
metadata = %{
socket: socket,
event: "e",
params: params
}
PhoenixInstrumenter.phoenix_channel_receive(:start, %{}, metadata)
end)
assert log =~ ~s/Received e on "topic" to channel @metadata /
end
end
describe "Timber.Integrations.PhoenixInstrumenter.phoenix_controller_call/3" do
test "logs phoenix controller calls" do
controller = Controller
action = :action
conn =
Phoenix.ConnTest.build_conn()
|> Plug.Conn.put_private(:phoenix_controller, controller)
|> Plug.Conn.put_private(:phoenix_action, action)
log =
capture_log(fn ->
PhoenixInstrumenter.phoenix_controller_call(:start, %{}, %{conn: conn})
end)
assert log =~ "Processing with Controller.action/2"
end
test "does not log controller calls if the controller/action pair is in the black list" do
controller = Controller
action = :action
PhoenixInstrumenter.add_controller_action_to_blacklist(controller, action)
conn =
Phoenix.ConnTest.build_conn()
|> Plug.Conn.put_private(:phoenix_controller, controller)
|> Plug.Conn.put_private(:phoenix_action, action)
log =
capture_log(fn ->
PhoenixInstrumenter.phoenix_controller_call(:start, %{}, %{conn: conn})
end)
assert log == ""
end
end
describe "Timber.Integrations.PhoenixInstrumenter.phoenix_controller_render/3" do
test ":start returns the log level and template name by default" do
controller = Controller
action = :action
template_name = "index.html"
conn =
Phoenix.ConnTest.build_conn()
|> Plug.Conn.put_private(:phoenix_controller, controller)
|> Plug.Conn.put_private(:phoenix_action, action)
assert {:ok, :info, ^template_name} =
PhoenixInstrumenter.phoenix_controller_render(:start, %{}, %{
template: template_name,
conn: conn
})
end
test ":start returns true when the controller/action is not available" do
# This test situation occurs when the route cannot be matched, for example
template_name = "404.html"
conn = Phoenix.ConnTest.build_conn()
assert {:ok, :info, ^template_name} =
PhoenixInstrumenter.phoenix_controller_render(:start, %{}, %{
template: template_name,
conn: conn
})
end
test ":start returns false when the controller/action is blacklisted" do
controller = Controller
action = :action
template_name = "index.html"
PhoenixInstrumenter.add_controller_action_to_blacklist(controller, action)
conn =
Phoenix.ConnTest.build_conn()
|> Plug.Conn.put_private(:phoenix_controller, controller)
|> Plug.Conn.put_private(:phoenix_action, action)
assert false ==
PhoenixInstrumenter.phoenix_controller_render(:start, %{}, %{
template: template_name,
conn: conn
})
end
test ":start returns true when a template name is given but no connection" do
# This test situation occurs when the route cannot be matched, for example
template_name = "404.html"
assert {:ok, :info, ^template_name} =
PhoenixInstrumenter.phoenix_controller_render(:start, %{}, %{
template: template_name
})
end
test ":start returns :ok when an unsupported map is passed" do
assert :ok = PhoenixInstrumenter.phoenix_controller_render(:start, %{}, %{})
end
test ":stop does not log anything when the third param is :ok" do
log =
capture_log(fn ->
PhoenixInstrumenter.phoenix_controller_render(:stop, %{}, :ok)
end)
assert log == ""
end
test ":stop does not log anything when the third param is false" do
log =
capture_log(fn ->
PhoenixInstrumenter.phoenix_controller_render(:stop, %{}, false)
end)
assert log == ""
end
test ":stop logs the render time when it is present" do
template_name = "index.html"
log_level = :info
log =
capture_log(fn ->
PhoenixInstrumenter.phoenix_controller_render(
:stop,
0,
{:ok, log_level, template_name}
)
end)
assert log =~ "Rendered \"index.html\" in 0.0ms"
end
end
end
end
| 32.037534 | 99 | 0.600921 |
f718e705810d6cf4bc99dfd5762cbda17268a8ac | 377 | ex | Elixir | lib/godfist/requests/status.ex | whitfin/godfist | b311b17b3db3b47b650b070da4fd753f4492560d | [
"MIT"
] | 6 | 2017-07-27T08:23:25.000Z | 2020-01-14T19:17:52.000Z | lib/godfist/requests/status.ex | whitfin/godfist | b311b17b3db3b47b650b070da4fd753f4492560d | [
"MIT"
] | 7 | 2017-08-26T06:01:16.000Z | 2018-04-03T18:30:44.000Z | lib/godfist/requests/status.ex | whitfin/godfist | b311b17b3db3b47b650b070da4fd753f4492560d | [
"MIT"
] | 2 | 2017-08-26T05:50:29.000Z | 2018-10-01T20:44:42.000Z | defmodule Godfist.Status do
@moduledoc """
Status endpoint.
"""
alias Godfist.LeagueRates
@v "v3"
# Returns shard-data of a specific server
@doc """
Return shard data.
"""
@spec shard(atom) :: {:ok, map} | {:error, String.t()}
def shard(region) do
rest = "/lol/status/#{@v}/shard-data"
LeagueRates.handle_rate(region, rest, :other)
end
end
| 17.136364 | 56 | 0.625995 |
f7190c82e6bedb917dfe7129290290019c0fdc0e | 1,514 | exs | Elixir | apps/ewallet/test/ewallet/web/v1/serializers/paginator_serializer_test.exs | vanmil/ewallet | 6c1aca95a83e0a9d93007670a40d8c45764a8122 | [
"Apache-2.0"
] | null | null | null | apps/ewallet/test/ewallet/web/v1/serializers/paginator_serializer_test.exs | vanmil/ewallet | 6c1aca95a83e0a9d93007670a40d8c45764a8122 | [
"Apache-2.0"
] | null | null | null | apps/ewallet/test/ewallet/web/v1/serializers/paginator_serializer_test.exs | vanmil/ewallet | 6c1aca95a83e0a9d93007670a40d8c45764a8122 | [
"Apache-2.0"
] | null | null | null | defmodule EWallet.Web.V1.PaginatorSerializerTest do
use EWallet.Web.SerializerCase, :v1
alias EWallet.Web.V1.PaginatorSerializer
alias EWallet.Web.Paginator
describe "PaginatorSerializer.serialize/1" do
test "serializes the given paginator into a list object" do
paginator = %Paginator{
data: "dummy_data",
pagination: %{
current_page: 2,
per_page: 5,
is_first_page: false,
is_last_page: true
}
}
expected = %{
object: "list",
data: "dummy_data",
pagination: %{
current_page: 2,
per_page: 5,
is_first_page: false,
is_last_page: true
}
}
assert PaginatorSerializer.serialize(paginator) == expected
end
end
describe "PaginatorSerializer.serialize/2" do
test "maps the data before serializing into a list object" do
paginator = %Paginator{
data: ["dummy", "another_dummy"],
pagination: %{
current_page: 2,
per_page: 5,
is_first_page: false,
is_last_page: true
}
}
expected = %{
object: "list",
data: ["replaced_data", "replaced_data"],
pagination: %{
current_page: 2,
per_page: 5,
is_first_page: false,
is_last_page: true
}
}
result = PaginatorSerializer.serialize(paginator, fn _ -> "replaced_data" end)
assert result == expected
end
end
end
| 24.819672 | 84 | 0.577279 |
f7191dd8d8cebdf174e71b2f1f35f1200b38949a | 162 | exs | Elixir | test/robosseum_client_test.exs | robosseum/client-elixir | 65efed560bc8aa79c866db0efcf6463be28527f0 | [
"MIT"
] | null | null | null | test/robosseum_client_test.exs | robosseum/client-elixir | 65efed560bc8aa79c866db0efcf6463be28527f0 | [
"MIT"
] | null | null | null | test/robosseum_client_test.exs | robosseum/client-elixir | 65efed560bc8aa79c866db0efcf6463be28527f0 | [
"MIT"
] | null | null | null | defmodule RobosseumClientTest do
use ExUnit.Case
doctest RobosseumClient
test "greets the world" do
assert RobosseumClient.hello() == :world
end
end
| 18 | 44 | 0.753086 |
f71922b1cfcce668c60f0f5411815ad40aa60245 | 6,754 | ex | Elixir | apps/cashtrail/lib/cashtrail/users.ex | maxmaccari/cashtrail | 74ec7ff1f8a41299a6086dc98719a32cbfbe9ee7 | [
"MIT"
] | 6 | 2020-05-02T01:12:24.000Z | 2020-06-23T12:31:32.000Z | apps/cashtrail/lib/cashtrail/users.ex | maxmaccari/cashtrail | 74ec7ff1f8a41299a6086dc98719a32cbfbe9ee7 | [
"MIT"
] | 16 | 2020-05-02T00:07:51.000Z | 2021-06-11T01:54:11.000Z | apps/cashtrail/lib/cashtrail/users.ex | maxmaccari/cashtrail | 74ec7ff1f8a41299a6086dc98719a32cbfbe9ee7 | [
"MIT"
] | null | null | null | defmodule Cashtrail.Users do
@moduledoc """
The Users context manages the users data of one entity and performs user
authentication.
See `Cashtrail.Users.User` to have more info about user.
"""
import Ecto.Query, warn: false
alias Cashtrail.Repo
alias Cashtrail.{Paginator, Users}
alias Cashtrail.Users.PasswordHash
import Cashtrail.QueryBuilder, only: [build_search: 3]
@type user() :: Users.User.t()
@doc """
Returns a `%Cashtrail.Paginator.Page{}` struct with a list of users in the
`:entries` field.
## Expected arguments
* options - A `keyword` list of the following options:
* `:search` - search users by `:first_name`, `:last_name` or `:email`.
* See `Cashtrail.Paginator.paginate/2` to see the paginations options.
See `Cashtrail.Users.User` to have more detailed info about the fields to
be filtered or searched.
## Examples
iex> list_users()
%Cashtrail.Paginator{entries: [%Users.User{}, ...]}
iex> list_users(search: "my")
%Cashtrail.Paginator{entries: [%Users.User{first_name: "My name"}, ...]}
"""
@spec list_users(keyword) :: Cashtrail.Paginator.Page.t(user)
def list_users(options \\ []) do
Users.User
|> build_search(Keyword.get(options, :search), [:first_name, :last_name, :email])
|> Paginator.paginate(options)
end
@doc """
Gets a single user.
Raises `Ecto.NoResultsError` if the User does not exist.
See `Cashtrail.Users.User` to have more detailed info about the returned
struct.
## Expected Arguments
* id - A `string` that is the unique id of the user to be found.
## Examples
iex> get_user!(123)
%Users.User{}
iex> get_user!(456)
** (Ecto.NoResultsError)
"""
@spec get_user!(Ecto.UUID.t() | String.t()) :: user()
def get_user!(id), do: Repo.get!(Users.User, id)
@doc """
Gets a single user by the given param.
Returns nil the User does not exist.
See `Cashtrail.Users.User` to have more detailed info about the returned
struct and the params attributes that can be given.
## Expected Arguments
* params - A `keyword` or a `map` with the attributes of the user to be found.
## Examples
iex> get_user_by(email: "[email protected]")
%Users.User{}
iex> get_user_by(email: "noexists')
nil
"""
@spec get_user_by(keyword | map) :: nil | {:error, :invalid_email} | user()
def get_user_by(email: nil), do: {:error, :invalid_email}
def get_user_by(params), do: Repo.get_by(Users.User, params)
@doc """
Authenticates a user with its email and password.
## Expected Arguments
* email - A `string` that is the email of the user.
* password - A `string` that is the expected password of the user.
## Returns
* `{:ok, user}` if user is found and the passwords match.
* `{:error, :unauthorized}` if passwords does not match.
* `{:error, :not_found}` if user email is not found.
## Examples
iex> authenticate(email, password)
{:ok, %Users.User{}}
iex> authenticate(email, wrong_pass)
{:error, :unauthorized}
iex> authenticate(wrong_email, password)
{:error, :not_found}
"""
@spec authenticate(String.t(), String.t()) ::
{:ok, user()} | {:error, :not_found | :unauthorized}
def authenticate(email, password) do
case get_user_by(email: email) do
nil ->
PasswordHash.no_user_verify()
{:error, :not_found}
%Users.User{} = user ->
verify_password_hash(user, password)
end
end
defp verify_password_hash(%Users.User{password_hash: password_hash} = user, password) do
if PasswordHash.verify_pass(password, password_hash) do
{:ok, user}
else
{:error, :unauthorized}
end
end
@doc """
Creates a user.
## Expected Arguments
* params - A `map` with the params of the user to be created:
* `:email` (required) - A `string` with the email of the user. Must be
a valid email and unique in the application.
* `:first_name` (required) - A `string` with the first name of the user.
* `:last_name` - A `string` with the last name of the user.
* `:password` (required) - A `string` with the password of the user to be created.
The password must have the min size of 6 characters containing at least one
letter, and one number.
* `:password_confirmation` (required) - A `string` with password confirmation
of the user to be created. Must be the equals the `:password` field.
See `Cashtrail.Users.User` to have more detailed info about the fields.
## Returns
* `{:ok, %Cashtrail.Users.User{}}` in case of success.
* `{:error, %Ecto.Changeset{}}` in case of error.
## Examples
iex> create_user(%{field: value})
{:ok, %Cashtrail.Users.User{}}
iex> create_user(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
@spec create_user(map) ::
{:ok, user()} | {:error, Ecto.Changeset.t(user())}
def create_user(attrs) do
%Users.User{}
|> Users.User.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a user.
## Expected Arguments
* user - The `%Cashtrail.Users.User{}` to be updated.
* params - A `map` with the field of the user to be updated. See
`create_user/2` to know about the params that can be given.
## Returns
* `{:ok, %Cashtrail.Users.User{}}` in case of success.
* `{:error, %Ecto.Changeset{}}` in case of error.
## Examples
iex> update_user(user, %{field: new_value})
{:ok, %Users.User{}}
iex> update_user(user, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
@spec update_user(user(), map) :: {:ok, user()} | {:error, Ecto.Changeset.t(user())}
def update_user(%Users.User{} = user, attrs) do
user
|> Users.User.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a user.
## Expected Arguments
* user - The `%Cashtrail.Users.User{}` to be deleted.
## Returns
* `{:ok, %Cashtrail.Users.User{}}` in case of success.
* `{:error, %Ecto.Changeset{}}` in case of error.
## Examples
iex> delete_user(user)
{:ok, %Users.User{}}
iex> delete_user(user)
{:error, %Ecto.Changeset{}}
"""
@spec delete_user(user()) :: {:ok, user()} | {:error, Ecto.Changeset.t(user())}
def delete_user(%Users.User{} = user) do
Repo.delete(user)
end
@doc """
Returns an `%Ecto.Changeset{}` for tracking user changes.
## Expected Arguments
* user - The `%Cashtrail.Users.User{}` to be tracked.
## Examples
iex> change_user(user)
%Ecto.Changeset{source: %Cashtrail.Users.User{}}
"""
@spec change_user(user()) :: Ecto.Changeset.t(user())
def change_user(%Users.User{} = user) do
Users.User.changeset(user, %{})
end
end
| 26.382813 | 90 | 0.639917 |
f7193307cb1dace3d6ee175e327b2eefac0060cf | 2,933 | exs | Elixir | apps/omg_watcher/test/omg_watcher/integration/transaction_submit_test.exs | PinkDiamond1/elixir-omg | 70dfd24a0a1ddf5d1d9d71aab61ea25300f889f7 | [
"Apache-2.0"
] | 1 | 2020-05-01T12:30:09.000Z | 2020-05-01T12:30:09.000Z | apps/omg_watcher/test/omg_watcher/integration/transaction_submit_test.exs | PinkDiamond1/elixir-omg | 70dfd24a0a1ddf5d1d9d71aab61ea25300f889f7 | [
"Apache-2.0"
] | null | null | null | apps/omg_watcher/test/omg_watcher/integration/transaction_submit_test.exs | PinkDiamond1/elixir-omg | 70dfd24a0a1ddf5d1d9d71aab61ea25300f889f7 | [
"Apache-2.0"
] | 1 | 2021-12-04T00:37:46.000Z | 2021-12-04T00:37:46.000Z | # Copyright 2019 OmiseGO Pte Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
defmodule OMG.Watcher.Integration.TransactionSubmitTest do
@moduledoc """
Tests thin-client scenario:
Assuming funded address
1. call `/transaction.create` to prepare transaction with data ready to be signed with `eth_signTypedData`
2. call Ethereum node (e.g. MetaMask) with above data as request to sign transaction
3. call `/transaction.submit_typed` with typed data and signatures to submit transaction to child chain
"""
use ExUnitFixtures
use ExUnit.Case, async: false
use OMG.Fixtures
use OMG.ChildChain.Integration.Fixtures
use Plug.Test
alias OMG.DevCrypto
alias OMG.Eth
alias OMG.Utils.HttpRPC.Encoding
alias OMG.Watcher.Integration.TestHelper, as: IntegrationTest
alias OMG.Watcher.TestHelper
@moduletag :integration
@moduletag :watcher
@moduletag timeout: 180_000
@timeout 40_000
@eth OMG.Eth.RootChain.eth_pseudo_address()
@eth_hex Encoding.to_hex(@eth)
@tag fixtures: [:watcher, :child_chain, :stable_alice, :bob, :stable_alice_deposits]
test "Thin client scenario", %{
stable_alice: alice,
bob: bob
} do
alice_addr = Encoding.to_hex(alice.addr)
bob_addr = Encoding.to_hex(bob.addr)
# 10 = 5 to Bob + 2 fee + 3 rest to Alice
fee = 2
alice_to_bob = 5
order = %{
"owner" => alice_addr,
"payments" => [%{"amount" => alice_to_bob, "currency" => @eth_hex, "owner" => bob_addr}],
"fee" => %{"amount" => fee, "currency" => @eth_hex}
}
%{
"result" => "complete",
"transactions" => [
%{
"sign_hash" => sign_hash,
"typed_data" => typed_data
}
]
} = TestHelper.success?("transaction.create", order)
signature =
sign_hash
|> Eth.Encoding.from_hex()
|> DevCrypto.signature_digest(alice.priv)
typed_data_signed =
typed_data
|> Map.put_new("signatures", [Encoding.to_hex(signature)])
assert %{
"blknum" => tx_blknum,
"txindex" => tx_index
} = TestHelper.success?("transaction.submit_typed", typed_data_signed)
IntegrationTest.wait_for_block_fetch(tx_blknum, @timeout)
assert [
%{
"blknum" => ^tx_blknum,
"txindex" => ^tx_index,
"amount" => ^alice_to_bob
}
] = TestHelper.get_utxos(bob.addr)
end
end
| 29.626263 | 108 | 0.66178 |
f71933617d834be659511f620f66a401fc08c4fa | 1,454 | ex | Elixir | lib/geocoder.ex | gmcintire/geocoder | 174251a2595657157e4e1d70ee2678c2a94f7cd2 | [
"MIT"
] | null | null | null | lib/geocoder.ex | gmcintire/geocoder | 174251a2595657157e4e1d70ee2678c2a94f7cd2 | [
"MIT"
] | null | null | null | lib/geocoder.ex | gmcintire/geocoder | 174251a2595657157e4e1d70ee2678c2a94f7cd2 | [
"MIT"
] | null | null | null | defmodule Geocoder do
use Application
@pool_name :geocoder_workers
@default_config [worker_module: Geocoder.Worker, name: {:local, @pool_name}]
def pool_name, do: @pool_name
def worker_config do
Keyword.merge(Application.get_env(:geocoder, Geocoder.Worker) || [], @default_config)
end
def store_config do
Application.get_env(:geocoder, Geocoder.Store) || []
end
def start(_type, _opts) do
import Supervisor.Spec
children = [
:poolboy.child_spec(
pool_name(),
worker_config(),
Application.get_env(:geocoder, :worker) || []
),
worker(Geocoder.Store, [store_config()])
]
options = [
strategy: :one_for_one,
name: Geocoder.Supervisor
]
Supervisor.start_link(children, options)
end
alias Geocoder.Worker
def call(opts) when is_list(opts), do: Worker.geocode(opts)
def call(q, opts \\ [])
def call(q, opts) when is_binary(q), do: Worker.geocode(opts ++ [address: q])
def call(q = {lat, lon}, opts),
do: Worker.reverse_geocode(opts ++ [lat: lat, lon: lon, latlng: q])
def call(%{lat: lat, lon: lon}, opts), do: call({lat, lon}, opts)
def call_list(q, opts \\ [])
def call_list(q, opts) when is_binary(q), do: Worker.geocode_list(opts ++ [address: q])
def call_list(q = {_, _}, opts), do: Worker.reverse_geocode_list(opts ++ [latlng: q])
def call_list(%{lat: lat, lon: lon}, opts), do: call_list({lat, lon}, opts)
end
| 26.925926 | 89 | 0.649243 |
f7193c883e54d9a53cc23635952d4bfc88e846b8 | 1,728 | ex | Elixir | lib/sanbase_web/controllers/root_controller.ex | santiment/sanbase2 | 9ef6e2dd1e377744a6d2bba570ea6bd477a1db31 | [
"MIT"
] | 81 | 2017-11-20T01:20:22.000Z | 2022-03-05T12:04:25.000Z | lib/sanbase_web/controllers/root_controller.ex | rmoorman/sanbase2 | 226784ab43a24219e7332c49156b198d09a6dd85 | [
"MIT"
] | 359 | 2017-10-15T14:40:53.000Z | 2022-01-25T13:34:20.000Z | lib/sanbase_web/controllers/root_controller.ex | rmoorman/sanbase2 | 226784ab43a24219e7332c49156b198d09a6dd85 | [
"MIT"
] | 16 | 2017-11-19T13:57:40.000Z | 2022-02-07T08:13:02.000Z | defmodule SanbaseWeb.RootController do
use SanbaseWeb, :controller
require Logger
alias Sanbase.Oauth2.Hydra
alias Sanbase.Accounts.User
# Used in production mode to serve the reactjs application
def index(conn, _params) do
conn
|> put_resp_header("content-type", "text/html; charset=utf-8")
|> Plug.Conn.send_file(200, path("priv/static/index.html"))
end
def get_routed_conn(conn, _params), do: conn
def healthcheck(conn, _params) do
conn
|> put_resp_content_type("text/plain")
|> send_resp(200, "")
end
def consent(conn, %{"consent" => consent} = params) do
token = Map.get(params, "token")
token =
if token != nil and token != "null" do
token
else
%Plug.Conn{
private: %{plug_session: %{"auth_token" => token}}
} = conn
token
end
with {:ok, user} <- bearer_authorize(token),
{:ok, access_token} <- Hydra.get_access_token(),
{:ok, redirect_url, _client_id} <- Hydra.get_consent_data(consent, access_token),
{:ok, _} <- Hydra.manage_consent(consent, access_token, user) do
redirect(conn, external: redirect_url)
else
error ->
Logger.error("Error in ouath #{inspect(error)}")
redirect(conn, to: "/")
end
end
def consent(conn, _params) do
redirect(conn, to: "/")
end
defp path(file) do
Application.app_dir(:sanbase)
|> Path.join(file)
end
defp bearer_authorize(token) do
case SanbaseWeb.Guardian.resource_from_token(token) do
{:ok, %User{} = user, _} ->
{:ok, user}
_ ->
Logger.warn("Invalid bearer token in request: #{token}")
{:error, :invalid_token}
end
end
end
| 24.685714 | 90 | 0.62037 |
f71959bc04010e1d9f8077cd2c2230a51757b903 | 1,436 | exs | Elixir | test/mmdb2/result/connection_type_test.exs | tcitworld/adapter_mmdb2 | 965fd00ce2ba3d11d1749047f97fa2ccaeaaf533 | [
"Apache-2.0"
] | 3 | 2018-03-03T18:59:55.000Z | 2020-12-31T19:36:59.000Z | test/mmdb2/result/connection_type_test.exs | tcitworld/adapter_mmdb2 | 965fd00ce2ba3d11d1749047f97fa2ccaeaaf533 | [
"Apache-2.0"
] | 3 | 2019-07-17T12:55:41.000Z | 2020-08-31T18:55:15.000Z | test/mmdb2/result/connection_type_test.exs | tcitworld/adapter_mmdb2 | 965fd00ce2ba3d11d1749047f97fa2ccaeaaf533 | [
"Apache-2.0"
] | 4 | 2019-07-15T10:07:16.000Z | 2021-09-22T15:46:04.000Z | defmodule Geolix.Adapter.MMDB2.Result.ConnectionTypeTest do
use ExUnit.Case, async: true
alias Geolix.Adapter.MMDB2.Result.ConnectionType
test "result type" do
assert %ConnectionType{} = Geolix.lookup("1.0.0.0", where: :fixture_connection)
end
test "ipv6 lookup" do
ip = "2003::"
{:ok, ip_address} = ip |> String.to_charlist() |> :inet.parse_address()
result = Geolix.lookup(ip, where: :fixture_connection)
expected = %ConnectionType{connection_type: "Cable/DSL", ip_address: ip_address}
assert result == expected
end
test "cable/dsl" do
ip = {1, 0, 1, 0}
result = Geolix.lookup(ip, where: :fixture_connection)
expected = %ConnectionType{connection_type: "Cable/DSL", ip_address: ip}
assert result == expected
end
test "corporate" do
ip = {201, 243, 200, 0}
result = Geolix.lookup(ip, where: :fixture_connection)
expected = %ConnectionType{connection_type: "Corporate", ip_address: ip}
assert result == expected
end
test "cellular" do
ip = {80, 214, 0, 0}
result = Geolix.lookup(ip, where: :fixture_connection)
expected = %ConnectionType{connection_type: "Cellular", ip_address: ip}
assert result == expected
end
test "dialup" do
ip = {1, 0, 2, 0}
result = Geolix.lookup(ip, where: :fixture_connection)
expected = %ConnectionType{connection_type: "Dialup", ip_address: ip}
assert result == expected
end
end
| 27.615385 | 84 | 0.681755 |
f71993ae1701754ef4bb17e4230ce000ac3b4dd0 | 9,587 | ex | Elixir | clients/cloud_resource_manager/lib/google_api/cloud_resource_manager/v1/model/list_policy.ex | nuxlli/elixir-google-api | ecb8679ac7282b7dd314c3e20c250710ec6a7870 | [
"Apache-2.0"
] | null | null | null | clients/cloud_resource_manager/lib/google_api/cloud_resource_manager/v1/model/list_policy.ex | nuxlli/elixir-google-api | ecb8679ac7282b7dd314c3e20c250710ec6a7870 | [
"Apache-2.0"
] | null | null | null | clients/cloud_resource_manager/lib/google_api/cloud_resource_manager/v1/model/list_policy.ex | nuxlli/elixir-google-api | ecb8679ac7282b7dd314c3e20c250710ec6a7870 | [
"Apache-2.0"
] | 1 | 2020-11-10T16:58:27.000Z | 2020-11-10T16:58:27.000Z | # Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE: This class is auto generated by the swagger code generator program.
# https://github.com/swagger-api/swagger-codegen.git
# Do not edit the class manually.
defmodule GoogleApi.CloudResourceManager.V1.Model.ListPolicy do
@moduledoc """
Used in `policy_type` to specify how `list_policy` behaves at this resource. `ListPolicy` can define specific values and subtrees of Cloud Resource Manager resource hierarchy (`Organizations`, `Folders`, `Projects`) that are allowed or denied by setting the `allowed_values` and `denied_values` fields. This is achieved by using the `under:` and optional `is:` prefixes. The `under:` prefix is used to denote resource subtree values. The `is:` prefix is used to denote specific values, and is required only if the value contains a \":\". Values prefixed with \"is:\" are treated the same as values with no prefix. Ancestry subtrees must be in one of the following formats: - “projects/<project-id>”, e.g. “projects/tokyo-rain-123” - “folders/<folder-id>”, e.g. “folders/1234” - “organizations/<organization-id>”, e.g. “organizations/1234” The `supports_under` field of the associated `Constraint` defines whether ancestry prefixes can be used. You can set `allowed_values` and `denied_values` in the same `Policy` if `all_values` is `ALL_VALUES_UNSPECIFIED`. `ALLOW` or `DENY` are used to allow or deny all values. If `all_values` is set to either `ALLOW` or `DENY`, `allowed_values` and `denied_values` must be unset.
## Attributes
- allValues (String.t): The policy all_values state. Defaults to: `null`.
- Enum - one of [ALL_VALUES_UNSPECIFIED, ALLOW, DENY]
- allowedValues ([String.t]): List of values allowed at this resource. Can only be set if `all_values` is set to `ALL_VALUES_UNSPECIFIED`. Defaults to: `null`.
- deniedValues ([String.t]): List of values denied at this resource. Can only be set if `all_values` is set to `ALL_VALUES_UNSPECIFIED`. Defaults to: `null`.
- inheritFromParent (boolean()): Determines the inheritance behavior for this `Policy`. By default, a `ListPolicy` set at a resource supercedes any `Policy` set anywhere up the resource hierarchy. However, if `inherit_from_parent` is set to `true`, then the values from the effective `Policy` of the parent resource are inherited, meaning the values set in this `Policy` are added to the values inherited up the hierarchy. Setting `Policy` hierarchies that inherit both allowed values and denied values isn't recommended in most circumstances to keep the configuration simple and understandable. However, it is possible to set a `Policy` with `allowed_values` set that inherits a `Policy` with `denied_values` set. In this case, the values that are allowed must be in `allowed_values` and not present in `denied_values`. For example, suppose you have a `Constraint` `constraints/serviceuser.services`, which has a `constraint_type` of `list_constraint`, and with `constraint_default` set to `ALLOW`. Suppose that at the Organization level, a `Policy` is applied that restricts the allowed API activations to {`E1`, `E2`}. Then, if a `Policy` is applied to a project below the Organization that has `inherit_from_parent` set to `false` and field all_values set to DENY, then an attempt to activate any API will be denied. The following examples demonstrate different possible layerings for `projects/bar` parented by `organizations/foo`: Example 1 (no inherited values): `organizations/foo` has a `Policy` with values: {allowed_values: “E1” allowed_values:”E2”} `projects/bar` has `inherit_from_parent` `false` and values: {allowed_values: \"E3\" allowed_values: \"E4\"} The accepted values at `organizations/foo` are `E1`, `E2`. The accepted values at `projects/bar` are `E3`, and `E4`. Example 2 (inherited values): `organizations/foo` has a `Policy` with values: {allowed_values: “E1” allowed_values:”E2”} `projects/bar` has a `Policy` with values: {value: “E3” value: ”E4” inherit_from_parent: true} The accepted values at `organizations/foo` are `E1`, `E2`. The accepted values at `projects/bar` are `E1`, `E2`, `E3`, and `E4`. Example 3 (inheriting both allowed and denied values): `organizations/foo` has a `Policy` with values: {allowed_values: \"E1\" allowed_values: \"E2\"} `projects/bar` has a `Policy` with: {denied_values: \"E1\"} The accepted values at `organizations/foo` are `E1`, `E2`. The value accepted at `projects/bar` is `E2`. Example 4 (RestoreDefault): `organizations/foo` has a `Policy` with values: {allowed_values: “E1” allowed_values:”E2”} `projects/bar` has a `Policy` with values: {RestoreDefault: {}} The accepted values at `organizations/foo` are `E1`, `E2`. The accepted values at `projects/bar` are either all or none depending on the value of `constraint_default` (if `ALLOW`, all; if `DENY`, none). Example 5 (no policy inherits parent policy): `organizations/foo` has no `Policy` set. `projects/bar` has no `Policy` set. The accepted values at both levels are either all or none depending on the value of `constraint_default` (if `ALLOW`, all; if `DENY`, none). Example 6 (ListConstraint allowing all): `organizations/foo` has a `Policy` with values: {allowed_values: “E1” allowed_values: ”E2”} `projects/bar` has a `Policy` with: {all: ALLOW} The accepted values at `organizations/foo` are `E1`, E2`. Any value is accepted at `projects/bar`. Example 7 (ListConstraint allowing none): `organizations/foo` has a `Policy` with values: {allowed_values: “E1” allowed_values: ”E2”} `projects/bar` has a `Policy` with: {all: DENY} The accepted values at `organizations/foo` are `E1`, E2`. No value is accepted at `projects/bar`. Example 10 (allowed and denied subtrees of Resource Manager hierarchy): Given the following resource hierarchy O1->{F1, F2}; F1->{P1}; F2->{P2, P3}, `organizations/foo` has a `Policy` with values: {allowed_values: \"under:organizations/O1\"} `projects/bar` has a `Policy` with: {allowed_values: \"under:projects/P3\"} {denied_values: \"under:folders/F2\"} The accepted values at `organizations/foo` are `organizations/O1`, `folders/F1`, `folders/F2`, `projects/P1`, `projects/P2`, `projects/P3`. The accepted values at `projects/bar` are `organizations/O1`, `folders/F1`, `projects/P1`. Defaults to: `null`.
- suggestedValue (String.t): Optional. The Google Cloud Console will try to default to a configuration that matches the value specified in this `Policy`. If `suggested_value` is not set, it will inherit the value specified higher in the hierarchy, unless `inherit_from_parent` is `false`. Defaults to: `null`.
"""
use GoogleApi.Gax.ModelBase
@type t :: %__MODULE__{
:allValues => any(),
:allowedValues => list(any()),
:deniedValues => list(any()),
:inheritFromParent => any(),
:suggestedValue => any()
}
field(:allValues)
field(:allowedValues, type: :list)
field(:deniedValues, type: :list)
field(:inheritFromParent)
field(:suggestedValue)
end
defimpl Poison.Decoder, for: GoogleApi.CloudResourceManager.V1.Model.ListPolicy do
def decode(value, options) do
GoogleApi.CloudResourceManager.V1.Model.ListPolicy.decode(value, options)
end
end
defimpl Poison.Encoder, for: GoogleApi.CloudResourceManager.V1.Model.ListPolicy do
def encode(value, options) do
GoogleApi.Gax.ModelBase.encode(value, options)
end
end
| 157.163934 | 5,553 | 0.714509 |
f71997fe3403a55989470e18bd1fd1a8efb5006e | 4,265 | ex | Elixir | lib/links.ex | ddidwyll/shorty | b02968d1093c2b61ab21e889ee39850244e4748e | [
"MIT"
] | null | null | null | lib/links.ex | ddidwyll/shorty | b02968d1093c2b61ab21e889ee39850244e4748e | [
"MIT"
] | 1 | 2021-05-10T22:27:20.000Z | 2021-05-10T22:27:20.000Z | lib/links.ex | ddidwyll/shorty | b02968d1093c2b61ab21e889ee39850244e4748e | [
"MIT"
] | null | null | null | alias Links.Link
alias Links.ChangeRequest, as: ChReq
alias Ecto.ConstraintError, as: DBErr
defmodule LinksBehaviour do
@type item :: Link.t() | ChReq.t()
@callback create(item) :: {:ok, item} | {:error, binary}
@callback create(item, boolean) :: {:ok, item} | {:error, binary}
@callback get_link(binary) :: {:ok, Link.t()} | {:error, binary}
@callback get_link(binary, boolean) :: {:ok, Link.t()} | {:error, binary}
@callback instant_change(binary, binary, binary) :: {:ok, Link.t()} | {:error, binary}
@callback request_change(binary, binary, binary) ::
{:ok, ChReq.t(), Link.t()} | {:error, binary}
@callback confirm_request(binary) :: {:ok, Link.t()} | {:error, binary}
@callback cancel_change(binary) :: :ok
@callback expire_requests() :: :ok
end
defmodule Links do
@behaviour LinksBehaviour
import Links.Repo
@impl true
def create(item, auto_id \\ true) do
try do
insert(item)
rescue
e in DBErr ->
if e.type == :unique do
if auto_id, do: create(item), else: {:error, ~s|{"message":"Id taken"}|}
else
{:error, ~s|{"message":"#{e.message}"}|}
end
end
end
@impl true
def get_link(id, confirmed_only \\ true) do
case get(Link, id) do
nil ->
{:error, ~s|{"id":"Link /#{id} not found, maybe it already changed"}|}
link ->
if !confirmed_only || link.confirmed,
do: {:ok, link},
else: {:error, ~s|{"id":"Link /#{id} not confirmed yet"}|}
end
end
defp get_req(token) do
case get(ChReq, token) do
nil -> {:error, ~s|{"token":"Token is expired, maybe link already changed"}|}
ch_req -> {:ok, ch_req}
end
end
defp clone_link(link, new_id) do
new_link = %{link | id: new_id, confirmed: false, confirm_token: nil}
case get_link(new_id, false) do
{:ok, _} -> {:error, ~s|{"id":"Url /#{new_id} taken, choose another"}|}
{:error, _} -> create(new_link, false)
end
end
defp swap_links(old_id, new_id) do
import Ecto.Changeset, only: [change: 2]
fn ->
try do
%Link{id: old_id}
|> delete!()
%Link{id: new_id}
|> change(confirmed: true)
|> update!(returning: true)
rescue
_ ->
cancel_change(new_id)
rollback(~s/{"message":"Something went wrong"}/)
end
end
|> transaction()
end
defp confirmation(link, guess, type) do
import String, only: [split: 2]
import Map, only: [fetch!: 2]
value = fetch!(link, type)
if value && value == guess do
:ok
else
[_, type_str] =
to_string(type)
|> split("_")
{:error, ~s|{"#{type_str}":"Sorry, #{type_str} #{guess} is invalid"}|}
end
end
@impl true
def instant_change(old_id, new_id, token) do
with {:ok, link} <- get_link(old_id),
:ok <- confirmation(link, token, :confirm_token),
{:ok, _} <- clone_link(link, new_id),
{:ok, new_link} <- swap_links(old_id, new_id) do
{:ok, new_link}
end
end
@impl true
def request_change(old_id, new_id, mail) do
with {:ok, link} <- get_link(old_id),
:ok <- confirmation(link, mail, :owner_mail),
{:ok, _} <- clone_link(link, new_id),
{:ok, ch_req} <-
%ChReq{
new_id: new_id,
old_id: old_id
}
|> create() do
{:ok, ch_req, link}
end
end
@impl true
def confirm_request(token) do
with {:ok, req} <- get_req(token),
%{new_id: new, old_id: old} <- req,
{:ok, new_link} <- swap_links(old, new) do
{:ok, new_link}
end
end
@impl true
def cancel_change(new_id) do
delete(%Link{id: new_id})
:ok
end
@impl true
def expire_requests do
import Enum, only: [each: 2]
import Ecto.Query, only: [from: 2]
import Application, only: [get_env: 3]
import NaiveDateTime, only: [utc_now: 0, add: 3]
seconds = get_env(:shorty, :request_expires_sec, 3600)
far_away =
utc_now()
|> add(-seconds, :second)
query =
from(l in ChReq,
where: l.created <= ^far_away,
select: l.new_id
)
all(query)
|> each(&(%Link{id: &1} |> delete))
end
end
| 25.538922 | 88 | 0.565064 |
f719a2f72fe3bb8a1e29510338cbd88e627b3e9f | 14,615 | exs | Elixir | test/teslamate/vehicles/vehicle/suspend_test.exs | normalfaults/teslamate | 9c61150bd5614728447e21789ab6edc5169b631e | [
"MIT"
] | 1 | 2020-05-17T05:05:22.000Z | 2020-05-17T05:05:22.000Z | test/teslamate/vehicles/vehicle/suspend_test.exs | normalfaults/teslamate | 9c61150bd5614728447e21789ab6edc5169b631e | [
"MIT"
] | null | null | null | test/teslamate/vehicles/vehicle/suspend_test.exs | normalfaults/teslamate | 9c61150bd5614728447e21789ab6edc5169b631e | [
"MIT"
] | null | null | null | defmodule TeslaMate.Vehicles.Vehicle.SuspendTest do
use TeslaMate.VehicleCase, async: true
alias TeslaMate.Vehicles.Vehicle
test "suspends when idling", %{test: name} do
suspendable =
online_event(
drive_state: %{timestamp: 0, latitude: 0.0, longitude: 0.0},
climate_state: %{is_preconditioning: false}
)
events = [
{:ok, online_event()},
{:ok, online_event()},
{:ok, suspendable},
{:ok, %TeslaApi.Vehicle{state: "asleep"}}
]
sudpend_after_idle_ms = 1
suspend_ms = 200
:ok =
start_vehicle(name, events,
settings: %{
suspend_after_idle_min: round(sudpend_after_idle_ms / 60),
suspend_min: suspend_ms
}
)
assert_receive {:start_state, car_id, :online}
assert_receive {:insert_position, ^car_id, %{}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online, since: s0}}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :suspended, since: s1}}}
assert DateTime.diff(s0, s1, :nanosecond) < 0
assert_receive {:start_state, ^car_id, :asleep}, round(suspend_ms * 1.1)
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :asleep, since: s2}}}
assert DateTime.diff(s1, s2, :nanosecond) < 0
refute_receive _
end
@tag :capture_log
test "does not suspend if preconditioning", %{test: name} do
not_supendable =
online_event(
drive_state: %{timestamp: 0, latitude: 0.0, longitude: 0.0},
climate_state: %{is_preconditioning: true}
)
events = [
{:ok, online_event()},
{:ok, not_supendable}
]
sudpend_after_idle_ms = 10
suspend_ms = 100
:ok =
start_vehicle(name, events,
settings: %{
suspend_after_idle_min: round(sudpend_after_idle_ms / 60),
suspend_min: suspend_ms
}
)
assert_receive {:start_state, car_id, :online}
assert_receive {:insert_position, ^car_id, %{}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online}}}
refute_receive _, round(suspend_ms * 0.5)
refute_receive _
end
@tag :capture_log
test "does not suspend if user is present", %{test: name} do
not_supendable =
online_event(
drive_state: %{timestamp: 0, latitude: 0.0, longitude: 0.0},
vehicle_state: %{is_user_present: true}
)
events = [
{:ok, online_event()},
{:ok, not_supendable}
]
sudpend_after_idle_ms = 10
suspend_ms = 100
:ok =
start_vehicle(name, events,
settings: %{
suspend_after_idle_min: round(sudpend_after_idle_ms / 60),
suspend_min: suspend_ms
}
)
assert_receive {:start_state, car_id, :online}
assert_receive {:insert_position, ^car_id, %{}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online}}}
refute_receive _, round(suspend_ms * 0.5)
refute_receive _
end
test "does not suspend if sentry mode is active", %{test: name} do
not_supendable =
online_event(
drive_state: %{timestamp: 0, latitude: 0.0, longitude: 0.0},
vehicle_state: %{sentry_mode: true}
)
events = [
{:ok, online_event()},
{:ok, not_supendable}
]
sudpend_after_idle_ms = 10
suspend_ms = 100
:ok =
start_vehicle(name, events,
settings: %{
suspend_after_idle_min: round(sudpend_after_idle_ms / 60),
suspend_min: suspend_ms
}
)
assert_receive {:start_state, car_id, :online}
assert_receive {:insert_position, ^car_id, %{}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online, sentry_mode: true}}}
refute_receive _, round(suspend_ms * 0.5)
refute_receive _
end
test "suspends if charging is complete", %{test: name} do
now = DateTime.utc_now()
now_ts = DateTime.to_unix(now, :millisecond)
events = [
{:ok, online_event()},
{:ok, charging_event(now_ts + 1, "Charging", 0.1)},
{:ok, charging_event(now_ts + 2, "Complete", 0.2)},
{:ok, charging_event(now_ts + 3, "Complete", 0.3)},
{:ok, %TeslaApi.Vehicle{state: "asleep"}}
]
sudpend_after_idle_ms = 1
suspend_ms = 200
:ok =
start_vehicle(name, events,
settings: %{
suspend_after_idle_min: round(sudpend_after_idle_ms / 60),
suspend_min: suspend_ms
}
)
assert_receive {:start_state, car_id, :online}
assert_receive {:insert_position, ^car_id, %{}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online}}}
assert_receive {:start_charging_process, ^car_id, %{date: _, latitude: 0.0, longitude: 0.0},
[]}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :charging}}}
assert_receive {:insert_charge, charge_id, %{date: _, charge_energy_added: 0.1}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :charging_complete}}}
assert_receive {:insert_charge, ^charge_id, %{date: _, charge_energy_added: 0.2}}
assert_receive {:complete_charging_process, ^charge_id, []}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :suspended}}}
assert_receive {:start_state, ^car_id, :asleep}, round(suspend_ms * 1.1)
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :asleep}}}
refute_receive _
end
test "continues charging if suspending wasn't successful", %{test: name} do
now = DateTime.utc_now()
now_ts = DateTime.to_unix(now, :millisecond)
events = [
{:ok, online_event()},
{:ok, charging_event(now_ts + 1, "Charging", 0.1)},
{:ok, charging_event(now_ts + 2, "Complete", 0.15)},
{:ok, charging_event(now_ts + 3, "Complete", 0.15)},
{:ok, charging_event(now_ts + 4, "Complete", 0.15)},
{:ok, charging_event(now_ts + 5, "Charging", 0.2)},
{:ok, charging_event(now_ts + 6, "Charging", 0.3)}
]
sudpend_after_idle_ms = 1
suspend_ms = 200
:ok =
start_vehicle(name, events,
settings: %{
suspend_after_idle_min: round(sudpend_after_idle_ms / 60),
suspend_min: suspend_ms
}
)
assert_receive {:start_state, car_id, :online}
assert_receive {:insert_position, ^car_id, %{}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online}}}
assert_receive {:start_charging_process, ^car_id, %{date: _, latitude: 0.0, longitude: 0.0},
[]}
assert_receive {:insert_charge, charging_event, %{date: _, charge_energy_added: 0.1}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :charging}}}
assert_receive {:insert_charge, ^charging_event, %{date: _, charge_energy_added: 0.15}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :charging_complete}}}
assert_receive {:complete_charging_process, ^charging_event, []}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :suspended}}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :charging}}},
round(suspend_ms * 1.1)
assert_receive {:insert_charge, ^charging_event, %{date: _, charge_energy_added: 0.2}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :charging}}}
assert_receive {:insert_charge, ^charging_event, %{date: _, charge_energy_added: 0.3}}
assert_receive {:resume_charging_process, ^charging_event}
# ...
end
test "broadcasts if vehicle gets (un)locked when idling", %{test: name} do
unlocked =
online_event(
drive_state: %{timestamp: 0, latitude: 0.0, longitude: 0.0},
vehicle_state: %{locked: false}
)
locked =
online_event(
drive_state: %{timestamp: 0, latitude: 0.0, longitude: 0.0},
vehicle_state: %{locked: true}
)
events = [
{:ok, online_event()},
{:ok, unlocked},
{:ok, locked},
{:ok, unlocked},
{:ok, locked}
]
:ok =
start_vehicle(name, events,
settings: %{
suspend_after_idle_min: 100_000,
suspend_min: 1000
}
)
assert_receive {:start_state, car_id, :online}
assert_receive {:insert_position, ^car_id, %{}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online, locked: false}}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online, locked: true}}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online, locked: false}}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online, locked: true}}}
refute_receive _
end
test "broadcasts if sentry mode gets turned on/off", %{test: name} do
sentry_mode_on =
online_event(
drive_state: %{timestamp: 0, latitude: 0.0, longitude: 0.0},
vehicle_state: %{sentry_mode: true}
)
sentry_mode_off =
online_event(
drive_state: %{timestamp: 0, latitude: 0.0, longitude: 0.0},
vehicle_state: %{sentry_mode: false}
)
events = [
{:ok, online_event()},
{:ok, sentry_mode_on},
{:ok, sentry_mode_off},
{:ok, sentry_mode_on},
{:ok, sentry_mode_off}
]
:ok =
start_vehicle(name, events,
settings: %{
suspend_after_idle_min: 100_000,
suspend_min: 1000
}
)
assert_receive {:start_state, car_id, :online}
assert_receive {:insert_position, ^car_id, %{}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online, sentry_mode: true}}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online, sentry_mode: false}}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online, sentry_mode: true}}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online, sentry_mode: false}}}
refute_receive _
end
describe "req_not_unlocked" do
@tag :capture_log
test "does not suspend if vehicle is unlocked", %{test: name} do
not_supendable =
online_event(
drive_state: %{timestamp: 0, latitude: 0.0, longitude: 0.0},
vehicle_state: %{locked: false}
)
events = [
{:ok, online_event()},
{:ok, not_supendable}
]
sudpend_after_idle_ms = 10
suspend_ms = 100
:ok =
start_vehicle(name, events,
settings: %{
req_not_unlocked: true,
suspend_after_idle_min: round(sudpend_after_idle_ms / 60),
suspend_min: suspend_ms
}
)
assert_receive {:start_state, car_id, :online}
assert_receive {:insert_position, ^car_id, %{}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online, locked: false}}}
refute_receive _, round(suspend_ms * 0.5)
refute_receive _
end
@tag :capture_log
test "w/o does suspend if vehicle is unlocked", %{test: name} do
not_supendable =
online_event(
drive_state: %{timestamp: 0, latitude: 0.0, longitude: 0.0},
vehicle_state: %{locked: false}
)
events = [
{:ok, online_event()},
{:ok, not_supendable}
]
sudpend_after_idle_ms = 10
suspend_ms = 100
:ok =
start_vehicle(name, events,
settings: %{
req_not_unlocked: false,
suspend_after_idle_min: round(sudpend_after_idle_ms / 60),
suspend_min: suspend_ms
}
)
assert_receive {:start_state, car_id, :online}
assert_receive {:insert_position, ^car_id, %{}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online, locked: false}}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :suspended, locked: false}}}
refute_receive _
end
end
describe "req_no_shift_state_reading" do
@tag :capture_log
test "does not suspend if shift_state is not nil", %{test: name} do
not_supendable =
online_event(
drive_state: %{timestamp: 0, shift_state: "P", latitude: 0.0, longitude: 0.0}
)
events = [
{:ok, online_event()},
{:ok, not_supendable}
]
sudpend_after_idle_ms = 10
suspend_ms = 100
:ok =
start_vehicle(name, events,
req_no_shift_state_reading: true,
suspend_after_idle_min: round(sudpend_after_idle_ms / 60),
suspend_min: suspend_ms
)
assert_receive {:start_state, car_id, :online}
assert_receive {:insert_position, ^car_id, %{}}
assert_receive {:pubsub, {:broadcast, _server, _topic, %Summary{state: :online}}}
refute_receive _, round(suspend_ms * 0.5)
refute_receive _
end
end
describe "req_no_temp_reading" do
@tag :capture_log
test "does not suspend if outside_temp is not nil", %{test: name} do
not_supendable =
online_event(
drive_state: %{timestamp: 0, latitude: 0.0, longitude: 0.0},
climate_state: %{outside_temp: 20.0}
)
events = [
{:ok, online_event()},
{:ok, not_supendable}
]
sudpend_after_idle_ms = 10
suspend_ms = 100
:ok =
start_vehicle(name, events,
settings: %{
req_no_temp_reading: true,
suspend_after_idle_min: round(sudpend_after_idle_ms / 60),
suspend_min: suspend_ms
}
)
assert_receive {:start_state, car_id, :online}
assert_receive {:insert_position, ^car_id, %{}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online, outside_temp: 20.0}}}
refute_receive _, round(suspend_ms * 0.5)
refute_receive _
end
@tag :capture_log
test "does not suspend if inside_temp is not nil", %{test: name} do
not_supendable =
online_event(
drive_state: %{timestamp: 0, latitude: 0.0, longitude: 0.0},
climate_state: %{inside_temp: 20.0}
)
events = [
{:ok, online_event()},
{:ok, not_supendable}
]
sudpend_after_idle_ms = 10
suspend_ms = 100
:ok =
start_vehicle(name, events,
settings: %{
req_no_temp_reading: true,
suspend_after_idle_min: round(sudpend_after_idle_ms / 60),
suspend_min: suspend_ms
}
)
assert_receive {:start_state, car_id, :online}
assert_receive {:insert_position, ^car_id, %{}}
assert_receive {:pubsub, {:broadcast, _, _, %Summary{state: :online, inside_temp: 20.0}}}
refute_receive _, round(suspend_ms * 0.5)
refute_receive _
end
end
end
| 29.58502 | 96 | 0.612042 |
f719a91a5b808e4357d2c2fb40a6584f9878443e | 83 | ex | Elixir | lib/newslettex_web/views/campaign_contact_event_view.ex | silva96/newslettex | 4876392c9900c0ce169dcdcb9ebb01ab3da83d65 | [
"MIT"
] | null | null | null | lib/newslettex_web/views/campaign_contact_event_view.ex | silva96/newslettex | 4876392c9900c0ce169dcdcb9ebb01ab3da83d65 | [
"MIT"
] | 10 | 2019-07-29T03:03:02.000Z | 2021-05-10T23:59:25.000Z | lib/newslettex_web/views/campaign_contact_event_view.ex | silva96/newslettex | 4876392c9900c0ce169dcdcb9ebb01ab3da83d65 | [
"MIT"
] | null | null | null | defmodule NewslettexWeb.CampaignContactEventView do
use NewslettexWeb, :view
end
| 20.75 | 51 | 0.855422 |
f719aa6ea3bb7dff52102e7b57801da3a1644299 | 1,502 | exs | Elixir | test/lib/code_corps/transition/user_state_test.exs | fikape/code-corps-api | c21674b0b2a19fa26945c94268db8894420ca181 | [
"MIT"
] | 275 | 2015-06-23T00:20:51.000Z | 2021-08-19T16:17:37.000Z | test/lib/code_corps/transition/user_state_test.exs | fikape/code-corps-api | c21674b0b2a19fa26945c94268db8894420ca181 | [
"MIT"
] | 1,304 | 2015-06-26T02:11:54.000Z | 2019-12-12T21:08:00.000Z | test/lib/code_corps/transition/user_state_test.exs | fikape/code-corps-api | c21674b0b2a19fa26945c94268db8894420ca181 | [
"MIT"
] | 140 | 2016-01-01T18:19:47.000Z | 2020-11-22T06:24:47.000Z | defmodule CodeCorps.Transition.UserStateTest do
use ExUnit.Case, async: true
alias CodeCorps.Transition.UserState
describe "next/2" do
test "returns nil if state_transition is nil" do
assert UserState.next("foo", nil) == nil
end
test "returns {:ok, next_state} for valid transitions" do
assert UserState.next("signed_up", "edit_profile") == {:ok, "edited_profile"}
assert UserState.next("edited_profile", "select_categories") == {:ok, "selected_categories"}
assert UserState.next("edited_profile", "skip_categories") == {:ok, "skipped_categories"}
assert UserState.next("selected_categories", "select_roles") == {:ok, "selected_roles"}
assert UserState.next("selected_categories", "skip_roles") == {:ok, "skipped_roles"}
assert UserState.next("skipped_categories", "select_roles") == {:ok, "selected_roles"}
assert UserState.next("skipped_categories", "skip_roles") == {:ok, "skipped_roles"}
assert UserState.next("selected_roles", "select_skills") == {:ok, "selected_skills"}
assert UserState.next("selected_roles", "skip_skills") == {:ok, "skipped_skills"}
assert UserState.next("skipped_roles", "select_skills") == {:ok, "selected_skills"}
assert UserState.next("skipped_roles", "skip_skills") == {:ok, "skipped_skills"}
end
test "returns {:error, message} for invalid transitions" do
assert UserState.next("foo", "bar") == {:error, "invalid transition bar from foo"}
end
end
end
| 42.914286 | 98 | 0.690413 |
f719ac5b895474def6dfce640ae8466186f837d3 | 3,324 | ex | Elixir | clients/dialogflow/lib/google_api/dialogflow/v2/model/google_cloud_dialogflow_v2beta1_knowledge_answers_answer.ex | medikent/elixir-google-api | 98a83d4f7bfaeac15b67b04548711bb7e49f9490 | [
"Apache-2.0"
] | null | null | null | clients/dialogflow/lib/google_api/dialogflow/v2/model/google_cloud_dialogflow_v2beta1_knowledge_answers_answer.ex | medikent/elixir-google-api | 98a83d4f7bfaeac15b67b04548711bb7e49f9490 | [
"Apache-2.0"
] | null | null | null | clients/dialogflow/lib/google_api/dialogflow/v2/model/google_cloud_dialogflow_v2beta1_knowledge_answers_answer.ex | medikent/elixir-google-api | 98a83d4f7bfaeac15b67b04548711bb7e49f9490 | [
"Apache-2.0"
] | null | null | null | # Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE: This file is auto generated by the elixir code generator program.
# Do not edit this file manually.
defmodule GoogleApi.Dialogflow.V2.Model.GoogleCloudDialogflowV2beta1KnowledgeAnswersAnswer do
@moduledoc """
An answer from Knowledge Connector.
## Attributes
* `answer` (*type:* `String.t`, *default:* `nil`) - The piece of text from the `source` knowledge base document that answers
this conversational query.
* `faqQuestion` (*type:* `String.t`, *default:* `nil`) - The corresponding FAQ question if the answer was extracted from a FAQ
Document, empty otherwise.
* `matchConfidence` (*type:* `number()`, *default:* `nil`) - The system's confidence score that this Knowledge answer is a good match
for this conversational query.
The range is from 0.0 (completely uncertain) to 1.0 (completely certain).
Note: The confidence score is likely to vary somewhat (possibly even for
identical requests), as the underlying model is under constant
improvement. It may be deprecated in the future. We recommend using
`match_confidence_level` which should be generally more stable.
* `matchConfidenceLevel` (*type:* `String.t`, *default:* `nil`) - The system's confidence level that this knowledge answer is a good match
for this conversational query.
NOTE: The confidence level for a given `<query, answer>` pair may change
without notice, as it depends on models that are constantly being
improved. However, it will change less frequently than the confidence
score below, and should be preferred for referencing the quality of an
answer.
* `source` (*type:* `String.t`, *default:* `nil`) - Indicates which Knowledge Document this answer was extracted from.
Format: `projects/<Project ID>/knowledgeBases/<Knowledge Base
ID>/documents/<Document ID>`.
"""
use GoogleApi.Gax.ModelBase
@type t :: %__MODULE__{
:answer => String.t(),
:faqQuestion => String.t(),
:matchConfidence => number(),
:matchConfidenceLevel => String.t(),
:source => String.t()
}
field(:answer)
field(:faqQuestion)
field(:matchConfidence)
field(:matchConfidenceLevel)
field(:source)
end
defimpl Poison.Decoder,
for: GoogleApi.Dialogflow.V2.Model.GoogleCloudDialogflowV2beta1KnowledgeAnswersAnswer do
def decode(value, options) do
GoogleApi.Dialogflow.V2.Model.GoogleCloudDialogflowV2beta1KnowledgeAnswersAnswer.decode(
value,
options
)
end
end
defimpl Poison.Encoder,
for: GoogleApi.Dialogflow.V2.Model.GoogleCloudDialogflowV2beta1KnowledgeAnswersAnswer do
def encode(value, options) do
GoogleApi.Gax.ModelBase.encode(value, options)
end
end
| 41.55 | 142 | 0.72142 |
f719f62ec2a782af39af10b7bbefe72115ee4d50 | 1,299 | ex | Elixir | clients/cloud_deploy/lib/google_api/cloud_deploy/v1/model/cancel_operation_request.ex | renovate-bot/elixir-google-api | 1da34cd39b670c99f067011e05ab90af93fef1f6 | [
"Apache-2.0"
] | 1 | 2021-12-20T03:40:53.000Z | 2021-12-20T03:40:53.000Z | clients/cloud_deploy/lib/google_api/cloud_deploy/v1/model/cancel_operation_request.ex | swansoffiee/elixir-google-api | 9ea6d39f273fb430634788c258b3189d3613dde0 | [
"Apache-2.0"
] | 1 | 2020-08-18T00:11:23.000Z | 2020-08-18T00:44:16.000Z | clients/cloud_deploy/lib/google_api/cloud_deploy/v1/model/cancel_operation_request.ex | dazuma/elixir-google-api | 6a9897168008efe07a6081d2326735fe332e522c | [
"Apache-2.0"
] | null | null | null | # Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE: This file is auto generated by the elixir code generator program.
# Do not edit this file manually.
defmodule GoogleApi.CloudDeploy.V1.Model.CancelOperationRequest do
@moduledoc """
The request message for Operations.CancelOperation.
## Attributes
"""
use GoogleApi.Gax.ModelBase
@type t :: %__MODULE__{}
end
defimpl Poison.Decoder, for: GoogleApi.CloudDeploy.V1.Model.CancelOperationRequest do
def decode(value, options) do
GoogleApi.CloudDeploy.V1.Model.CancelOperationRequest.decode(value, options)
end
end
defimpl Poison.Encoder, for: GoogleApi.CloudDeploy.V1.Model.CancelOperationRequest do
def encode(value, options) do
GoogleApi.Gax.ModelBase.encode(value, options)
end
end
| 30.928571 | 85 | 0.769053 |
f71a0300f7c4e4f2c2596cb63a5a4432da99bcc7 | 871 | exs | Elixir | deps/decimal/mix.exs | rpillar/Top5_Elixir | 9c450d2e9b291108ff1465dc066dfe442dbca822 | [
"MIT"
] | null | null | null | deps/decimal/mix.exs | rpillar/Top5_Elixir | 9c450d2e9b291108ff1465dc066dfe442dbca822 | [
"MIT"
] | null | null | null | deps/decimal/mix.exs | rpillar/Top5_Elixir | 9c450d2e9b291108ff1465dc066dfe442dbca822 | [
"MIT"
] | null | null | null | defmodule Decimal.Mixfile do
use Mix.Project
@version "1.6.0"
def project() do
[
app: :decimal,
version: @version,
elixir: "~> 1.0",
deps: deps(),
name: "Decimal",
source_url: "https://github.com/ericmj/decimal",
docs: [source_ref: "v#{@version}", main: "readme", extras: ["README.md"]],
description: description(),
package: package()
]
end
def application() do
[]
end
defp deps() do
[
{:ex_doc, ">= 0.0.0", only: :dev},
{:earmark, ">= 0.0.0", only: :dev}
]
end
defp description() do
"Arbitrary precision decimal arithmetic."
end
defp package() do
[
maintainers: ["Eric Meadows-Jönsson"],
licenses: ["Apache 2.0"],
links: %{"GitHub" => "https://github.com/ericmj/decimal"}
]
end
end
| 20.255814 | 81 | 0.522388 |
f71a3830bc3acddf3e65df064ce69f09e57f78be | 1,242 | ex | Elixir | wsf_c/build/packaging/debian/emacsen-install.ex | michaelarnauts/wso-wsf-php | 48d05363fe70ffd51b159b957bf00c4128d8d615 | [
"Apache-2.0"
] | 1 | 2021-12-02T13:43:00.000Z | 2021-12-02T13:43:00.000Z | wsf_c/build/packaging/debian/emacsen-install.ex | michaelarnauts/wso-wsf-php | 48d05363fe70ffd51b159b957bf00c4128d8d615 | [
"Apache-2.0"
] | null | null | null | wsf_c/build/packaging/debian/emacsen-install.ex | michaelarnauts/wso-wsf-php | 48d05363fe70ffd51b159b957bf00c4128d8d615 | [
"Apache-2.0"
] | 4 | 2017-03-21T15:27:57.000Z | 2021-05-27T11:20:00.000Z | #! /bin/sh -e
# /usr/lib/emacsen-common/packages/install/wso2-wsf-c
# Written by Jim Van Zandt <[email protected]>, borrowing heavily
# from the install scripts for gettext by Santiago Vila
# <[email protected]> and octave by Dirk Eddelbuettel <[email protected]>.
FLAVOR=$1
PACKAGE=wso2-wsf-c
if [ ${FLAVOR} = emacs ]; then exit 0; fi
echo install/${PACKAGE}: Handling install for emacsen flavor ${FLAVOR}
#FLAVORTEST=`echo $FLAVOR | cut -c-6`
#if [ ${FLAVORTEST} = xemacs ] ; then
# SITEFLAG="-no-site-file"
#else
# SITEFLAG="--no-site-file"
#fi
FLAGS="${SITEFLAG} -q -batch -l path.el -f batch-byte-compile"
ELDIR=/usr/share/emacs/site-lisp/${PACKAGE}
ELCDIR=/usr/share/${FLAVOR}/site-lisp/${PACKAGE}
# Install-info-altdir does not actually exist.
# Maybe somebody will write it.
if test -x /usr/sbin/install-info-altdir; then
echo install/${PACKAGE}: install Info links for ${FLAVOR}
install-info-altdir --quiet --section "" "" --dirname=${FLAVOR} /usr/share/info/${PACKAGE}.info.gz
fi
install -m 755 -d ${ELCDIR}
cd ${ELDIR}
FILES=`echo *.el`
cp ${FILES} ${ELCDIR}
cd ${ELCDIR}
cat << EOF > path.el
(setq load-path (cons "." load-path) byte-compile-warnings nil)
EOF
${FLAVOR} ${FLAGS} ${FILES}
rm -f *.el path.el
exit 0
| 27 | 102 | 0.685185 |
f71a3cf0e9c54f913e77dc323db5fe4b9fb4fa5f | 945 | ex | Elixir | lib/postgrex/extensions/line_segment.ex | activeprospect/postgrex | d267e419de5db61ac8705210dec8527e4bf94a84 | [
"Apache-2.0"
] | null | null | null | lib/postgrex/extensions/line_segment.ex | activeprospect/postgrex | d267e419de5db61ac8705210dec8527e4bf94a84 | [
"Apache-2.0"
] | 1 | 2020-07-17T10:07:44.000Z | 2020-07-17T10:07:44.000Z | lib/postgrex/extensions/line_segment.ex | activeprospect/postgrex | d267e419de5db61ac8705210dec8527e4bf94a84 | [
"Apache-2.0"
] | null | null | null | defmodule Postgrex.Extensions.LineSegment do
@moduledoc false
import Postgrex.BinaryUtils, warn: false
use Postgrex.BinaryExtension, send: "lseg_send"
alias Postgrex.Extensions.Point
def encode(_) do
quote location: :keep do
%Postgrex.LineSegment{point1: p1, point2: p2} ->
encoded_p1 = Point.encode_point(p1, Postgrex.LineSegment)
encoded_p2 = Point.encode_point(p2, Postgrex.LineSegment)
# 2 points -> 16 bytes each
[<<32::int32>>, encoded_p1 | encoded_p2]
other ->
raise DBConnection.EncodeError, Postgrex.Utils.encode_msg(other, Postgrex.Line)
end
end
def decode(_) do
quote location: :keep do
# 2 points -> 16 bytes each
<<32::int32, x1::float64, y1::float64, x2::float64, y2::float64>> ->
p1 = %Postgrex.Point{x: x1, y: y1}
p2 = %Postgrex.Point{x: x2, y: y2}
%Postgrex.LineSegment{point1: p1, point2: p2}
end
end
end
| 32.586207 | 87 | 0.655026 |
f71aa4a0518cc983d216dd5a570dd9d274c957ea | 664 | ex | Elixir | xarb/test/support/fixtures/accounts_fixtures.ex | Erik-joh/examensarbete | 951847f0ee5195abc0e3aa5f2b6fff78233127ee | [
"MIT"
] | null | null | null | xarb/test/support/fixtures/accounts_fixtures.ex | Erik-joh/examensarbete | 951847f0ee5195abc0e3aa5f2b6fff78233127ee | [
"MIT"
] | null | null | null | xarb/test/support/fixtures/accounts_fixtures.ex | Erik-joh/examensarbete | 951847f0ee5195abc0e3aa5f2b6fff78233127ee | [
"MIT"
] | null | null | null | defmodule Xarb.AccountsFixtures do
@moduledoc """
This module defines test helpers for creating
entities via the `Xarb.Accounts` context.
"""
def unique_user_email, do: "user#{System.unique_integer()}@example.com"
def valid_user_password, do: "hello world!"
def user_fixture(attrs \\ %{}) do
{:ok, user} =
attrs
|> Enum.into(%{
email: unique_user_email(),
password: valid_user_password()
})
|> Xarb.Accounts.register_user()
user
end
def extract_user_token(fun) do
{:ok, captured} = fun.(&"[TOKEN]#{&1}[TOKEN]")
[_, token, _] = String.split(captured.body, "[TOKEN]")
token
end
end
| 23.714286 | 73 | 0.63253 |
f71ac152405f06866ddb9adbb6e47eb928e67bab | 425 | exs | Elixir | integration_test/support/types.exs | larryweya/ecto | d0d1fd43f0f97856a119184163167a7e79574923 | [
"Apache-2.0"
] | 64 | 2015-06-03T09:48:13.000Z | 2020-04-25T08:39:49.000Z | integration_test/support/types.exs | larryweya/ecto | d0d1fd43f0f97856a119184163167a7e79574923 | [
"Apache-2.0"
] | 70 | 2015-02-13T14:00:13.000Z | 2021-09-15T10:40:01.000Z | integration_test/support/types.exs | larryweya/ecto | d0d1fd43f0f97856a119184163167a7e79574923 | [
"Apache-2.0"
] | 50 | 2015-02-13T13:55:47.000Z | 2020-03-03T15:34:13.000Z | defmodule Custom.Permalink do
def type, do: :id
def cast(string) when is_binary(string) do
case Integer.parse(string) do
{int, _} -> {:ok, int}
:error -> :error
end
end
def cast(integer) when is_integer(integer), do: {:ok, integer}
def cast(_), do: :error
def load(integer) when is_integer(integer), do: {:ok, integer}
def dump(integer) when is_integer(integer), do: {:ok, integer}
end
| 25 | 64 | 0.649412 |
f71acee3d1c59ebece06a53e9345420d86d7327c | 1,603 | exs | Elixir | test/integration/atom_keys_test.exs | lexmag/xandra | eadd1be7fa36a0973c2b7fe525fe5aaba2ce264d | [
"0BSD"
] | null | null | null | test/integration/atom_keys_test.exs | lexmag/xandra | eadd1be7fa36a0973c2b7fe525fe5aaba2ce264d | [
"0BSD"
] | null | null | null | test/integration/atom_keys_test.exs | lexmag/xandra | eadd1be7fa36a0973c2b7fe525fe5aaba2ce264d | [
"0BSD"
] | null | null | null | defmodule AtomKeysTest do
use XandraTest.IntegrationCase, async: true, start_options: [atom_keys: true]
alias Xandra.{SchemaChange, SetKeyspace, Void}
@moduletag :cassandra_specific
test "each possible result and prepared", %{conn: conn, keyspace: keyspace} do
result = Xandra.execute!(conn, "USE #{keyspace}")
assert result == %SetKeyspace{keyspace: String.downcase(keyspace)}
statement = "CREATE TABLE numbers_atom_keys (figure int PRIMARY KEY)"
result = Xandra.execute!(conn, statement)
assert result == %SchemaChange{
effect: "CREATED",
options: %{
keyspace: String.downcase(keyspace),
subject: "numbers_atom_keys"
},
target: "TABLE"
}
statement = "INSERT INTO numbers_atom_keys (figure) VALUES (?)"
result = Xandra.execute!(conn, statement, %{figure: {"int", 123}})
assert result == %Void{}
statement = "SELECT * FROM numbers_atom_keys WHERE figure = ?"
result = Xandra.execute!(conn, statement, [{"int", 123}])
assert Enum.to_list(result) == [%{figure: 123}]
result = Xandra.execute!(conn, statement, [{"int", 321}])
assert Enum.to_list(result) == []
statement = "SELECT * FROM #{keyspace}.numbers_atom_keys WHERE figure = :figure"
result = Xandra.execute!(conn, statement, %{"figure" => {"int", 123}})
assert Enum.to_list(result) == [%{figure: 123}]
prepared = Xandra.prepare!(conn, statement)
result = Xandra.execute!(conn, prepared, %{figure: 123})
assert Enum.to_list(result) == [%{figure: 123}]
end
end
| 36.431818 | 84 | 0.641921 |
f71ad88c58b3ac4548804bafc7445d07c4d88a2f | 2,055 | ex | Elixir | clients/run/lib/google_api/run/v1/model/configuration_spec.ex | medikent/elixir-google-api | 98a83d4f7bfaeac15b67b04548711bb7e49f9490 | [
"Apache-2.0"
] | null | null | null | clients/run/lib/google_api/run/v1/model/configuration_spec.ex | medikent/elixir-google-api | 98a83d4f7bfaeac15b67b04548711bb7e49f9490 | [
"Apache-2.0"
] | null | null | null | clients/run/lib/google_api/run/v1/model/configuration_spec.ex | medikent/elixir-google-api | 98a83d4f7bfaeac15b67b04548711bb7e49f9490 | [
"Apache-2.0"
] | null | null | null | # Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE: This file is auto generated by the elixir code generator program.
# Do not edit this file manually.
defmodule GoogleApi.Run.V1.Model.ConfigurationSpec do
@moduledoc """
ConfigurationSpec holds the desired state of the Configuration (from the
client).
## Attributes
* `template` (*type:* `GoogleApi.Run.V1.Model.RevisionTemplate.t`, *default:* `nil`) - Optional metadata for this Revision, including labels and annotations. Name
will be generated by the Configuration.
To set minimum instances for this revision, use the
"autoscaling.knative.dev/minScale" annotation key. (Cloud Run for Anthos
only). To set maximum instances for this revision, use the
"autoscaling.knative.dev/maxScale" annotation key.
To set Cloud SQL connections for the revision, use the
"run.googleapis.com/cloudsql-instances" annotation key. Values should be
comma separated.
"""
use GoogleApi.Gax.ModelBase
@type t :: %__MODULE__{
:template => GoogleApi.Run.V1.Model.RevisionTemplate.t()
}
field(:template, as: GoogleApi.Run.V1.Model.RevisionTemplate)
end
defimpl Poison.Decoder, for: GoogleApi.Run.V1.Model.ConfigurationSpec do
def decode(value, options) do
GoogleApi.Run.V1.Model.ConfigurationSpec.decode(value, options)
end
end
defimpl Poison.Encoder, for: GoogleApi.Run.V1.Model.ConfigurationSpec do
def encode(value, options) do
GoogleApi.Gax.ModelBase.encode(value, options)
end
end
| 36.696429 | 166 | 0.742579 |
f71ae1c20e979a08f5b6598ab07c721108493c42 | 1,203 | exs | Elixir | mix.exs | egillet/ueberauth_cas | 9c546226e59eace0504a275431710ec67d8e0370 | [
"MIT"
] | null | null | null | mix.exs | egillet/ueberauth_cas | 9c546226e59eace0504a275431710ec67d8e0370 | [
"MIT"
] | null | null | null | mix.exs | egillet/ueberauth_cas | 9c546226e59eace0504a275431710ec67d8e0370 | [
"MIT"
] | null | null | null | defmodule UeberauthCAS.Mixfile do
use Mix.Project
@version "1.1.0"
@url "https://github.com/marceldegraaf/ueberauth_cas"
def project do
[
app: :ueberauth_cas,
version: @version,
elixir: "~> 1.2",
name: "Ueberauth CAS strategy",
package: package(),
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
source_url: @url,
homepage_url: @url,
description: "An Ueberauth strategy for CAS authentication.",
deps: deps(),
test_coverage: [tool: ExCoveralls],
]
end
def application do
[
applications: [:logger, :ueberauth, :httpoison]
]
end
defp deps do
[
{:ueberauth, "~> 0.6.2"},
{:httpoison, "~> 1.0"},
{:sweet_xml, "~> 0.6.6"},
{:excoveralls, "~> 0.12.2", only: :test},
{:inch_ex, "~> 0.5.6", only: :docs},
{:earmark, "~> 1.4.3", only: :dev},
{:ex_doc, "~> 0.21.2", only: :dev},
{:mock, "~> 0.3.4", only: :test},
]
end
defp package do
[
files: ["lib", "mix.exs", "README.md", "LICENSE.md"],
maintainers: ["Marcel de Graaf"],
licenses: ["MIT"],
links: %{"GitHub": @url}
]
end
end
| 23.134615 | 67 | 0.533666 |
f71b447f4a92e1e71a237324721dbc333c20d867 | 864 | ex | Elixir | apps/tai/lib/tai/venue_adapters/okex.ex | CalebOts/tai | 1603bfefa390eac89085ba18fd259b2e9fcac6c0 | [
"MIT"
] | 1 | 2019-12-19T05:16:26.000Z | 2019-12-19T05:16:26.000Z | apps/tai/lib/tai/venue_adapters/okex.ex | CalebOts/tai | 1603bfefa390eac89085ba18fd259b2e9fcac6c0 | [
"MIT"
] | null | null | null | apps/tai/lib/tai/venue_adapters/okex.ex | CalebOts/tai | 1603bfefa390eac89085ba18fd259b2e9fcac6c0 | [
"MIT"
] | null | null | null | defmodule Tai.VenueAdapters.OkEx do
alias Tai.VenueAdapters.OkEx.{
StreamSupervisor,
Products,
AssetBalances,
Positions,
MakerTakerFees,
CreateOrder,
CancelOrder
}
@behaviour Tai.Venues.Adapter
def stream_supervisor, do: StreamSupervisor
defdelegate products(venue_id), to: Products
defdelegate asset_balances(venue_id, account_id, credentials), to: AssetBalances
defdelegate maker_taker_fees(venue_id, account_id, credentials), to: MakerTakerFees
defdelegate positions(venue_id, account_id, credentials), to: Positions
defdelegate create_order(order, credentials), to: CreateOrder
def amend_order(_order, _attrs, _credentials), do: {:error, :not_supported}
def amend_bulk_orders(_orders_with_attrs, _credentials), do: {:error, :not_supported}
defdelegate cancel_order(order, credentials), to: CancelOrder
end
| 36 | 87 | 0.780093 |
f71b5299c15825558ab2c63ae90169c1d7dc0a58 | 960 | exs | Elixir | test/integration/sign_in_test.exs | KazuCocoa/ex_torello | 187d814094f79a3d99bca2746683804333d40dfe | [
"MIT"
] | null | null | null | test/integration/sign_in_test.exs | KazuCocoa/ex_torello | 187d814094f79a3d99bca2746683804333d40dfe | [
"MIT"
] | null | null | null | test/integration/sign_in_test.exs | KazuCocoa/ex_torello | 187d814094f79a3d99bca2746683804333d40dfe | [
"MIT"
] | null | null | null | defmodule ExTrello.SignInTest do
use ExTrello.IntegrationCase
@tag :integration
test "GET /" do
navigate_to "/"
assert page_title == "Sign in | Phoenix Trello"
assert element_displayed?({:id, "sign_in_form"})
end
@tag :integration
test "Sign in with wrong email/password" do
navigate_to "/"
assert element_displayed?({:id, "sign_in_form"})
sign_in_form = find_element(:id, "sign_in_form")
sign_in_form
|> find_within_element(:id, "user_email")
|> fill_field("[email protected]")
sign_in_form
|> find_within_element(:css, "button")
|> click
assert element_displayed?({:class, "error"})
assert page_source =~ "Invalid email or password"
end
@tag :integration
test "Sign in with existing email/password" do
user = create_user
user_sign_in(%{user: user})
assert page_source =~ "#{user.first_name} #{user.last_name}"
assert page_source =~ "My boards"
end
end
| 22.325581 | 64 | 0.676042 |
f71b719aacc4d5799d663632de40b8f5772066c8 | 1,133 | exs | Elixir | apps/gen_rtmp_server/config/config.exs | Kabie/elixir-media-libs | 9750c6dcdffdf8014183a6a4f303c5d0d658f062 | [
"MIT"
] | 75 | 2016-12-23T14:37:18.000Z | 2021-04-26T14:07:20.000Z | apps/gen_rtmp_server/config/config.exs | Kabie/elixir-media-libs | 9750c6dcdffdf8014183a6a4f303c5d0d658f062 | [
"MIT"
] | 19 | 2016-12-22T03:20:43.000Z | 2020-06-11T12:10:37.000Z | apps/gen_rtmp_server/config/config.exs | Kabie/elixir-media-libs | 9750c6dcdffdf8014183a6a4f303c5d0d658f062 | [
"MIT"
] | 3 | 2018-03-29T06:40:40.000Z | 2019-02-13T09:37:19.000Z | # This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for
# 3rd-party users, it should be done in your "mix.exs" file.
# You can configure for your application as:
#
# config :gen_rtmp_server, key: :value
#
# And access this configuration in your application as:
#
# Application.get_env(:gen_rtmp_server, :key)
#
# Or configure a 3rd-party app:
#
# config :logger, level: :info
#
# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
# import_config "#{Mix.env}.exs"
| 36.548387 | 73 | 0.754634 |
f71b74273ef13ecf5a25f722b9343f74149a1237 | 1,976 | ex | Elixir | lib/prm/global_parameters/global_parameters.ex | EDENLABLLC/prm.api | 86743f26874f47ce3d48010ccf5d2cd596a3474b | [
"Apache-2.0"
] | 1 | 2017-07-27T16:03:28.000Z | 2017-07-27T16:03:28.000Z | lib/prm/global_parameters/global_parameters.ex | EDENLABLLC/prm.api | 86743f26874f47ce3d48010ccf5d2cd596a3474b | [
"Apache-2.0"
] | null | null | null | lib/prm/global_parameters/global_parameters.ex | EDENLABLLC/prm.api | 86743f26874f47ce3d48010ccf5d2cd596a3474b | [
"Apache-2.0"
] | null | null | null | defmodule PRM.GlobalParameters do
@moduledoc """
The boundary for the Global parameters system.
"""
import Ecto.{Query, Changeset}, warn: false
alias PRM.Repo
alias PRM.GlobalParameters.GlobalParameter
def list_global_parameters do
query = from gp in GlobalParameter,
order_by: [desc: :inserted_at]
Repo.all(query)
end
def create_global_parameter(attrs, user_id) do
%GlobalParameter{}
|> global_parameter_changeset(attrs)
|> Repo.insert_and_log(user_id)
end
def update_global_parameter(%GlobalParameter{} = global_parameter, attrs, user_id) do
global_parameter
|> global_parameter_changeset(attrs)
|> Repo.update_and_log(user_id)
end
def create_or_update_global_parameters(params, x_consumer_id) do
result =
params
|> Map.keys()
|> Enum.reduce_while(nil, fn(x, _acc) -> process_global_parameters(x, params, x_consumer_id) end)
case result do
nil -> {:ok, list_global_parameters()}
error -> error
end
end
defp process_global_parameters(x, params, x_consumer_id) do
case create_or_update_global_parameters(x, Map.get(params, x), x_consumer_id) do
{:ok, _} -> {:cont, nil}
{:error, _} = error -> {:halt, error}
end
end
defp create_or_update_global_parameters(key, value, x_consumer_id) do
case Repo.get_by(GlobalParameter, parameter: key) do
%GlobalParameter{} = global_parameter ->
update_global_parameter(global_parameter, %{value: value, updated_by: x_consumer_id}, x_consumer_id)
nil ->
create_global_parameter(%{parameter: key, value: value, inserted_by: x_consumer_id, updated_by: x_consumer_id},
x_consumer_id)
end
end
defp global_parameter_changeset(%GlobalParameter{} = global_paramter, attrs) do
fields = ~W(
parameter
value
inserted_by
updated_by
)a
global_paramter
|> cast(attrs, fields)
|> validate_required(fields)
end
end
| 27.444444 | 119 | 0.697368 |
f71ba4a2b4a11bdde723ec82ba6bd340577a96c5 | 2,132 | ex | Elixir | clients/security_center/lib/google_api/security_center/v1/model/audit_log_config.ex | medikent/elixir-google-api | 98a83d4f7bfaeac15b67b04548711bb7e49f9490 | [
"Apache-2.0"
] | null | null | null | clients/security_center/lib/google_api/security_center/v1/model/audit_log_config.ex | medikent/elixir-google-api | 98a83d4f7bfaeac15b67b04548711bb7e49f9490 | [
"Apache-2.0"
] | null | null | null | clients/security_center/lib/google_api/security_center/v1/model/audit_log_config.ex | medikent/elixir-google-api | 98a83d4f7bfaeac15b67b04548711bb7e49f9490 | [
"Apache-2.0"
] | null | null | null | # Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE: This file is auto generated by the elixir code generator program.
# Do not edit this file manually.
defmodule GoogleApi.SecurityCenter.V1.Model.AuditLogConfig do
@moduledoc """
Provides the configuration for logging a type of permissions.
Example:
{
"audit_log_configs": [
{
"log_type": "DATA_READ",
"exempted_members": [
"user:[email protected]"
]
},
{
"log_type": "DATA_WRITE",
}
]
}
This enables 'DATA_READ' and 'DATA_WRITE' logging, while exempting
[email protected] from DATA_READ logging.
## Attributes
* `exemptedMembers` (*type:* `list(String.t)`, *default:* `nil`) - Specifies the identities that do not cause logging for this type of
permission.
Follows the same format of Binding.members.
* `logType` (*type:* `String.t`, *default:* `nil`) - The log type that this config enables.
"""
use GoogleApi.Gax.ModelBase
@type t :: %__MODULE__{
:exemptedMembers => list(String.t()),
:logType => String.t()
}
field(:exemptedMembers, type: :list)
field(:logType)
end
defimpl Poison.Decoder, for: GoogleApi.SecurityCenter.V1.Model.AuditLogConfig do
def decode(value, options) do
GoogleApi.SecurityCenter.V1.Model.AuditLogConfig.decode(value, options)
end
end
defimpl Poison.Encoder, for: GoogleApi.SecurityCenter.V1.Model.AuditLogConfig do
def encode(value, options) do
GoogleApi.Gax.ModelBase.encode(value, options)
end
end
| 30.457143 | 138 | 0.679174 |
f71bc39f6ec90da6871f5a348d9a6b5caa23121b | 187 | ex | Elixir | lib/find_site_icon/icon_info.ex | XukuLLC/find_site_icon | 08333585f48bfaf742e50f804bbd373f2e9e02b8 | [
"MIT"
] | 1 | 2021-03-11T17:45:43.000Z | 2021-03-11T17:45:43.000Z | lib/find_site_icon/icon_info.ex | Victoria91/find_site_icon | de7514df059725dcfd932123bdf4b4150b6e9100 | [
"MIT"
] | 1 | 2021-03-12T03:18:41.000Z | 2021-03-12T03:18:41.000Z | lib/find_site_icon/icon_info.ex | Victoria91/find_site_icon | de7514df059725dcfd932123bdf4b4150b6e9100 | [
"MIT"
] | 2 | 2021-03-22T13:11:18.000Z | 2021-04-12T10:21:04.000Z | defmodule FindSiteIcon.IconInfo do
@moduledoc """
The basic icon struct, holding all the info we need for an icon
"""
defstruct url: nil, expiration_timestamp: nil, size: nil
end
| 26.714286 | 65 | 0.737968 |
f71bce9a6bcae3fc373150dfe554d37e8a20a595 | 1,071 | ex | Elixir | test/support/ets_cache_mock.ex | dweremeichik/pow | 8c45624c1bf40487680abf5a077549fad2de2141 | [
"MIT"
] | null | null | null | test/support/ets_cache_mock.ex | dweremeichik/pow | 8c45624c1bf40487680abf5a077549fad2de2141 | [
"MIT"
] | null | null | null | test/support/ets_cache_mock.ex | dweremeichik/pow | 8c45624c1bf40487680abf5a077549fad2de2141 | [
"MIT"
] | 1 | 2020-07-13T01:11:17.000Z | 2020-07-13T01:11:17.000Z | defmodule Pow.Test.EtsCacheMock do
@moduledoc false
@tab __MODULE__
def init, do: :ets.new(@tab, [:set, :protected, :named_table])
def get(config, key) do
ets_key = ets_key(config, key)
@tab
|> :ets.lookup(ets_key)
|> case do
[{^ets_key, value} | _rest] -> value
[] -> :not_found
end
end
def delete(config, key) do
:ets.delete(@tab, ets_key(config, key))
end
def put(config, key, value) do
:ets.insert(@tab, {ets_key(config, key), value})
end
def keys(config) do
namespace = ets_key(config, "")
length = String.length(namespace)
Stream.resource(
fn -> :ets.first(@tab) end,
fn :"$end_of_table" -> {:halt, nil}
previous_key -> {[previous_key], :ets.next(@tab, previous_key)} end,
fn _ -> :ok
end)
|> Enum.filter(&String.starts_with?(&1, namespace))
|> Enum.map(&String.slice(&1, length..-1))
end
defp ets_key(config, key) do
namespace = Pow.Config.get(config, :namespace, "cache")
"#{namespace}:#{key}"
end
end
| 23.282609 | 76 | 0.586368 |
f71bd6267527b93aeb63a16960e469ea9e18efdf | 74,474 | ex | Elixir | bench/lib/datasets/google_message3/benchmark_message3_1.pb.ex | redink/protobuf | 9f3e443ba2f0e808aae8ae075ffb7abeeca75483 | [
"MIT"
] | 4 | 2021-01-16T02:21:44.000Z | 2022-03-04T18:42:18.000Z | bench/lib/datasets/google_message3/benchmark_message3_1.pb.ex | redink/protobuf | 9f3e443ba2f0e808aae8ae075ffb7abeeca75483 | [
"MIT"
] | 5 | 2020-04-07T20:22:38.000Z | 2020-09-23T02:28:36.000Z | bench/lib/datasets/google_message3/benchmark_message3_1.pb.ex | redink/protobuf | 9f3e443ba2f0e808aae8ae075ffb7abeeca75483 | [
"MIT"
] | 4 | 2020-07-22T23:38:34.000Z | 2021-03-26T18:52:54.000Z | defmodule Benchmarks.GoogleMessage3.Message34390 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field34452: [Benchmarks.GoogleMessage3.Message34387.t()]
}
defstruct [:field34452]
field :field34452, 1, repeated: true, type: Benchmarks.GoogleMessage3.Message34387
end
defmodule Benchmarks.GoogleMessage3.Message34624 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field34683: Benchmarks.GoogleMessage3.Message34621.t() | nil,
field34684: Benchmarks.GoogleMessage3.Message34621.t() | nil
}
defstruct [:field34683, :field34684]
field :field34683, 1, optional: true, type: Benchmarks.GoogleMessage3.Message34621
field :field34684, 2, optional: true, type: Benchmarks.GoogleMessage3.Message34621
end
defmodule Benchmarks.GoogleMessage3.Message34791.Message34792 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field34808: String.t(),
field34809: String.t()
}
defstruct [:field34808, :field34809]
field :field34808, 3, required: true, type: :string
field :field34809, 4, optional: true, type: :string
end
defmodule Benchmarks.GoogleMessage3.Message34791 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field34793: non_neg_integer,
message34792: [any],
field34795: integer,
field34796: integer,
field34797: integer,
field34798: integer,
field34799: integer,
field34800: integer,
field34801: boolean,
field34802: float | :infinity | :negative_infinity | :nan,
field34803: integer,
field34804: String.t(),
field34805: integer,
field34806: [non_neg_integer]
}
defstruct [
:field34793,
:message34792,
:field34795,
:field34796,
:field34797,
:field34798,
:field34799,
:field34800,
:field34801,
:field34802,
:field34803,
:field34804,
:field34805,
:field34806
]
field :field34793, 1, optional: true, type: :fixed64
field :message34792, 2, repeated: true, type: :group
field :field34795, 5, optional: true, type: :int32
field :field34796, 6, optional: true, type: :int32
field :field34797, 7, optional: true, type: :int32
field :field34798, 8, optional: true, type: :int32
field :field34799, 9, optional: true, type: :int32
field :field34800, 10, optional: true, type: :int32
field :field34801, 11, optional: true, type: :bool
field :field34802, 12, optional: true, type: :float
field :field34803, 13, optional: true, type: :int32
field :field34804, 14, optional: true, type: :string
field :field34805, 15, optional: true, type: :int64
field :field34806, 17, repeated: true, type: :fixed64, packed: true
end
defmodule Benchmarks.GoogleMessage3.Message35483 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field35499: integer,
field35500: String.t(),
field35501: String.t(),
field35502: String.t(),
field35503: [Benchmarks.GoogleMessage3.Message35476.t()],
field35504: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil
}
defstruct [:field35499, :field35500, :field35501, :field35502, :field35503, :field35504]
field :field35499, 1, optional: true, type: :int32
field :field35500, 2, optional: true, type: :string
field :field35501, 3, optional: true, type: :string
field :field35502, 4, optional: true, type: :string
field :field35503, 5, repeated: true, type: Benchmarks.GoogleMessage3.Message35476
field :field35504, 6, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
end
defmodule Benchmarks.GoogleMessage3.Message35807 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field35810: integer,
field35811: integer,
field35812: integer,
field35813: integer,
field35814: integer,
field35815: integer,
field35816: integer,
field35817: integer
}
defstruct [
:field35810,
:field35811,
:field35812,
:field35813,
:field35814,
:field35815,
:field35816,
:field35817
]
field :field35810, 1, optional: true, type: :int32
field :field35811, 2, optional: true, type: :int32
field :field35812, 3, optional: true, type: :int32
field :field35813, 4, optional: true, type: :int32
field :field35814, 5, optional: true, type: :int32
field :field35815, 6, optional: true, type: :int32
field :field35816, 7, optional: true, type: :int32
field :field35817, 8, optional: true, type: :int32
end
defmodule Benchmarks.GoogleMessage3.Message37487 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field37501: binary,
field37502: boolean
}
defstruct [:field37501, :field37502]
field :field37501, 2, optional: true, type: :bytes
field :field37502, 3, optional: true, type: :bool
end
defmodule Benchmarks.GoogleMessage3.Message13062 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field13075: integer,
field13076: String.t(),
field13077: integer,
field13078: String.t(),
field13079: integer
}
defstruct [:field13075, :field13076, :field13077, :field13078, :field13079]
field :field13075, 1, optional: true, type: :int64
field :field13076, 2, optional: true, type: :string
field :field13077, 3, optional: true, type: :int32
field :field13078, 4, optional: true, type: :string
field :field13079, 5, optional: true, type: :int32
end
defmodule Benchmarks.GoogleMessage3.Message952 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field963: [Benchmarks.GoogleMessage3.Message949.t()]
}
defstruct [:field963]
field :field963, 1, repeated: true, type: Benchmarks.GoogleMessage3.Message949
end
defmodule Benchmarks.GoogleMessage3.Message36876.Message36877 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field37044: String.t(),
field37045: integer,
field37046: binary,
field37047: integer,
field37048: integer
}
defstruct [:field37044, :field37045, :field37046, :field37047, :field37048]
field :field37044, 112, required: true, type: :string
field :field37045, 113, optional: true, type: :int32
field :field37046, 114, optional: true, type: :bytes
field :field37047, 115, optional: true, type: :int32
field :field37048, 157, optional: true, type: :int32
end
defmodule Benchmarks.GoogleMessage3.Message36876.Message36878 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{}
defstruct []
end
defmodule Benchmarks.GoogleMessage3.Message36876.Message36879 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field37050: String.t(),
field37051: integer
}
defstruct [:field37050, :field37051]
field :field37050, 56, required: true, type: :string
field :field37051, 69, optional: true, type: :int32
end
defmodule Benchmarks.GoogleMessage3.Message36876.Message36880 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{}
defstruct []
end
defmodule Benchmarks.GoogleMessage3.Message36876.Message36881 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{}
defstruct []
end
defmodule Benchmarks.GoogleMessage3.Message36876.Message36882 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{}
defstruct []
end
defmodule Benchmarks.GoogleMessage3.Message36876.Message36883 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{}
defstruct []
end
defmodule Benchmarks.GoogleMessage3.Message36876.Message36884 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{}
defstruct []
end
defmodule Benchmarks.GoogleMessage3.Message36876.Message36885 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{}
defstruct []
end
defmodule Benchmarks.GoogleMessage3.Message36876.Message36886 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{}
defstruct []
end
defmodule Benchmarks.GoogleMessage3.Message36876.Message36887 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{}
defstruct []
end
defmodule Benchmarks.GoogleMessage3.Message36876.Message36888 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field37089: non_neg_integer,
field37090: boolean,
field37091: non_neg_integer,
field37092: float | :infinity | :negative_infinity | :nan,
field37093: non_neg_integer,
field37094: binary
}
defstruct [:field37089, :field37090, :field37091, :field37092, :field37093, :field37094]
field :field37089, 75, optional: true, type: :uint64
field :field37090, 76, optional: true, type: :bool
field :field37091, 165, optional: true, type: :uint64
field :field37092, 166, optional: true, type: :double
field :field37093, 109, optional: true, type: :uint64
field :field37094, 122, optional: true, type: :bytes
end
defmodule Benchmarks.GoogleMessage3.Message36876.Message36889 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field37095: integer,
field37096: String.t(),
field37097: integer,
field37098: boolean,
field37099: integer,
field37100: integer,
field37101: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field37102: Benchmarks.GoogleMessage3.Message13174.t() | nil,
field37103: Benchmarks.GoogleMessage3.Message13169.t() | nil,
field37104: non_neg_integer,
field37105: [[Benchmarks.GoogleMessage3.Enum36890.t()]],
field37106: boolean,
field37107: boolean,
field37108: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field37109: float | :infinity | :negative_infinity | :nan,
field37110: float | :infinity | :negative_infinity | :nan,
field37111: boolean,
field37112: integer,
field37113: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field37114: boolean,
field37115: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field37116: Benchmarks.GoogleMessage3.UnusedEnum.t(),
field37117: [[Benchmarks.GoogleMessage3.UnusedEnum.t()]],
field37118: integer,
field37119: [String.t()]
}
defstruct [
:field37095,
:field37096,
:field37097,
:field37098,
:field37099,
:field37100,
:field37101,
:field37102,
:field37103,
:field37104,
:field37105,
:field37106,
:field37107,
:field37108,
:field37109,
:field37110,
:field37111,
:field37112,
:field37113,
:field37114,
:field37115,
:field37116,
:field37117,
:field37118,
:field37119
]
field :field37095, 117, optional: true, type: :int64
field :field37096, 145, optional: true, type: :string
field :field37097, 123, optional: true, type: :int32
field :field37098, 163, optional: true, type: :bool
field :field37099, 164, optional: true, type: :int32
field :field37100, 149, optional: true, type: :int32
field :field37101, 129, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field37102, 124, optional: true, type: Benchmarks.GoogleMessage3.Message13174
field :field37103, 128, optional: true, type: Benchmarks.GoogleMessage3.Message13169
field :field37104, 132, optional: true, type: :uint64
field :field37105, 131, repeated: true, type: Benchmarks.GoogleMessage3.Enum36890, enum: true
field :field37106, 134, optional: true, type: :bool
field :field37107, 140, optional: true, type: :bool
field :field37108, 135, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field37109, 136, optional: true, type: :float
field :field37110, 156, optional: true, type: :float
field :field37111, 142, optional: true, type: :bool
field :field37112, 167, optional: true, type: :int64
field :field37113, 146, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field37114, 148, optional: true, type: :bool
field :field37115, 154, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field37116, 158, optional: true, type: Benchmarks.GoogleMessage3.UnusedEnum, enum: true
field :field37117, 159, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEnum, enum: true
field :field37118, 160, optional: true, type: :int32
field :field37119, 161, repeated: true, type: :string
end
defmodule Benchmarks.GoogleMessage3.Message36876.Message36910 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{}
defstruct []
end
defmodule Benchmarks.GoogleMessage3.Message36876.Message36911 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field37121: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field37122: Benchmarks.GoogleMessage3.Message35538.t() | nil,
field37123: Benchmarks.GoogleMessage3.Message35540.t() | nil,
field37124: Benchmarks.GoogleMessage3.Message35542.t() | nil
}
defstruct [:field37121, :field37122, :field37123, :field37124]
field :field37121, 127, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field37122, 130, optional: true, type: Benchmarks.GoogleMessage3.Message35538
field :field37123, 144, optional: true, type: Benchmarks.GoogleMessage3.Message35540
field :field37124, 150, optional: true, type: Benchmarks.GoogleMessage3.Message35542
end
defmodule Benchmarks.GoogleMessage3.Message36876.Message36912 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field37125: Benchmarks.GoogleMessage3.Message3901.t() | nil,
field37126: Benchmarks.GoogleMessage3.Message3901.t() | nil
}
defstruct [:field37125, :field37126]
field :field37125, 153, optional: true, type: Benchmarks.GoogleMessage3.Message3901
field :field37126, 162, optional: true, type: Benchmarks.GoogleMessage3.Message3901
end
defmodule Benchmarks.GoogleMessage3.Message36876 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field36980: Benchmarks.GoogleMessage3.Message2356.t() | nil,
message36877: [any],
message36878: [any],
message36879: [any],
field36984: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
message36880: any,
field36986: non_neg_integer,
field36987: binary,
field36988: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field36989: Benchmarks.GoogleMessage3.Message7029.t() | nil,
field36990: Benchmarks.GoogleMessage3.Message35573.t() | nil,
field36991: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field36992: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field36993: float | :infinity | :negative_infinity | :nan,
field36994: integer,
field36995: boolean,
field36996: boolean,
field36997: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field36998: integer,
field36999: integer,
field37000: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
message36881: [any],
field37002: Benchmarks.GoogleMessage3.Message4144.t() | nil,
message36882: [any],
field37004: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field37005: Benchmarks.GoogleMessage3.Message18921.t() | nil,
field37006: Benchmarks.GoogleMessage3.Message36858.t() | nil,
field37007: Benchmarks.GoogleMessage3.Message18831.t() | nil,
field37008: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field37009: Benchmarks.GoogleMessage3.Message18283.t() | nil,
field37010: String.t(),
field37011: String.t(),
field37012: Benchmarks.GoogleMessage3.Message0.t() | nil,
field37013: Benchmarks.GoogleMessage3.Message0.t() | nil,
field37014: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field37015: Benchmarks.GoogleMessage3.Message36869.t() | nil,
message36883: any,
message36884: [any],
message36885: [any],
message36886: any,
field37020: [[Benchmarks.GoogleMessage3.UnusedEnum.t()]],
field37021: [integer],
field37022: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field37023: Benchmarks.GoogleMessage3.Message13090.t() | nil,
message36887: any,
field37025: [Benchmarks.GoogleMessage3.Message10155.t()],
field37026: [Benchmarks.GoogleMessage3.Message11874.t()],
field37027: String.t(),
field37028: integer,
field37029: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field37030: Benchmarks.GoogleMessage3.Message35546.t() | nil,
message36888: any,
field37032: [Benchmarks.GoogleMessage3.Message19255.t()],
field37033: Benchmarks.GoogleMessage3.Message33968.t() | nil,
field37034: boolean,
field37035: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field37036: Benchmarks.GoogleMessage3.Message6644.t() | nil,
field37037: binary,
message36889: any,
message36910: [any],
message36911: any,
message36912: any,
field37042: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil
}
defstruct [
:field36980,
:message36877,
:message36878,
:message36879,
:field36984,
:message36880,
:field36986,
:field36987,
:field36988,
:field36989,
:field36990,
:field36991,
:field36992,
:field36993,
:field36994,
:field36995,
:field36996,
:field36997,
:field36998,
:field36999,
:field37000,
:message36881,
:field37002,
:message36882,
:field37004,
:field37005,
:field37006,
:field37007,
:field37008,
:field37009,
:field37010,
:field37011,
:field37012,
:field37013,
:field37014,
:field37015,
:message36883,
:message36884,
:message36885,
:message36886,
:field37020,
:field37021,
:field37022,
:field37023,
:message36887,
:field37025,
:field37026,
:field37027,
:field37028,
:field37029,
:field37030,
:message36888,
:field37032,
:field37033,
:field37034,
:field37035,
:field37036,
:field37037,
:message36889,
:message36910,
:message36911,
:message36912,
:field37042
]
field :field36980, 1, optional: true, type: Benchmarks.GoogleMessage3.Message2356
field :message36877, 111, repeated: true, type: :group
field :message36878, 168, repeated: true, type: :group
field :message36879, 55, repeated: true, type: :group
field :field36984, 78, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :message36880, 137, optional: true, type: :group
field :field36986, 59, optional: true, type: :uint64
field :field36987, 121, optional: true, type: :bytes
field :field36988, 2, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field36989, 118, optional: true, type: Benchmarks.GoogleMessage3.Message7029
field :field36990, 11, optional: true, type: Benchmarks.GoogleMessage3.Message35573
field :field36991, 21, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field36992, 22, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field36993, 13, optional: true, type: :float
field :field36994, 20, optional: true, type: :int32
field :field36995, 51, optional: true, type: :bool
field :field36996, 57, optional: true, type: :bool
field :field36997, 100, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field36998, 47, optional: true, type: :int32
field :field36999, 48, optional: true, type: :int32
field :field37000, 68, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :message36881, 23, repeated: true, type: :group
field :field37002, 125, optional: true, type: Benchmarks.GoogleMessage3.Message4144
field :message36882, 35, repeated: true, type: :group
field :field37004, 49, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field37005, 52, optional: true, type: Benchmarks.GoogleMessage3.Message18921
field :field37006, 46, optional: true, type: Benchmarks.GoogleMessage3.Message36858
field :field37007, 54, optional: true, type: Benchmarks.GoogleMessage3.Message18831
field :field37008, 58, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field37009, 10, optional: true, type: Benchmarks.GoogleMessage3.Message18283
field :field37010, 44, optional: true, type: :string
field :field37011, 103, optional: true, type: :string
field :field37012, 43, optional: true, type: Benchmarks.GoogleMessage3.Message0
field :field37013, 143, optional: true, type: Benchmarks.GoogleMessage3.Message0
field :field37014, 53, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field37015, 15, optional: true, type: Benchmarks.GoogleMessage3.Message36869
field :message36883, 3, optional: true, type: :group
field :message36884, 16, repeated: true, type: :group
field :message36885, 27, repeated: true, type: :group
field :message36886, 32, optional: true, type: :group
field :field37020, 71, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEnum, enum: true
field :field37021, 70, repeated: true, type: :int32
field :field37022, 66, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field37023, 67, optional: true, type: Benchmarks.GoogleMessage3.Message13090
field :message36887, 62, optional: true, type: :group
field :field37025, 50, repeated: true, type: Benchmarks.GoogleMessage3.Message10155
field :field37026, 151, repeated: true, type: Benchmarks.GoogleMessage3.Message11874
field :field37027, 12, optional: true, type: :string
field :field37028, 72, optional: true, type: :int64
field :field37029, 73, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field37030, 108, optional: true, type: Benchmarks.GoogleMessage3.Message35546
field :message36888, 74, optional: true, type: :group
field :field37032, 104, repeated: true, type: Benchmarks.GoogleMessage3.Message19255
field :field37033, 105, optional: true, type: Benchmarks.GoogleMessage3.Message33968
field :field37034, 106, optional: true, type: :bool
field :field37035, 107, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field37036, 110, optional: true, type: Benchmarks.GoogleMessage3.Message6644
field :field37037, 133, optional: true, type: :bytes
field :message36889, 116, optional: true, type: :group
field :message36910, 119, repeated: true, type: :group
field :message36911, 126, optional: true, type: :group
field :message36912, 152, optional: true, type: :group
field :field37042, 155, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
end
defmodule Benchmarks.GoogleMessage3.Message1328 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{}
defstruct []
end
defmodule Benchmarks.GoogleMessage3.Message6850 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{}
defstruct []
end
defmodule Benchmarks.GoogleMessage3.Message6863 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field6931: Benchmarks.GoogleMessage3.Enum6858.t(),
field6932: Benchmarks.GoogleMessage3.Enum6858.t(),
field6933: Benchmarks.GoogleMessage3.UnusedEnum.t(),
field6934: boolean,
field6935: Benchmarks.GoogleMessage3.Message6773.t() | nil,
field6936: integer,
field6937: integer,
field6938: Benchmarks.GoogleMessage3.Enum6815.t(),
field6939: String.t(),
field6940: integer,
field6941: Benchmarks.GoogleMessage3.Enum6822.t(),
field6942: boolean,
field6943: boolean,
field6944: float | :infinity | :negative_infinity | :nan,
field6945: float | :infinity | :negative_infinity | :nan,
field6946: integer,
field6947: integer,
field6948: boolean,
field6949: integer,
field6950: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field6951: non_neg_integer,
field6952: String.t(),
field6953: binary,
field6954: integer,
field6955: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field6956: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field6957: Benchmarks.GoogleMessage3.Message3886.t() | nil,
field6958: String.t(),
field6959: non_neg_integer,
field6960: Benchmarks.GoogleMessage3.Message6743.t() | nil,
field6961: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field6962: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field6963: boolean
}
defstruct [
:field6931,
:field6932,
:field6933,
:field6934,
:field6935,
:field6936,
:field6937,
:field6938,
:field6939,
:field6940,
:field6941,
:field6942,
:field6943,
:field6944,
:field6945,
:field6946,
:field6947,
:field6948,
:field6949,
:field6950,
:field6951,
:field6952,
:field6953,
:field6954,
:field6955,
:field6956,
:field6957,
:field6958,
:field6959,
:field6960,
:field6961,
:field6962,
:field6963
]
field :field6931, 1, optional: true, type: Benchmarks.GoogleMessage3.Enum6858, enum: true
field :field6932, 2, optional: true, type: Benchmarks.GoogleMessage3.Enum6858, enum: true
field :field6933, 36, optional: true, type: Benchmarks.GoogleMessage3.UnusedEnum, enum: true
field :field6934, 27, optional: true, type: :bool
field :field6935, 26, optional: true, type: Benchmarks.GoogleMessage3.Message6773
field :field6936, 30, optional: true, type: :int32
field :field6937, 37, optional: true, type: :int32
field :field6938, 31, optional: true, type: Benchmarks.GoogleMessage3.Enum6815, enum: true
field :field6939, 3, optional: true, type: :string
field :field6940, 4, optional: true, type: :int32
field :field6941, 15, optional: true, type: Benchmarks.GoogleMessage3.Enum6822, enum: true
field :field6942, 10, optional: true, type: :bool
field :field6943, 17, optional: true, type: :bool
field :field6944, 18, optional: true, type: :float
field :field6945, 19, optional: true, type: :float
field :field6946, 5, optional: true, type: :int32
field :field6947, 6, optional: true, type: :int32
field :field6948, 7, optional: true, type: :bool
field :field6949, 12, optional: true, type: :int32
field :field6950, 8, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field6951, 9, optional: true, type: :uint64
field :field6952, 11, optional: true, type: :string
field :field6953, 13, optional: true, type: :bytes
field :field6954, 14, optional: true, type: :int32
field :field6955, 16, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field6956, 22, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field6957, 38, optional: true, type: Benchmarks.GoogleMessage3.Message3886
field :field6958, 20, optional: true, type: :string
field :field6959, 21, optional: true, type: :uint32
field :field6960, 23, optional: true, type: Benchmarks.GoogleMessage3.Message6743
field :field6961, 29, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field6962, 33, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field6963, 34, optional: true, type: :bool
end
defmodule Benchmarks.GoogleMessage3.Message6871 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{}
defstruct []
end
defmodule Benchmarks.GoogleMessage3.Message7547 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field7549: binary,
field7550: integer
}
defstruct [:field7549, :field7550]
field :field7549, 1, required: true, type: :bytes
field :field7550, 2, required: true, type: :int32
end
defmodule Benchmarks.GoogleMessage3.Message7648 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field7669: String.t(),
field7670: integer,
field7671: integer,
field7672: integer,
field7673: integer,
field7674: integer,
field7675: float | :infinity | :negative_infinity | :nan,
field7676: boolean,
field7677: boolean,
field7678: boolean,
field7679: boolean,
field7680: boolean
}
defstruct [
:field7669,
:field7670,
:field7671,
:field7672,
:field7673,
:field7674,
:field7675,
:field7676,
:field7677,
:field7678,
:field7679,
:field7680
]
field :field7669, 1, optional: true, type: :string
field :field7670, 2, optional: true, type: :int32
field :field7671, 3, optional: true, type: :int32
field :field7672, 4, optional: true, type: :int32
field :field7673, 5, optional: true, type: :int32
field :field7674, 6, optional: true, type: :int32
field :field7675, 7, optional: true, type: :float
field :field7676, 8, optional: true, type: :bool
field :field7677, 9, optional: true, type: :bool
field :field7678, 10, optional: true, type: :bool
field :field7679, 11, optional: true, type: :bool
field :field7680, 12, optional: true, type: :bool
end
defmodule Benchmarks.GoogleMessage3.Message7865 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{}
defstruct []
end
defmodule Benchmarks.GoogleMessage3.Message7928 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field7940: String.t(),
field7941: integer
}
defstruct [:field7940, :field7941]
field :field7940, 1, optional: true, type: :string
field :field7941, 2, optional: true, type: :int64
end
defmodule Benchmarks.GoogleMessage3.Message7919 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field7931: non_neg_integer,
field7932: integer,
field7933: binary
}
defstruct [:field7931, :field7932, :field7933]
field :field7931, 1, optional: true, type: :fixed64
field :field7932, 2, optional: true, type: :int64
field :field7933, 3, optional: true, type: :bytes
end
defmodule Benchmarks.GoogleMessage3.Message7920 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field7934: integer,
field7935: integer
}
defstruct [:field7934, :field7935]
field :field7934, 1, optional: true, type: :int64
field :field7935, 2, optional: true, type: :int64
end
defmodule Benchmarks.GoogleMessage3.Message7921 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field7936: integer,
field7937: integer,
field7938: float | :infinity | :negative_infinity | :nan,
field7939: Benchmarks.GoogleMessage3.UnusedEnum.t()
}
defstruct [:field7936, :field7937, :field7938, :field7939]
field :field7936, 1, optional: true, type: :int32
field :field7937, 2, optional: true, type: :int64
field :field7938, 3, optional: true, type: :float
field :field7939, 4, optional: true, type: Benchmarks.GoogleMessage3.UnusedEnum, enum: true
end
defmodule Benchmarks.GoogleMessage3.Message8511 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field8539: Benchmarks.GoogleMessage3.Message8224.t() | nil,
field8540: String.t(),
field8541: boolean,
field8542: integer,
field8543: String.t()
}
defstruct [:field8539, :field8540, :field8541, :field8542, :field8543]
field :field8539, 1, optional: true, type: Benchmarks.GoogleMessage3.Message8224
field :field8540, 2, optional: true, type: :string
field :field8541, 3, optional: true, type: :bool
field :field8542, 4, optional: true, type: :int64
field :field8543, 5, optional: true, type: :string
end
defmodule Benchmarks.GoogleMessage3.Message8512 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field8544: Benchmarks.GoogleMessage3.Message8301.t() | nil,
field8545: Benchmarks.GoogleMessage3.Message8302.t() | nil,
field8546: String.t(),
field8547: boolean,
field8548: integer,
field8549: String.t()
}
defstruct [:field8544, :field8545, :field8546, :field8547, :field8548, :field8549]
field :field8544, 1, optional: true, type: Benchmarks.GoogleMessage3.Message8301
field :field8545, 2, optional: true, type: Benchmarks.GoogleMessage3.Message8302
field :field8546, 3, optional: true, type: :string
field :field8547, 4, optional: true, type: :bool
field :field8548, 5, optional: true, type: :int64
field :field8549, 6, optional: true, type: :string
end
defmodule Benchmarks.GoogleMessage3.Message8513 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field8550: [Benchmarks.GoogleMessage3.Message8392.t()],
field8551: String.t(),
field8552: boolean,
field8553: String.t()
}
defstruct [:field8550, :field8551, :field8552, :field8553]
field :field8550, 1, repeated: true, type: Benchmarks.GoogleMessage3.Message8392
field :field8551, 2, optional: true, type: :string
field :field8552, 3, optional: true, type: :bool
field :field8553, 4, optional: true, type: :string
end
defmodule Benchmarks.GoogleMessage3.Message8514 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field8554: String.t(),
field8555: integer,
field8556: boolean,
field8557: [Benchmarks.GoogleMessage3.Message8130.t()],
field8558: String.t()
}
defstruct [:field8554, :field8555, :field8556, :field8557, :field8558]
field :field8554, 1, optional: true, type: :string
field :field8555, 2, optional: true, type: :int64
field :field8556, 3, optional: true, type: :bool
field :field8557, 4, repeated: true, type: Benchmarks.GoogleMessage3.Message8130
field :field8558, 5, optional: true, type: :string
end
defmodule Benchmarks.GoogleMessage3.Message8515 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field8559: Benchmarks.GoogleMessage3.Message8479.t() | nil,
field8560: Benchmarks.GoogleMessage3.Message8478.t() | nil,
field8561: String.t()
}
defstruct [:field8559, :field8560, :field8561]
field :field8559, 1, optional: true, type: Benchmarks.GoogleMessage3.Message8479
field :field8560, 2, optional: true, type: Benchmarks.GoogleMessage3.Message8478
field :field8561, 3, optional: true, type: :string
end
defmodule Benchmarks.GoogleMessage3.Message10320 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field10347: Benchmarks.GoogleMessage3.Enum10335.t(),
field10348: [Benchmarks.GoogleMessage3.Message10319.t()],
field10349: integer,
field10350: integer,
field10351: integer,
field10352: integer,
field10353: Benchmarks.GoogleMessage3.Enum10337.t()
}
defstruct [
:field10347,
:field10348,
:field10349,
:field10350,
:field10351,
:field10352,
:field10353
]
field :field10347, 1, optional: true, type: Benchmarks.GoogleMessage3.Enum10335, enum: true
field :field10348, 2, repeated: true, type: Benchmarks.GoogleMessage3.Message10319
field :field10349, 3, optional: true, type: :int32
field :field10350, 4, optional: true, type: :int32
field :field10351, 5, optional: true, type: :int32
field :field10352, 6, optional: true, type: :int32
field :field10353, 7, optional: true, type: Benchmarks.GoogleMessage3.Enum10337, enum: true
end
defmodule Benchmarks.GoogleMessage3.Message10321 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field10354: integer,
field10355: integer,
field10356: non_neg_integer
}
defstruct [:field10354, :field10355, :field10356]
field :field10354, 1, optional: true, type: :int32
field :field10355, 2, optional: true, type: :int32
field :field10356, 3, optional: true, type: :uint64
end
defmodule Benchmarks.GoogleMessage3.Message10322 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field10357: Benchmarks.GoogleMessage3.Message4016.t() | nil,
field10358: boolean,
field10359: boolean
}
defstruct [:field10357, :field10358, :field10359]
field :field10357, 1, optional: true, type: Benchmarks.GoogleMessage3.Message4016
field :field10358, 2, optional: true, type: :bool
field :field10359, 3, optional: true, type: :bool
end
defmodule Benchmarks.GoogleMessage3.Message11988 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field12021: String.t(),
field12022: String.t(),
field12023: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field12024: Benchmarks.GoogleMessage3.Message10155.t() | nil
}
defstruct [:field12021, :field12022, :field12023, :field12024]
field :field12021, 1, optional: true, type: :string
field :field12022, 2, optional: true, type: :string
field :field12023, 3, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field12024, 4, optional: true, type: Benchmarks.GoogleMessage3.Message10155
end
defmodule Benchmarks.GoogleMessage3.Message12668 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field12677: [Benchmarks.GoogleMessage3.Message12669.t()],
field12678: integer,
field12679: integer,
field12680: integer
}
defstruct [:field12677, :field12678, :field12679, :field12680]
field :field12677, 1, repeated: true, type: Benchmarks.GoogleMessage3.Message12669
field :field12678, 2, optional: true, type: :int32
field :field12679, 3, optional: true, type: :int32
field :field12680, 4, optional: true, type: :int32
end
defmodule Benchmarks.GoogleMessage3.Message12825 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field12862: [Benchmarks.GoogleMessage3.Message12818.t()],
field12863: integer,
field12864: Benchmarks.GoogleMessage3.Message12819.t() | nil,
field12865: Benchmarks.GoogleMessage3.Message12820.t() | nil,
field12866: integer,
field12867: [Benchmarks.GoogleMessage3.Message12821.t()],
field12868: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()]
}
defstruct [
:field12862,
:field12863,
:field12864,
:field12865,
:field12866,
:field12867,
:field12868
]
field :field12862, 1, repeated: true, type: Benchmarks.GoogleMessage3.Message12818
field :field12863, 2, optional: true, type: :int32
field :field12864, 3, optional: true, type: Benchmarks.GoogleMessage3.Message12819
field :field12865, 4, optional: true, type: Benchmarks.GoogleMessage3.Message12820
field :field12866, 5, optional: true, type: :int32
field :field12867, 6, repeated: true, type: Benchmarks.GoogleMessage3.Message12821
field :field12868, 7, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
end
defmodule Benchmarks.GoogleMessage3.Message16478 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field16481: [Benchmarks.GoogleMessage3.Message16479.t()],
field16482: boolean,
field16483: integer
}
defstruct [:field16481, :field16482, :field16483]
field :field16481, 1, repeated: true, type: Benchmarks.GoogleMessage3.Message16479
field :field16482, 3, optional: true, type: :bool
field :field16483, 2, optional: true, type: :int32
end
defmodule Benchmarks.GoogleMessage3.Message16552 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field16565: non_neg_integer,
field16566: integer,
field16567: Benchmarks.GoogleMessage3.Enum16553.t()
}
defstruct [:field16565, :field16566, :field16567]
field :field16565, 1, optional: true, type: :fixed64
field :field16566, 2, optional: true, type: :int32
field :field16567, 3, optional: true, type: Benchmarks.GoogleMessage3.Enum16553, enum: true
end
defmodule Benchmarks.GoogleMessage3.Message16660 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field16668: String.t(),
field16669: String.t(),
field16670: integer
}
defstruct [:field16668, :field16669, :field16670]
field :field16668, 1, optional: true, type: :string
field :field16669, 2, optional: true, type: :string
field :field16670, 3, optional: true, type: :int32
end
defmodule Benchmarks.GoogleMessage3.Message16727 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field16782: Benchmarks.GoogleMessage3.Enum16728.t(),
field16783: String.t(),
field16784: String.t(),
field16785: integer,
field16786: String.t(),
field16787: String.t(),
field16788: String.t(),
field16789: Benchmarks.GoogleMessage3.Enum16732.t(),
field16790: String.t(),
field16791: String.t(),
field16792: String.t(),
field16793: Benchmarks.GoogleMessage3.Enum16738.t(),
field16794: integer,
field16795: [Benchmarks.GoogleMessage3.Message16722.t()],
field16796: boolean,
field16797: boolean,
field16798: String.t(),
field16799: integer,
field16800: boolean,
field16801: String.t(),
field16802: Benchmarks.GoogleMessage3.Enum16698.t(),
field16803: Benchmarks.GoogleMessage3.Message16724.t() | nil,
field16804: boolean,
field16805: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
__pb_extensions__: map
}
defstruct [
:field16782,
:field16783,
:field16784,
:field16785,
:field16786,
:field16787,
:field16788,
:field16789,
:field16790,
:field16791,
:field16792,
:field16793,
:field16794,
:field16795,
:field16796,
:field16797,
:field16798,
:field16799,
:field16800,
:field16801,
:field16802,
:field16803,
:field16804,
:field16805,
:__pb_extensions__
]
field :field16782, 1, required: true, type: Benchmarks.GoogleMessage3.Enum16728, enum: true
field :field16783, 2, required: true, type: :string
field :field16784, 3, optional: true, type: :string
field :field16785, 23, optional: true, type: :int32
field :field16786, 4, required: true, type: :string
field :field16787, 5, optional: true, type: :string
field :field16788, 6, optional: true, type: :string
field :field16789, 7, required: true, type: Benchmarks.GoogleMessage3.Enum16732, enum: true
field :field16790, 8, optional: true, type: :string
field :field16791, 9, optional: true, type: :string
field :field16792, 10, optional: true, type: :string
field :field16793, 11, optional: true, type: Benchmarks.GoogleMessage3.Enum16738, enum: true
field :field16794, 12, optional: true, type: :int32
field :field16795, 13, repeated: true, type: Benchmarks.GoogleMessage3.Message16722
field :field16796, 19, optional: true, type: :bool
field :field16797, 24, optional: true, type: :bool
field :field16798, 14, optional: true, type: :string
field :field16799, 15, optional: true, type: :int64
field :field16800, 16, optional: true, type: :bool
field :field16801, 17, optional: true, type: :string
field :field16802, 18, optional: true, type: Benchmarks.GoogleMessage3.Enum16698, enum: true
field :field16803, 20, optional: true, type: Benchmarks.GoogleMessage3.Message16724
field :field16804, 22, optional: true, type: :bool
field :field16805, 25, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
extensions [{1000, 536_870_912}]
end
defmodule Benchmarks.GoogleMessage3.Message16725 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field16774: Benchmarks.GoogleMessage3.Enum16728.t(),
field16775: [String.t()]
}
defstruct [:field16774, :field16775]
field :field16774, 1, optional: true, type: Benchmarks.GoogleMessage3.Enum16728, enum: true
field :field16775, 2, repeated: true, type: :string
end
defmodule Benchmarks.GoogleMessage3.Message17726 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field17801: String.t(),
field17802: [String.t()],
field17803: String.t(),
field17804: [String.t()],
field17805: String.t(),
field17806: [String.t()],
field17807: String.t(),
field17808: String.t(),
field17809: [String.t()],
field17810: [String.t()],
field17811: [String.t()],
field17812: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field17813: String.t(),
field17814: String.t(),
field17815: String.t(),
field17816: String.t(),
field17817: String.t(),
field17818: String.t(),
field17819: String.t(),
field17820: [Benchmarks.GoogleMessage3.Message17728.t()],
field17821: [Benchmarks.GoogleMessage3.Message17728.t()],
field17822: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()]
}
defstruct [
:field17801,
:field17802,
:field17803,
:field17804,
:field17805,
:field17806,
:field17807,
:field17808,
:field17809,
:field17810,
:field17811,
:field17812,
:field17813,
:field17814,
:field17815,
:field17816,
:field17817,
:field17818,
:field17819,
:field17820,
:field17821,
:field17822
]
field :field17801, 1, optional: true, type: :string
field :field17802, 2, repeated: true, type: :string
field :field17803, 3, optional: true, type: :string
field :field17804, 4, repeated: true, type: :string
field :field17805, 5, optional: true, type: :string
field :field17806, 6, repeated: true, type: :string
field :field17807, 7, optional: true, type: :string
field :field17808, 8, optional: true, type: :string
field :field17809, 15, repeated: true, type: :string
field :field17810, 16, repeated: true, type: :string
field :field17811, 17, repeated: true, type: :string
field :field17812, 18, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field17813, 9, optional: true, type: :string
field :field17814, 10, optional: true, type: :string
field :field17815, 11, optional: true, type: :string
field :field17816, 12, optional: true, type: :string
field :field17817, 13, optional: true, type: :string
field :field17818, 14, optional: true, type: :string
field :field17819, 19, optional: true, type: :string
field :field17820, 20, repeated: true, type: Benchmarks.GoogleMessage3.Message17728
field :field17821, 21, repeated: true, type: Benchmarks.GoogleMessage3.Message17728
field :field17822, 30, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
end
defmodule Benchmarks.GoogleMessage3.Message17782 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field18153: String.t(),
field18154: String.t()
}
defstruct [:field18153, :field18154]
field :field18153, 1, optional: true, type: :string
field :field18154, 2, optional: true, type: :string
end
defmodule Benchmarks.GoogleMessage3.Message17783.Message17784 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field18162: String.t(),
field18163: String.t(),
field18164: String.t(),
field18165: [String.t()],
field18166: String.t(),
field18167: String.t()
}
defstruct [:field18162, :field18163, :field18164, :field18165, :field18166, :field18167]
field :field18162, 5, optional: true, type: :string
field :field18163, 6, optional: true, type: :string
field :field18164, 7, optional: true, type: :string
field :field18165, 8, repeated: true, type: :string
field :field18166, 17, optional: true, type: :string
field :field18167, 18, optional: true, type: :string
end
defmodule Benchmarks.GoogleMessage3.Message17783.Message17785 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field18168: String.t(),
field18169: String.t(),
field18170: Benchmarks.GoogleMessage3.Message17783.t() | nil,
field18171: String.t(),
field18172: String.t(),
field18173: [String.t()]
}
defstruct [:field18168, :field18169, :field18170, :field18171, :field18172, :field18173]
field :field18168, 10, optional: true, type: :string
field :field18169, 11, optional: true, type: :string
field :field18170, 12, optional: true, type: Benchmarks.GoogleMessage3.Message17783
field :field18171, 13, optional: true, type: :string
field :field18172, 14, optional: true, type: :string
field :field18173, 15, repeated: true, type: :string
end
defmodule Benchmarks.GoogleMessage3.Message17783 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field18155: String.t(),
field18156: String.t(),
field18157: String.t(),
message17784: [any],
message17785: [any],
field18160: [String.t()]
}
defstruct [:field18155, :field18156, :field18157, :message17784, :message17785, :field18160]
field :field18155, 1, optional: true, type: :string
field :field18156, 2, optional: true, type: :string
field :field18157, 3, optional: true, type: :string
field :message17784, 4, repeated: true, type: :group
field :message17785, 9, repeated: true, type: :group
field :field18160, 16, repeated: true, type: :string
end
defmodule Benchmarks.GoogleMessage3.Message16945 do
@moduledoc false
use Protobuf, syntax: :proto2
@type t :: %__MODULE__{
field16946: String.t(),
field16947: String.t(),
field16948: String.t(),
field16949: String.t(),
field16950: String.t(),
field16951: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field16952: [Benchmarks.GoogleMessage3.Message0.t()],
field16953: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field16954: [Benchmarks.GoogleMessage3.Message0.t()],
field16955: [String.t()],
field16956: [String.t()],
field16957: [String.t()],
field16958: [String.t()],
field16959: [String.t()],
field16960: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field16961: [Benchmarks.GoogleMessage3.Message0.t()],
field16962: [Benchmarks.GoogleMessage3.Message0.t()],
field16963: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field16964: [String.t()],
field16965: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field16966: [String.t()],
field16967: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field16968: [String.t()],
field16969: [Benchmarks.GoogleMessage3.Message0.t()],
field16970: [String.t()],
field16971: [String.t()],
field16972: [String.t()],
field16973: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field16974: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field16975: [String.t()],
field16976: [String.t()],
field16977: [Benchmarks.GoogleMessage3.Message0.t()],
field16978: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field16979: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field16980: [integer],
field16981: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field16982: [String.t()],
field16983: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field16984: [String.t()],
field16985: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field16986: [String.t()],
field16987: [String.t()],
field16988: [String.t()],
field16989: String.t(),
field16990: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field16991: [String.t()],
field16992: [String.t()],
field16993: [String.t()],
field16994: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field16995: integer,
field16996: integer,
field16997: String.t(),
field16998: [String.t()],
field16999: [String.t()],
field17000: String.t(),
field17001: [String.t()],
field17002: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field17003: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field17004: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field17005: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field17006: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field17007: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field17008: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field17009: Benchmarks.GoogleMessage3.UnusedEmptyMessage.t() | nil,
field17010: [Benchmarks.GoogleMessage3.Message0.t()],
field17011: [String.t()],
field17012: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field17013: [String.t()],
field17014: [Benchmarks.GoogleMessage3.UnusedEmptyMessage.t()],
field17015: [Benchmarks.GoogleMessage3.Message0.t()],
field17016: [String.t()],
field17017: [String.t()],
field17018: [String.t()],
field17019: [String.t()],
field17020: [String.t()],
field17021: [String.t()],
field17022: [String.t()],
field17023: [Benchmarks.GoogleMessage3.Message0.t()],
field17024: [String.t()],
__pb_extensions__: map
}
defstruct [
:field16946,
:field16947,
:field16948,
:field16949,
:field16950,
:field16951,
:field16952,
:field16953,
:field16954,
:field16955,
:field16956,
:field16957,
:field16958,
:field16959,
:field16960,
:field16961,
:field16962,
:field16963,
:field16964,
:field16965,
:field16966,
:field16967,
:field16968,
:field16969,
:field16970,
:field16971,
:field16972,
:field16973,
:field16974,
:field16975,
:field16976,
:field16977,
:field16978,
:field16979,
:field16980,
:field16981,
:field16982,
:field16983,
:field16984,
:field16985,
:field16986,
:field16987,
:field16988,
:field16989,
:field16990,
:field16991,
:field16992,
:field16993,
:field16994,
:field16995,
:field16996,
:field16997,
:field16998,
:field16999,
:field17000,
:field17001,
:field17002,
:field17003,
:field17004,
:field17005,
:field17006,
:field17007,
:field17008,
:field17009,
:field17010,
:field17011,
:field17012,
:field17013,
:field17014,
:field17015,
:field17016,
:field17017,
:field17018,
:field17019,
:field17020,
:field17021,
:field17022,
:field17023,
:field17024,
:__pb_extensions__
]
field :field16946, 1, optional: true, type: :string
field :field16947, 2, optional: true, type: :string
field :field16948, 3, optional: true, type: :string
field :field16949, 4, optional: true, type: :string
field :field16950, 5, optional: true, type: :string
field :field16951, 872, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field16952, 16, repeated: true, type: Benchmarks.GoogleMessage3.Message0
field :field16953, 54, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field16954, 55, repeated: true, type: Benchmarks.GoogleMessage3.Message0
field :field16955, 58, repeated: true, type: :string
field :field16956, 59, repeated: true, type: :string
field :field16957, 62, repeated: true, type: :string
field :field16958, 37, repeated: true, type: :string
field :field16959, 18, repeated: true, type: :string
field :field16960, 38, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field16961, 67, repeated: true, type: Benchmarks.GoogleMessage3.Message0
field :field16962, 130, repeated: true, type: Benchmarks.GoogleMessage3.Message0
field :field16963, 136, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field16964, 138, repeated: true, type: :string
field :field16965, 156, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field16966, 139, repeated: true, type: :string
field :field16967, 126, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field16968, 152, repeated: true, type: :string
field :field16969, 183, repeated: true, type: Benchmarks.GoogleMessage3.Message0
field :field16970, 168, repeated: true, type: :string
field :field16971, 212, repeated: true, type: :string
field :field16972, 213, repeated: true, type: :string
field :field16973, 189, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field16974, 190, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field16975, 191, repeated: true, type: :string
field :field16976, 192, repeated: true, type: :string
field :field16977, 193, repeated: true, type: Benchmarks.GoogleMessage3.Message0
field :field16978, 194, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field16979, 195, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field16980, 196, repeated: true, type: :int32
field :field16981, 95, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field16982, 96, repeated: true, type: :string
field :field16983, 97, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field16984, 1086, repeated: true, type: :string
field :field16985, 98, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field16986, 99, repeated: true, type: :string
field :field16987, 100, repeated: true, type: :string
field :field16988, 48, repeated: true, type: :string
field :field16989, 22, optional: true, type: :string
field :field16990, 51, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field16991, 81, repeated: true, type: :string
field :field16992, 85, repeated: true, type: :string
field :field16993, 169, repeated: true, type: :string
field :field16994, 260, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field16995, 198, optional: true, type: :int32
field :field16996, 204, optional: true, type: :int32
field :field16997, 1087, optional: true, type: :string
field :field16998, 197, repeated: true, type: :string
field :field16999, 206, repeated: true, type: :string
field :field17000, 211, optional: true, type: :string
field :field17001, 205, repeated: true, type: :string
field :field17002, 68, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field17003, 69, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field17004, 70, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field17005, 71, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field17006, 72, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field17007, 19, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field17008, 24, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field17009, 23, optional: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field17010, 131, repeated: true, type: Benchmarks.GoogleMessage3.Message0
field :field17011, 133, repeated: true, type: :string
field :field17012, 142, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field17013, 143, repeated: true, type: :string
field :field17014, 153, repeated: true, type: Benchmarks.GoogleMessage3.UnusedEmptyMessage
field :field17015, 170, repeated: true, type: Benchmarks.GoogleMessage3.Message0
field :field17016, 171, repeated: true, type: :string
field :field17017, 172, repeated: true, type: :string
field :field17018, 173, repeated: true, type: :string
field :field17019, 174, repeated: true, type: :string
field :field17020, 175, repeated: true, type: :string
field :field17021, 186, repeated: true, type: :string
field :field17022, 101, repeated: true, type: :string
field :field17023, 102, repeated: true, type: Benchmarks.GoogleMessage3.Message0
field :field17024, 274, repeated: true, type: :string
extensions [
{17, 18},
{21, 22},
{25, 26},
{27, 28},
{29, 30},
{30, 31},
{31, 32},
{32, 33},
{33, 34},
{34, 35},
{35, 36},
{36, 37},
{39, 40},
{40, 41},
{41, 42},
{42, 43},
{43, 44},
{44, 45},
{45, 46},
{46, 47},
{47, 48},
{49, 50},
{50, 51},
{52, 53},
{53, 54},
{56, 57},
{57, 58},
{60, 61},
{61, 62},
{63, 64},
{64, 65},
{65, 66},
{66, 67},
{73, 74},
{74, 75},
{75, 76},
{76, 77},
{77, 78},
{78, 79},
{79, 80},
{80, 81},
{82, 83},
{83, 84},
{84, 85},
{86, 87},
{87, 88},
{88, 89},
{89, 90},
{90, 91},
{91, 92},
{92, 93},
{93, 94},
{94, 95},
{103, 104},
{104, 105},
{105, 106},
{106, 107},
{107, 108},
{108, 109},
{109, 110},
{110, 111},
{111, 112},
{112, 113},
{113, 114},
{114, 115},
{115, 116},
{116, 117},
{117, 118},
{118, 119},
{119, 120},
{120, 121},
{121, 122},
{122, 123},
{123, 124},
{124, 125},
{125, 126},
{127, 128},
{128, 129},
{129, 130},
{132, 133},
{134, 135},
{135, 136},
{137, 138},
{140, 141},
{141, 142},
{144, 145},
{145, 146},
{146, 147},
{147, 148},
{148, 149},
{149, 150},
{150, 151},
{151, 152},
{154, 155},
{155, 156},
{157, 158},
{158, 159},
{159, 160},
{160, 161},
{161, 162},
{162, 163},
{163, 164},
{164, 165},
{165, 166},
{166, 167},
{167, 168},
{176, 177},
{177, 178},
{178, 179},
{179, 180},
{180, 181},
{181, 182},
{182, 183},
{184, 185},
{185, 186},
{187, 188},
{188, 189},
{199, 200},
{200, 201},
{201, 202},
{202, 203},
{203, 204},
{207, 208},
{208, 209},
{209, 210},
{210, 211},
{214, 215},
{215, 216},
{216, 217},
{217, 218},
{218, 219},
{219, 220},
{220, 221},
{221, 222},
{222, 223},
{223, 224},
{224, 225},
{225, 226},
{226, 227},
{227, 228},
{228, 229},
{229, 230},
{230, 231},
{231, 232},
{232, 233},
{233, 234},
{234, 235},
{235, 236},
{236, 237},
{237, 238},
{238, 239},
{239, 240},
{240, 241},
{241, 242},
{242, 243},
{243, 244},
{244, 245},
{245, 246},
{246, 247},
{247, 248},
{248, 249},
{249, 250},
{250, 251},
{251, 252},
{252, 253},
{253, 254},
{254, 255},
{255, 256},
{256, 257},
{257, 258},
{258, 259},
{259, 260},
{261, 262},
{262, 263},
{263, 264},
{264, 265},
{265, 266},
{266, 267},
{267, 268},
{268, 269},
{269, 270},
{270, 271},
{271, 272},
{272, 273},
{273, 274},
{275, 276},
{276, 277},
{277, 278},
{278, 279},
{279, 280},
{280, 281},
{281, 282},
{282, 283},
{283, 284},
{284, 285},
{285, 286},
{286, 287},
{290, 291},
{291, 292},
{292, 293},
{293, 294},
{294, 295},
{295, 296},
{296, 297},
{297, 298},
{298, 299},
{299, 300},
{300, 301},
{301, 302},
{302, 303},
{303, 304},
{304, 305},
{305, 306},
{306, 307},
{307, 308},
{308, 309},
{309, 310},
{310, 311},
{311, 312},
{312, 313},
{313, 314},
{314, 315},
{315, 316},
{316, 317},
{317, 318},
{318, 319},
{319, 320},
{320, 321},
{321, 322},
{322, 323},
{323, 324},
{324, 325},
{325, 326},
{326, 327},
{327, 328},
{328, 329},
{329, 330},
{330, 331},
{331, 332},
{332, 333},
{333, 334},
{334, 335},
{335, 336},
{336, 337},
{337, 338},
{338, 339},
{339, 340},
{340, 341},
{341, 342},
{342, 343},
{343, 344},
{344, 345},
{345, 346},
{346, 347},
{347, 348},
{348, 349},
{349, 350},
{350, 351},
{351, 352},
{352, 353},
{353, 354},
{354, 355},
{355, 356},
{356, 357},
{357, 358},
{358, 359},
{359, 360},
{360, 361},
{361, 362},
{362, 363},
{363, 364},
{364, 365},
{365, 366},
{366, 367},
{367, 368},
{368, 369},
{369, 370},
{370, 371},
{371, 372},
{372, 373},
{373, 374},
{374, 375},
{375, 376},
{376, 377},
{377, 378},
{378, 379},
{379, 380},
{380, 381},
{381, 382},
{382, 383},
{383, 384},
{384, 385},
{385, 386},
{386, 387},
{387, 388},
{388, 389},
{389, 390},
{390, 391},
{391, 392},
{392, 393},
{393, 394},
{394, 395},
{395, 396},
{396, 397},
{397, 398},
{398, 399},
{399, 400},
{400, 401},
{401, 402},
{402, 403},
{403, 404},
{404, 405},
{405, 406},
{406, 407},
{407, 408},
{408, 409},
{409, 410},
{410, 411},
{411, 412},
{412, 413},
{413, 414},
{414, 415},
{415, 416},
{416, 417},
{417, 418},
{418, 419},
{419, 420},
{420, 421},
{421, 422},
{422, 423},
{423, 424},
{424, 425},
{425, 426},
{426, 427},
{427, 428},
{428, 429},
{429, 430},
{430, 431},
{431, 432},
{432, 433},
{433, 434},
{434, 435},
{435, 436},
{436, 437},
{437, 438},
{438, 439},
{439, 440},
{440, 441},
{441, 442},
{442, 443},
{443, 444},
{444, 445},
{445, 446},
{446, 447},
{447, 448},
{448, 449},
{449, 450},
{450, 451},
{451, 452},
{452, 453},
{453, 454},
{454, 455},
{455, 456},
{456, 457},
{457, 458},
{458, 459},
{459, 460},
{460, 461},
{461, 462},
{462, 463},
{463, 464},
{464, 465},
{465, 466},
{466, 467},
{467, 468},
{468, 469},
{469, 470},
{470, 471},
{471, 472},
{472, 473},
{473, 474},
{474, 475},
{509, 510},
{511, 512},
{512, 513},
{513, 514},
{514, 515},
{515, 516},
{516, 517},
{517, 518},
{518, 519},
{519, 520},
{520, 521},
{521, 522},
{522, 523},
{523, 524},
{524, 525},
{525, 526},
{526, 527},
{527, 528},
{528, 529},
{529, 530},
{530, 531},
{531, 532},
{532, 533},
{533, 534},
{534, 535},
{535, 536},
{536, 537},
{537, 538},
{538, 539},
{539, 540},
{540, 541},
{541, 542},
{542, 543},
{543, 544},
{544, 545},
{545, 546},
{546, 547},
{547, 548},
{548, 549},
{549, 550},
{550, 551},
{551, 552},
{552, 553},
{553, 554},
{554, 555},
{555, 556},
{556, 557},
{557, 558},
{558, 559},
{559, 560},
{560, 561},
{561, 562},
{562, 563},
{563, 564},
{564, 565},
{565, 566},
{566, 567},
{567, 568},
{568, 569},
{569, 570},
{570, 571},
{571, 572},
{572, 573},
{573, 574},
{574, 575},
{575, 576},
{576, 577},
{577, 578},
{578, 579},
{579, 580},
{580, 581},
{581, 582},
{582, 583},
{583, 584},
{584, 585},
{585, 586},
{586, 587},
{587, 588},
{588, 589},
{589, 590},
{590, 591},
{604, 605},
{605, 606},
{606, 607},
{607, 608},
{608, 609},
{609, 610},
{610, 611},
{611, 612},
{612, 613},
{613, 614},
{614, 615},
{615, 616},
{616, 617},
{617, 618},
{618, 619},
{619, 620},
{620, 621},
{621, 622},
{622, 623},
{623, 624},
{624, 625},
{625, 626},
{626, 627},
{627, 628},
{628, 629},
{629, 630},
{813, 814},
{814, 815},
{815, 816},
{816, 817},
{817, 818},
{818, 819},
{819, 820},
{820, 821},
{821, 822},
{822, 823},
{823, 824},
{824, 825},
{827, 828},
{828, 829},
{829, 830},
{830, 831},
{831, 832},
{832, 833},
{833, 834},
{834, 835},
{835, 836},
{836, 837},
{837, 838},
{838, 839},
{839, 840},
{840, 841},
{841, 842},
{842, 843},
{843, 844},
{844, 845},
{845, 846},
{846, 847},
{847, 848},
{848, 849},
{849, 850},
{850, 851},
{851, 852},
{852, 853},
{853, 854},
{854, 855},
{855, 856},
{856, 857},
{857, 858},
{858, 859},
{859, 860},
{860, 861},
{861, 862},
{862, 863},
{863, 864},
{864, 865},
{865, 866},
{866, 867},
{867, 868},
{868, 869},
{869, 870},
{870, 871},
{871, 872},
{880, 881},
{881, 882},
{882, 883},
{883, 884},
{884, 885},
{885, 886},
{886, 887},
{887, 888},
{888, 889},
{890, 891},
{891, 892},
{892, 893},
{912, 913},
{914, 915},
{915, 916},
{916, 917},
{917, 918},
{918, 919},
{919, 920},
{920, 921},
{921, 922},
{922, 923},
{923, 924},
{924, 925},
{925, 926},
{926, 927},
{927, 928},
{928, 929},
{929, 930},
{930, 931},
{931, 932},
{932, 933},
{933, 934},
{934, 935},
{935, 936},
{936, 937},
{937, 938},
{938, 939},
{939, 940},
{940, 941},
{941, 942},
{942, 943},
{943, 944},
{944, 945},
{945, 946},
{946, 947},
{947, 948},
{949, 950},
{950, 951},
{951, 952},
{952, 953},
{954, 955},
{955, 956},
{956, 957},
{957, 958},
{958, 959},
{959, 960},
{960, 961},
{961, 962},
{962, 963},
{963, 964},
{964, 965},
{965, 966},
{966, 967},
{967, 968},
{968, 969},
{969, 970},
{970, 971},
{971, 972},
{972, 973},
{973, 974},
{974, 975},
{975, 976},
{976, 977},
{977, 978},
{978, 979},
{979, 980},
{980, 981},
{981, 982},
{982, 983},
{983, 984},
{984, 985},
{985, 986},
{987, 988},
{988, 989},
{1000, 1001},
{1001, 1002},
{1002, 1003},
{1003, 1004},
{1004, 1005},
{1005, 1006},
{1006, 1007},
{1007, 1008},
{1008, 1009},
{1009, 1010},
{1010, 1011},
{1011, 1012},
{1012, 1013},
{1013, 1014},
{1014, 1015},
{1015, 1016},
{1016, 1017},
{1017, 1018},
{1018, 1019},
{1019, 1020},
{1020, 1021},
{1021, 1022},
{1022, 1023},
{1023, 1024},
{1024, 1025},
{1025, 1026},
{1026, 1027},
{1027, 1028},
{1028, 1029},
{1029, 1030},
{1030, 1031},
{1031, 1032},
{1032, 1033},
{1033, 1034},
{1034, 1035},
{1035, 1036},
{1036, 1037},
{1037, 1038},
{1038, 1039},
{1039, 1040},
{1040, 1041},
{1041, 1042},
{1042, 1043},
{1043, 1044},
{1044, 1045},
{1045, 1046},
{1046, 1047},
{1047, 1048},
{1048, 1049},
{1049, 1050},
{1050, 1051},
{1051, 1052},
{1052, 1053},
{1053, 1054},
{1054, 1055},
{1055, 1056},
{1056, 1057},
{1057, 1058},
{1058, 1059},
{1079, 1080},
{1080, 1081},
{1081, 1082},
{1082, 1083},
{1083, 1084},
{1084, 1085},
{1085, 1086}
]
end
defmodule Benchmarks.GoogleMessage3.PbExtension do
@moduledoc false
use Protobuf, syntax: :proto2
extend Benchmarks.GoogleMessage3.Message0, :"Message34390.field34453", 92_144_610,
optional: true,
type: Benchmarks.GoogleMessage3.Message34390
extend Benchmarks.GoogleMessage3.Message0, :"Message34624.field34685", 18_178_548,
optional: true,
type: Benchmarks.GoogleMessage3.Message34624
extend Benchmarks.GoogleMessage3.Message0, :"Message34791.field34807", 6_330_340,
optional: true,
type: Benchmarks.GoogleMessage3.Message34791
extend Benchmarks.GoogleMessage3.Message0, :"Message35483.field35505", 7_913_554,
optional: true,
type: Benchmarks.GoogleMessage3.Message35483
extend Benchmarks.GoogleMessage3.Message0, :"Message35807.field35818", 3_803_299,
optional: true,
type: Benchmarks.GoogleMessage3.Message35807
extend Benchmarks.GoogleMessage3.Message0, :"Message16945.field17025", 22_068_132,
optional: true,
type: Benchmarks.GoogleMessage3.Message16945
end
| 30.672982 | 96 | 0.643124 |
f71beb5675e604532eef58b2c65574253e45a0dd | 2,310 | exs | Elixir | mix.exs | oryono/banking | 0a49ebae5ebf93a6db0c24476a1c86c60bb72733 | [
"MIT"
] | null | null | null | mix.exs | oryono/banking | 0a49ebae5ebf93a6db0c24476a1c86c60bb72733 | [
"MIT"
] | null | null | null | mix.exs | oryono/banking | 0a49ebae5ebf93a6db0c24476a1c86c60bb72733 | [
"MIT"
] | null | null | null | defmodule BankingGraph.MixProject do
use Mix.Project
def project do
[
app: :banking_graph,
version: "0.1.0",
elixir: "~> 1.5",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
deps: deps()
]
end
# Configuration for the OTP application.
#
# Type `mix help compile.app` for more information.
def application do
[
mod: {BankingGraph.Application, []},
extra_applications: [:ssl, :timex, :ex_machina, :faker, :logger, :runtime_tools, :phoenix_pubsub]
]
end
# Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
# Specifies your project dependencies.
#
# Type `mix help deps` for examples and options.
defp deps do
[
{:phoenix, "~> 1.4.7"},
{:phoenix_pubsub, "~> 1.1"},
{:phoenix_ecto, "~> 4.0"},
{:ecto_sql, "~> 3.0"},
{:myxql, "~> 0.3.0", override: true},
{:gettext, "~> 0.11"},
{:jason, "~> 1.0"},
{:plug_cowboy, "~> 2.0"},
{:pbkdf2_elixir, "~> 1.0"},
{:absinthe, "~> 1.4.2"},
{:absinthe_plug, "~> 1.4.0"},
{:absinthe_phoenix, "~> 1.4.0"},
{:dataloader, "~> 1.0.0"},
{:guardian, "~> 1.2"},
{:ecto_autoslug_field, "~> 2.0"},
{:cors_plug, "~> 2.0"},
{:distillery, "~> 2.0"},
{:ex_machina, "~> 2.3"},
{:faker, "~> 0.13"},
{:timex, "~> 3.5"},
]
end
# Aliases are shortcuts or tasks specific to the current project.
# For example, to create, migrate and run the seeds file at once:
#
# $ mix ecto.setup
#
# See the documentation for `Mix` for more info on aliases.
defp aliases do
[
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
test: ["ecto.create --quiet", "ecto.migrate", "test"]
]
end
end
| 31.643836 | 109 | 0.487013 |
f71bfb7fc71e0224668bb5d6395ba96d78116a52 | 607 | ex | Elixir | clients/client/elixir/lib/ory/model/is_owner_for_project_by_slug_payload.ex | ory/sdk-generator | 958314d130922ad6f20f439b5230141a832231a5 | [
"Apache-2.0"
] | null | null | null | clients/client/elixir/lib/ory/model/is_owner_for_project_by_slug_payload.ex | ory/sdk-generator | 958314d130922ad6f20f439b5230141a832231a5 | [
"Apache-2.0"
] | null | null | null | clients/client/elixir/lib/ory/model/is_owner_for_project_by_slug_payload.ex | ory/sdk-generator | 958314d130922ad6f20f439b5230141a832231a5 | [
"Apache-2.0"
] | null | null | null | # NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
# https://openapi-generator.tech
# Do not edit the class manually.
defmodule Ory.Model.IsOwnerForProjectBySlugPayload do
@moduledoc """
"""
@derive [Poison.Encoder]
defstruct [
:"project_scope",
:"project_slug",
:"subject"
]
@type t :: %__MODULE__{
:"project_scope" => String.t | nil,
:"project_slug" => String.t,
:"subject" => String.t
}
end
defimpl Poison.Decoder, for: Ory.Model.IsOwnerForProjectBySlugPayload do
def decode(value, _options) do
value
end
end
| 20.233333 | 91 | 0.6771 |
f71c178b1d63546f2c69901d9bde7b27a3e54a38 | 86 | exs | Elixir | config/prod.exs | qgadrian/locux | 77404174c5c66bd27fed0d07404f916c11060393 | [
"MIT"
] | null | null | null | config/prod.exs | qgadrian/locux | 77404174c5c66bd27fed0d07404f916c11060393 | [
"MIT"
] | null | null | null | config/prod.exs | qgadrian/locux | 77404174c5c66bd27fed0d07404f916c11060393 | [
"MIT"
] | null | null | null | use Mix.Config
config :locust, num_of_workers: 1
config :locust, num_of_requests: 10
| 17.2 | 35 | 0.790698 |
f71c55183a5d6ae65852a8221603b67315391ec7 | 8,798 | ex | Elixir | lib/eml/compiler.ex | clemensm/eml | e2dc3dc605d2a61ccbdca1901a444a123abd8e94 | [
"Apache-2.0"
] | null | null | null | lib/eml/compiler.ex | clemensm/eml | e2dc3dc605d2a61ccbdca1901a444a123abd8e94 | [
"Apache-2.0"
] | null | null | null | lib/eml/compiler.ex | clemensm/eml | e2dc3dc605d2a61ccbdca1901a444a123abd8e94 | [
"Apache-2.0"
] | null | null | null | defmodule Eml.Compiler do
@moduledoc """
Various helper functions for implementing an Eml compiler.
"""
@type chunk :: String.t | { :safe, String.t } | Macro.t
# Options helper
@default_opts [escape: true,
transform: nil,
fragment: false,
compiler: Eml.HTML.Compiler]
defp new_opts(opts), do: Keyword.merge(@default_opts, opts)
# API
@doc """
Compiles eml to a string, or a quoted expression when the input contains
contains quoted expressions too.
Accepts the same options as `Eml.render/3`
In case of error, raises an Eml.CompileError exception.
### Examples:
iex> Eml.Compiler.compile(body(h1(id: "main-title")))
{:safe, "<body><h1 id='main-title'></h1></body>"
"""
@spec compile(Eml.t, Keyword.t) :: { :safe, String.t } | Macro.t
def compile(eml, opts \\ []) do
opts = new_opts(opts)
opts = Keyword.merge(opts[:compiler].opts(), opts)
compile_node(eml, opts, []) |> to_result(opts)
end
@spec precompile(Macro.Env.t, Keyword.t) :: { :safe, String.t } | Macro.t
def precompile(env \\ %Macro.Env{}, opts) do
mod = env.module
mod_opts = if mod && Module.open?(mod),
do: Module.get_attribute(mod, :eml_compile) |> Macro.escape(),
else: []
opts = Keyword.merge(mod_opts, opts)
{ file, opts } = Keyword.pop(opts, :file)
{ block, opts } = Keyword.pop(opts, :do)
ast = if file do
string = File.read!(file)
Code.string_to_quoted!(string, file: file, line: 1)
else
block
end |> prewalk(opts[:fragment])
{ expr, _ } = Code.eval_quoted(ast, [], env)
{ opts, _ } = Code.eval_quoted(opts, [], env)
compile(expr, opts)
end
# Content parsing
@spec compile_node(Eml.t, map, [chunk]) :: [chunk]
def compile_node(list, opts, chunks) when is_list(list) do
Enum.reduce(list, chunks, fn node, chunks ->
compile_node(node, opts, chunks)
end)
end
def compile_node(node, opts, chunks) do
node = node
|> maybe_transform(opts)
|> Eml.Encoder.encode()
case opts[:compiler].compile_node(node, opts, chunks) do
:unhandled ->
default_compile_node(node, opts, chunks)
s ->
s
end
end
@spec default_compile_node(Eml.node_primitive, map, [chunk]) :: [chunk]
defp default_compile_node(node, opts, chunks) when is_binary(node) do
add_chunk(maybe_escape(node, opts), chunks)
end
defp default_compile_node({ :safe, node }, _opts, chunks) when is_binary(node) do
add_chunk(node, chunks)
end
defp default_compile_node(node, _opts, chunks) when is_tuple(node) do
add_chunk(node, chunks)
end
defp default_compile_node(%Eml.Element{template: fun} = node, opts, chunks) when is_function(fun) do
node |> Eml.Element.apply_template() |> compile_node(opts, chunks)
end
defp default_compile_node(nil, _opts, chunks) do
chunks
end
defp default_compile_node(node, _, _) do
raise Eml.CompileError, message: "Bad node primitive: #{inspect node}"
end
# Attributes parsing
@spec compile_attrs(Eml.Element.attrs, map, [chunk]) :: [chunk]
def compile_attrs(attrs, opts, chunks) when is_map(attrs) do
Enum.reduce(attrs, chunks, fn
{ _, nil }, chunks -> chunks
{ k, v }, chunks -> compile_attr(k, v, opts, chunks)
end)
end
@spec compile_attr(atom, Eml.t, map, [chunk]) :: [chunk]
def compile_attr(field, value, opts, chunks) do
opts[:compiler].compile_attr(field, value, opts, chunks)
end
@spec compile_attr_value(Eml.t, map, [chunk]) :: [chunk]
def compile_attr_value(list, opts, chunks) when is_list(list) do
Enum.reduce(list, chunks, fn value, chunks ->
compile_attr_value(value, opts, chunks)
end)
end
def compile_attr_value(value, opts, chunks) do
value = Eml.Encoder.encode(value)
case opts[:compiler].compile_attr_value(value, opts, chunks) do
:unhandled ->
default_compile_node(value, opts, chunks)
s ->
s
end
end
# Text escaping
entity_map = %{"&" => "&",
"<" => "<",
">" => ">",
"\"" => """,
"'" => "'",
"…" => "…"}
def escape(eml) do
Eml.transform(eml, fn
node when is_binary(node) ->
escape(node, "")
node ->
node
end)
end
for {char, entity} <- entity_map do
defp escape(unquote(char) <> rest, acc) do
escape(rest, acc <> unquote(entity))
end
end
defp escape(<<char::utf8, rest::binary>>, acc) do
escape(rest, acc <> <<char::utf8>>)
end
defp escape("", acc) do
acc
end
# Create final result.
defp to_result([{ :safe, string }], _opts) do
{ :safe, string }
end
defp to_result(chunks, opts) do
template = :lists.reverse(chunks)
if opts[:fragment] do
template
else
quote do
Eml.Compiler.concat(unquote(template), unquote(Macro.escape(opts)))
end
end
end
def maybe_transform(node, opts) do
fun = opts[:transform]
if is_function(fun), do: fun.(node), else: node
end
def maybe_escape(node, opts) do
if opts[:escape], do: escape(node, ""), else: node
end
def add_chunk(chunk, [{:safe, safe_chunk} | rest]) when is_binary(chunk) do
[{:safe, safe_chunk <> chunk } | rest]
end
def add_chunk(chunk, chunks) when is_binary(chunk) do
[{ :safe, chunk } | chunks]
end
def add_chunk(chunk, chunks) do
[chunk | chunks]
end
def concat(buffer, opts) do
try do
{ :safe, concat(buffer, "", opts) }
catch
:throw, { :illegal_quoted, stacktrace } ->
reraise Eml.CompileError,
[message: "It's only possible to pass assigns to templates or components when using &"],
stacktrace
end
end
defp concat({ :safe, chunk }, acc, _opts) do
acc <> chunk
end
defp concat(chunk, acc, opts) when is_binary(chunk) do
acc <> maybe_escape(chunk, opts)
end
defp concat([chunk | rest], acc, opts) do
concat(rest, concat(chunk, acc, opts), opts)
end
defp concat([], acc, _opts) do
acc
end
defp concat(nil, acc, _opts) do
acc
end
defp concat(node, acc, opts) do
case Eml.Compiler.compile(node, opts) do
{ :safe, chunk } ->
acc <> chunk
_ ->
throw { :illegal_quoted, System.stacktrace() }
end
end
def prewalk(quoted, fragment?) do
handler = if fragment?,
do: &handle_fragment/1,
else: &handle_template/1
Macro.prewalk(quoted, handler)
end
defp handle_fragment({ :@, meta, [{ name, _, atom }] }) when is_atom(name) and is_atom(atom) do
line = meta[:line] || 0
Macro.escape(quote line: line do
Access.get(var!(assigns), unquote(name))
end)
end
defp handle_fragment({ :&, _meta, [{ _fun, _, args }] } = ast) do
case Macro.prewalk(args, false, &handle_capture_args/2) do
{ _, true } ->
ast
{ _, false } ->
raise Eml.CompileError,
message: "It's not possible to use & inside fragments"
end
end
defp handle_fragment(arg) do
arg
end
defp handle_template({ :&, meta, [{ fun, _, args }] }) do
case Macro.prewalk(args, false, &handle_capture_args/2) do
{ _, true } ->
raise Eml.CompileError,
message: "It's not possible to use & for captures inside templates or components"
{ new_args, false } ->
line = Keyword.get(meta, :line, 0)
Macro.escape(quote line: line do
unquote(fun)(unquote_splicing(List.wrap(new_args)))
end)
end
end
defp handle_template({ :@, meta, [{ name, _, atom }]}) when is_atom(name) and is_atom(atom) do
line = Keyword.get(meta, :line, 0)
Macro.escape(quote line: line do
Eml.Compiler.get_assign(unquote(name), var!(assigns), var!(funs))
end)
end
defp handle_template(ast) do
ast
end
defp handle_capture_args({ :@, meta, [{ name, _, atom }]}, regular_capure?) when is_atom(name) and is_atom(atom) do
line = Keyword.get(meta, :line, 0)
ast = quote line: line do
Eml.Compiler.get_assign(unquote(name), var!(assigns), var!(funs))
end
{ ast, regular_capure? }
end
defp handle_capture_args({ :&, _meta, [num]} = ast, _regular_capure?) when is_integer(num) do
{ ast, true }
end
defp handle_capture_args({ :/, _meta, _args} = ast, _regular_capure?) do
{ ast, true }
end
defp handle_capture_args(ast, regular_capure?) do
{ ast, regular_capure? }
end
@doc false
def get_assign(key, assigns, funs) do
x = if is_map(assigns), do: Map.get(assigns, key), else: Keyword.get(assigns, key)
case Keyword.get(funs, key) do
nil -> x
fun -> fun.(x)
end
end
end
| 28.108626 | 117 | 0.612526 |
f71c59822927e88beb5aaddda2e29c3d7188fdce | 1,898 | ex | Elixir | lib/open_exchange_rates/updater.ex | smeevil/open_exchange_rates | ea25dbab9baaf6c61a674452e2143cf6b0bb6d49 | [
"MIT"
] | 5 | 2016-08-07T13:57:56.000Z | 2020-10-05T17:17:17.000Z | lib/open_exchange_rates/updater.ex | smeevil/open_exchange_rates | ea25dbab9baaf6c61a674452e2143cf6b0bb6d49 | [
"MIT"
] | null | null | null | lib/open_exchange_rates/updater.ex | smeevil/open_exchange_rates | ea25dbab9baaf6c61a674452e2143cf6b0bb6d49 | [
"MIT"
] | 5 | 2018-07-01T17:41:40.000Z | 2021-03-31T19:06:47.000Z | defmodule OpenExchangeRates.Updater do
@moduledoc """
This module takes care of updating the cache with new conversion rates from openexchangerates.org and is for internal use only.
"""
require Logger
@update_interval_in_seconds 60
def cache_file, do: Application.get_env(:open_exchange_rates, :cache_file) || (File.cwd! <> "/priv/latest.json")
@doc false
def start do
load_data_from_disk
check_for_update
:ok
end
@doc false
def check_for_update do
cache_time = Application.get_env(:open_exchange_rates, :cache_time_in_minutes, 1440) * 60
if OpenExchangeRates.Cache.cache_age >= cache_time, do: update
Process.sleep(@update_interval_in_seconds * 1000)
check_for_update
end
def load_data_from_disk do
if File.exists?(cache_file()) do
cached_at = File.lstat!(cache_file(), [time: :posix]).mtime
cache_file()
|> File.read!
|> Poison.decode!
|> update_cache!(cached_at)
:ok
else
{:error, "could not find #{cache_file()} which you defined in your config"}
end
end
def load_data_from_disk! do
case load_data_from_disk do
:ok -> :ok
{:error, message} -> raise(message)
end
end
defp write_to_disk!(data) do
json = Poison.encode!(data)
File.write!(cache_file(), json)
data
end
defp update do
Logger.info "OpenExchangeRates Updating Rates..."
case OpenExchangeRates.Client.get_latest do
{:ok, data} -> data |> write_to_disk! |> update_cache!
{:error, message} -> {:error, message}
end
end
defp update_cache!(data, cached_at \\ nil)
defp update_cache!(%{"rates" => rates}, cached_at) do
cached_at = cached_at || :os.system_time(:seconds)
GenServer.call(OpenExchangeRates.Cache, {:update!, rates, cached_at})
end
defp update_cache!(data, _cached_at), do: raise "Data was corrupted ? #{inspect data}"
end
| 27.114286 | 129 | 0.683878 |
f71c6bfebcd7ba37e1a2abdb75f4c8353e9d4a91 | 1,419 | ex | Elixir | lib/plug/logger.ex | outstand/plug | e75d542b3028b5c1f348ac9d128306c46a6b6e70 | [
"Apache-2.0"
] | 1,218 | 2017-07-14T15:13:32.000Z | 2022-03-30T16:42:42.000Z | lib/plug/logger.ex | outstand/plug | e75d542b3028b5c1f348ac9d128306c46a6b6e70 | [
"Apache-2.0"
] | 502 | 2017-07-19T15:36:44.000Z | 2022-03-31T06:47:36.000Z | deps/plug/lib/plug/logger.ex | adrianomota/blog | ef3b2d2ed54f038368ead8234d76c18983caa75b | [
"MIT"
] | 376 | 2017-07-17T15:47:55.000Z | 2022-03-23T19:24:30.000Z | defmodule Plug.Logger do
@moduledoc """
A plug for logging basic request information in the format:
GET /index.html
Sent 200 in 572ms
To use it, just plug it into the desired module.
plug Plug.Logger, log: :debug
## Options
* `:log` - The log level at which this plug should log its request info.
Default is `:info`.
The [list of supported levels](https://hexdocs.pm/logger/Logger.html#module-levels)
is available in the `Logger` documentation.
"""
require Logger
alias Plug.Conn
@behaviour Plug
@impl true
def init(opts) do
Keyword.get(opts, :log, :info)
end
@impl true
def call(conn, level) do
Logger.log(level, fn ->
[conn.method, ?\s, conn.request_path]
end)
start = System.monotonic_time()
Conn.register_before_send(conn, fn conn ->
Logger.log(level, fn ->
stop = System.monotonic_time()
diff = System.convert_time_unit(stop - start, :native, :microsecond)
status = Integer.to_string(conn.status)
[connection_type(conn), ?\s, status, " in ", formatted_diff(diff)]
end)
conn
end)
end
defp formatted_diff(diff) when diff > 1000, do: [diff |> div(1000) |> Integer.to_string(), "ms"]
defp formatted_diff(diff), do: [Integer.to_string(diff), "µs"]
defp connection_type(%{state: :set_chunked}), do: "Chunked"
defp connection_type(_), do: "Sent"
end
| 24.894737 | 98 | 0.648344 |
f71ca810f2e75bc5330260800af416800a233897 | 3,245 | ex | Elixir | clients/double_click_bid_manager/lib/google_api/double_click_bid_manager/v1/api/sdf.ex | kolorahl/elixir-google-api | 46bec1e092eb84c6a79d06c72016cb1a13777fa6 | [
"Apache-2.0"
] | null | null | null | clients/double_click_bid_manager/lib/google_api/double_click_bid_manager/v1/api/sdf.ex | kolorahl/elixir-google-api | 46bec1e092eb84c6a79d06c72016cb1a13777fa6 | [
"Apache-2.0"
] | null | null | null | clients/double_click_bid_manager/lib/google_api/double_click_bid_manager/v1/api/sdf.ex | kolorahl/elixir-google-api | 46bec1e092eb84c6a79d06c72016cb1a13777fa6 | [
"Apache-2.0"
] | null | null | null | # Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE: This file is auto generated by the elixir code generator program.
# Do not edit this file manually.
defmodule GoogleApi.DoubleClickBidManager.V1.Api.Sdf do
@moduledoc """
API calls for all endpoints tagged `Sdf`.
"""
alias GoogleApi.DoubleClickBidManager.V1.Connection
alias GoogleApi.Gax.{Request, Response}
@library_version Mix.Project.config() |> Keyword.get(:version, "")
@doc """
Retrieves entities in SDF format.
## Parameters
* `connection` (*type:* `GoogleApi.DoubleClickBidManager.V1.Connection.t`) - Connection to server
* `optional_params` (*type:* `keyword()`) - Optional parameters
* `:alt` (*type:* `String.t`) - Data format for the response.
* `:fields` (*type:* `String.t`) - Selector specifying which fields to include in a partial response.
* `:key` (*type:* `String.t`) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
* `:oauth_token` (*type:* `String.t`) - OAuth 2.0 token for the current user.
* `:prettyPrint` (*type:* `boolean()`) - Returns response with indentations and line breaks.
* `:quotaUser` (*type:* `String.t`) - An opaque string that represents a user for quota purposes. Must not exceed 40 characters.
* `:userIp` (*type:* `String.t`) - Deprecated. Please use quotaUser instead.
* `:body` (*type:* `GoogleApi.DoubleClickBidManager.V1.Model.DownloadRequest.t`) -
* `opts` (*type:* `keyword()`) - Call options
## Returns
* `{:ok, %GoogleApi.DoubleClickBidManager.V1.Model.DownloadResponse{}}` on success
* `{:error, info}` on failure
"""
@spec doubleclickbidmanager_sdf_download(Tesla.Env.client(), keyword(), keyword()) ::
{:ok, GoogleApi.DoubleClickBidManager.V1.Model.DownloadResponse.t()}
| {:ok, Tesla.Env.t()}
| {:error, any()}
def doubleclickbidmanager_sdf_download(connection, optional_params \\ [], opts \\ []) do
optional_params_config = %{
:alt => :query,
:fields => :query,
:key => :query,
:oauth_token => :query,
:prettyPrint => :query,
:quotaUser => :query,
:userIp => :query,
:body => :body
}
request =
Request.new()
|> Request.method(:post)
|> Request.url("/sdf/download", %{})
|> Request.add_optional_params(optional_params_config, optional_params)
|> Request.library_version(@library_version)
connection
|> Connection.execute(request)
|> Response.decode(
opts ++ [struct: %GoogleApi.DoubleClickBidManager.V1.Model.DownloadResponse{}]
)
end
end
| 40.5625 | 187 | 0.669954 |
f71d10ef4d525194bd117aa4da56342f14daa9ad | 710 | exs | Elixir | mix.exs | Plus17/openpayex | dbff5051254fd3c040f86364cf40793804af9e66 | [
"MIT"
] | null | null | null | mix.exs | Plus17/openpayex | dbff5051254fd3c040f86364cf40793804af9e66 | [
"MIT"
] | 1 | 2019-08-19T03:53:19.000Z | 2019-08-19T03:53:19.000Z | mix.exs | Plus17/openpayex | dbff5051254fd3c040f86364cf40793804af9e66 | [
"MIT"
] | null | null | null | defmodule Openpayex.MixProject do
use Mix.Project
def project do
[
app: :openpayex,
version: "0.1.0",
elixir: "~> 1.7",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger, :plug_cowboy],
mod: {Openpayex.Application, []}
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:ex_doc, "~> 0.19", only: :dev, runtime: false},
{:credo, "~> 1.0.0", only: [:dev, :test], runtime: false},
{:jason, "~> 1.1"},
{:httpoison, "~> 1.4"},
{:plug_cowboy, "~> 2.0"}
]
end
end
| 21.515152 | 64 | 0.543662 |
f71d1713a32415580a0dde30a20d77da8cfc9835 | 4,396 | ex | Elixir | clients/content/lib/google_api/content/v21/model/return_policy_online.ex | pojiro/elixir-google-api | 928496a017d3875a1929c6809d9221d79404b910 | [
"Apache-2.0"
] | 1 | 2021-12-20T03:40:53.000Z | 2021-12-20T03:40:53.000Z | clients/content/lib/google_api/content/v21/model/return_policy_online.ex | pojiro/elixir-google-api | 928496a017d3875a1929c6809d9221d79404b910 | [
"Apache-2.0"
] | 1 | 2020-08-18T00:11:23.000Z | 2020-08-18T00:44:16.000Z | clients/content/lib/google_api/content/v21/model/return_policy_online.ex | pojiro/elixir-google-api | 928496a017d3875a1929c6809d9221d79404b910 | [
"Apache-2.0"
] | null | null | null | # Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE: This file is auto generated by the elixir code generator program.
# Do not edit this file manually.
defmodule GoogleApi.Content.V21.Model.ReturnPolicyOnline do
@moduledoc """
Return policy online object. This is currently used to represent return policies for ads and free listings programs.
## Attributes
* `countries` (*type:* `list(String.t)`, *default:* `nil`) - The countries of sale where the return policy is applicable. The values must be a valid 2 letter ISO 3166 code, e.g. "US".
* `itemConditions` (*type:* `list(String.t)`, *default:* `nil`) - The item conditions that are accepted for returns. This is required to not be empty unless the type of return policy is noReturns.
* `label` (*type:* `String.t`, *default:* `nil`) - The unique user-defined label of the return policy. The same label cannot be used in different return policies for the same country. Policies with the label 'default' will apply to all products, unless a product specifies a return_policy_label attribute.
* `name` (*type:* `String.t`, *default:* `nil`) - The name of the policy as shown in Merchant Center.
* `policy` (*type:* `GoogleApi.Content.V21.Model.ReturnPolicyOnlinePolicy.t`, *default:* `nil`) - The return policy.
* `restockingFee` (*type:* `GoogleApi.Content.V21.Model.ReturnPolicyOnlineRestockingFee.t`, *default:* `nil`) - The restocking fee that applies to all return reason categories. This would be treated as a free restocking fee if the value is not set.
* `returnMethods` (*type:* `list(String.t)`, *default:* `nil`) - The return methods of how customers can return an item. This value is required to not be empty unless the type of return policy is noReturns.
* `returnPolicyId` (*type:* `String.t`, *default:* `nil`) - Output only. Return policy ID generated by Google.
* `returnPolicyUri` (*type:* `String.t`, *default:* `nil`) - The return policy uri. This can used by Google to do a sanity check for the policy.
* `returnReasonCategoryInfo` (*type:* `list(GoogleApi.Content.V21.Model.ReturnPolicyOnlineReturnReasonCategoryInfo.t)`, *default:* `nil`) - The return reason category information. This required to not be empty unless the type of return policy is noReturns.
"""
use GoogleApi.Gax.ModelBase
@type t :: %__MODULE__{
:countries => list(String.t()) | nil,
:itemConditions => list(String.t()) | nil,
:label => String.t() | nil,
:name => String.t() | nil,
:policy => GoogleApi.Content.V21.Model.ReturnPolicyOnlinePolicy.t() | nil,
:restockingFee => GoogleApi.Content.V21.Model.ReturnPolicyOnlineRestockingFee.t() | nil,
:returnMethods => list(String.t()) | nil,
:returnPolicyId => String.t() | nil,
:returnPolicyUri => String.t() | nil,
:returnReasonCategoryInfo =>
list(GoogleApi.Content.V21.Model.ReturnPolicyOnlineReturnReasonCategoryInfo.t()) | nil
}
field(:countries, type: :list)
field(:itemConditions, type: :list)
field(:label)
field(:name)
field(:policy, as: GoogleApi.Content.V21.Model.ReturnPolicyOnlinePolicy)
field(:restockingFee, as: GoogleApi.Content.V21.Model.ReturnPolicyOnlineRestockingFee)
field(:returnMethods, type: :list)
field(:returnPolicyId)
field(:returnPolicyUri)
field(:returnReasonCategoryInfo,
as: GoogleApi.Content.V21.Model.ReturnPolicyOnlineReturnReasonCategoryInfo,
type: :list
)
end
defimpl Poison.Decoder, for: GoogleApi.Content.V21.Model.ReturnPolicyOnline do
def decode(value, options) do
GoogleApi.Content.V21.Model.ReturnPolicyOnline.decode(value, options)
end
end
defimpl Poison.Encoder, for: GoogleApi.Content.V21.Model.ReturnPolicyOnline do
def encode(value, options) do
GoogleApi.Gax.ModelBase.encode(value, options)
end
end
| 55.64557 | 309 | 0.719973 |
f71d1de0cc720dffe1a3882003c4f97f925d073f | 28,367 | exs | Elixir | apps/astarte_appengine_api/test/astarte_appengine_api_web/channels/rooms_channel_test.exs | Annopaolo/astarte | f8190e8bf044759a9b84bdeb5786a55b6f793a4f | [
"Apache-2.0"
] | 191 | 2018-03-30T13:23:08.000Z | 2022-03-02T12:05:32.000Z | apps/astarte_appengine_api/test/astarte_appengine_api_web/channels/rooms_channel_test.exs | Annopaolo/astarte | f8190e8bf044759a9b84bdeb5786a55b6f793a4f | [
"Apache-2.0"
] | 402 | 2018-03-30T13:37:00.000Z | 2022-03-31T16:47:10.000Z | apps/astarte_appengine_api/test/astarte_appengine_api_web/channels/rooms_channel_test.exs | Annopaolo/astarte | f8190e8bf044759a9b84bdeb5786a55b6f793a4f | [
"Apache-2.0"
] | 24 | 2018-03-30T13:29:48.000Z | 2022-02-28T11:10:26.000Z | #
# This file is part of Astarte.
#
# Copyright 2018 Ispirata Srl
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
defmodule Astarte.AppEngine.APIWeb.RoomsChannelTest do
use Astarte.AppEngine.APIWeb.ChannelCase
alias Astarte.AppEngine.API.Auth.RoomsUser
alias Astarte.AppEngine.API.DatabaseTestHelper
alias Astarte.AppEngine.API.Groups
alias Astarte.AppEngine.API.JWTTestHelper
alias Astarte.AppEngine.API.Rooms.EventsDispatcher
alias Astarte.AppEngine.API.Rooms.Room
alias Astarte.AppEngine.API.Utils
alias Astarte.AppEngine.APIWeb.RoomsChannel
alias Astarte.AppEngine.APIWeb.UserSocket
alias Astarte.Core.Triggers.SimpleEvents.IncomingDataEvent
alias Astarte.Core.Triggers.SimpleEvents.SimpleEvent
alias Astarte.RPC.Protocol.DataUpdaterPlant, as: Protocol
alias Astarte.RPC.Protocol.DataUpdaterPlant.Call
alias Astarte.RPC.Protocol.DataUpdaterPlant.DeleteVolatileTrigger
alias Astarte.RPC.Protocol.DataUpdaterPlant.GenericErrorReply
alias Astarte.RPC.Protocol.DataUpdaterPlant.GenericOkReply
alias Astarte.RPC.Protocol.DataUpdaterPlant.InstallVolatileTrigger
alias Astarte.RPC.Protocol.DataUpdaterPlant.Reply
import Mox
@all_access_regex ".*"
@realm "autotestrealm"
@authorized_room_name "letmein"
@device_id "9ZJmHWdwSjuXjPVaEMqkuA"
@interface_exact "com.Some.Interface"
@interface_regex "com.Some.Other.Interface"
@path "/my/watched/path"
@authorized_watch_path_exact "#{@device_id}/#{@interface_exact}#{@path}"
@authorized_watch_path_regex "#{@device_id}/#{@interface_regex}.*"
@grouped_device_id_1 "4UQbIokuRufdtbVZt9AsLg"
@grouped_device_id_2 "aWag-VlVKC--1S-vfzZ9uQ"
@group_name "my_group"
@authorized_group_watch_path "groups/#{@group_name}/#{@interface_exact}#{@path}"
@authorized_group "groups/#{@group_name}"
@dup_rpc_destination Protocol.amqp_queue()
@name "testwatch"
@data_simple_trigger %{
"type" => "data_trigger",
"interface_name" => @interface_exact,
"interface_major" => 2,
"on" => "incoming_data",
"value_match_operator" => ">",
"match_path" => @path,
"known_value" => 42
}
@device_simple_trigger %{
"type" => "device_trigger",
"on" => "device_connected",
"device_id" => @device_id
}
@timestamp 1_573_233_693_478
@unauthorized_reason %{reason: "unauthorized"}
@encoded_generic_ok_reply %Reply{
reply: {:generic_ok_reply, %GenericOkReply{async_operation: false}}
}
|> Reply.encode()
@error_string "unsupported_interface_aggregation"
@encoded_generic_error_reply %Reply{
error: true,
reply:
{:generic_error_reply,
%GenericErrorReply{error_name: @error_string}}
}
|> Reply.encode()
@event_simple_trigger_id Utils.get_uuid()
@event_value 1000
@simple_event %SimpleEvent{
simple_trigger_id: @event_simple_trigger_id,
# Populated in tests
parent_trigger_id: nil,
realm: @realm,
device_id: @device_id,
timestamp: @timestamp,
event: {
:incoming_data_event,
%IncomingDataEvent{
interface: @interface_exact,
path: @path,
bson_value: Cyanide.encode!(%{v: @event_value})
}
}
}
setup_all do
DatabaseTestHelper.create_test_keyspace()
:ok = DatabaseTestHelper.seed_data()
group_params = %{
group_name: @group_name,
devices: [@grouped_device_id_1, @grouped_device_id_2]
}
{:ok, _} = Groups.create_group(@realm, group_params)
on_exit(fn ->
DatabaseTestHelper.destroy_local_test_keyspace()
end)
:ok
end
describe "authentication" do
test "connection with empty params fails" do
assert :error = connect(UserSocket, %{})
end
test "connection with non-existing realm fails" do
token = JWTTestHelper.gen_channels_jwt_all_access_token()
assert :error = connect(UserSocket, %{"realm" => "nonexisting", "token" => token})
end
test "connection with valid realm and token succeeds" do
token = JWTTestHelper.gen_channels_jwt_all_access_token()
assert {:ok, socket} = connect(UserSocket, %{"realm" => @realm, "token" => token})
assert %RoomsUser{
join_authorizations: [@all_access_regex],
watch_authorizations: [@all_access_regex]
} = socket.assigns[:user]
end
end
describe "join authorization" do
setup [:room_join_authorized_socket]
test "fails with different realm", %{socket: socket} do
assert {:error, @unauthorized_reason} =
join(socket, "rooms:otherrealm:#{@authorized_room_name}")
end
test "fails with unauthorized room", %{socket: socket} do
assert {:error, @unauthorized_reason} =
join(socket, "rooms:#{@realm}:unauthorized_room_name")
end
test "fails with empty auth token" do
token = JWTTestHelper.gen_channels_jwt_token([])
{:ok, socket} = connect(UserSocket, %{"realm" => @realm, "token" => token})
assert {:error, @unauthorized_reason} =
join(socket, "rooms:#{@realm}:#{@authorized_room_name}")
end
test "succeeds with correct realm and room name", %{socket: socket} do
assert {:ok, _reply, socket} = join(socket, "rooms:#{@realm}:#{@authorized_room_name}")
assert socket.assigns[:room_name] == "#{@realm}:#{@authorized_room_name}"
assert Room.clients_count("#{@realm}:#{@authorized_room_name}") == 1
end
test "succeeds with all access token" do
token = JWTTestHelper.gen_channels_jwt_all_access_token()
{:ok, socket} = connect(UserSocket, %{"realm" => @realm, "token" => token})
assert {:ok, _reply, socket} = join(socket, "rooms:#{@realm}:#{@authorized_room_name}")
assert socket.assigns[:room_name] == "#{@realm}:#{@authorized_room_name}"
assert Room.clients_count("#{@realm}:#{@authorized_room_name}") == 1
end
end
describe "watch" do
setup [:join_socket_and_authorize_watch, :verify_on_exit!]
test "fails with invalid simple trigger", %{socket: socket} do
invalid_simple_trigger_payload = %{
"device_id" => @device_id,
"name" => @name,
"simple_trigger" => %{"type" => "invalid"}
}
ref = push(socket, "watch", invalid_simple_trigger_payload)
assert_reply(ref, :error, %{errors: _errors})
end
test "fails if without both device_id and group_name", %{socket: socket} do
invalid_simple_trigger_payload = %{
"name" => @name,
"simple_trigger" => @data_simple_trigger
}
ref = push(socket, "watch", invalid_simple_trigger_payload)
assert_reply ref, :error, %{errors: _errors}
end
test "fails if both device_id and group_name are specified", %{socket: socket} do
device_and_group_payload = %{
"device_id" => @device_id,
"group_name" => @group_name,
"name" => @name,
"simple_trigger" => @data_simple_trigger
}
ref = push(socket, "watch", device_and_group_payload)
assert_reply ref, :error, %{errors: _errors}
end
test "fails with group data_trigger if device_id is not *", %{socket: socket} do
invalid_payload = %{
"group_name" => @group_name,
"name" => @name,
"simple_trigger" => @device_simple_trigger
}
ref = push(socket, "watch", invalid_payload)
assert_reply ref, :error, %{reason: "device_id must be * for group triggers"}
end
test "fails on unauthorized paths", %{socket: socket} do
unauthorized_device_id = "0JS2C1qlTiS0JTmUC4vCKQ"
unauthorized_device_id_payload = %{
"device_id" => unauthorized_device_id,
"name" => @name,
"simple_trigger" => @data_simple_trigger
}
ref = push(socket, "watch", unauthorized_device_id_payload)
assert_reply(ref, :error, @unauthorized_reason)
unauthorized_interface =
Map.put(@data_simple_trigger, "interface_name", "com.OtherInterface")
unauthorized_interface_payload = %{
"device_id" => @device_id,
"name" => @name,
"simple_trigger" => unauthorized_interface
}
ref = push(socket, "watch", unauthorized_interface_payload)
assert_reply(ref, :error, @unauthorized_reason)
end
test "fails if RPC replies with an error", %{socket: socket, room_process: room_process} do
MockRPCClient
|> allow(self(), room_process)
|> expect(:rpc_call, fn _serialized_call, @dup_rpc_destination ->
{:ok, @encoded_generic_error_reply}
end)
watch_payload = %{
"device_id" => @device_id,
"name" => @name,
"simple_trigger" => @data_simple_trigger
}
ref = push(socket, "watch", watch_payload)
assert_reply(ref, :error, %{reason: @error_string})
end
test "succeeds on authorized exact path", %{socket: socket, room_process: room_process} do
MockRPCClient
|> allow(self(), room_process)
|> expect(:rpc_call, fn serialized_call, @dup_rpc_destination ->
assert %Call{call: {:install_volatile_trigger, %InstallVolatileTrigger{} = install_call}} =
Call.decode(serialized_call)
assert %InstallVolatileTrigger{
realm_name: @realm,
device_id: @device_id
} = install_call
{:ok, @encoded_generic_ok_reply}
end)
|> stub(:rpc_call, fn _serialized_call, @dup_rpc_destination ->
{:ok, @encoded_generic_ok_reply}
end)
watch_payload = %{
"device_id" => @device_id,
"name" => @name,
"simple_trigger" => @data_simple_trigger
}
ref = push(socket, "watch", watch_payload)
assert_broadcast("watch_added", _)
assert_reply(ref, :ok, %{})
watch_cleanup(socket, @name)
end
test "fails on duplicate", %{socket: socket, room_process: room_process} do
MockRPCClient
|> allow(self(), room_process)
|> expect(:rpc_call, fn serialized_call, @dup_rpc_destination ->
assert %Call{call: {:install_volatile_trigger, %InstallVolatileTrigger{} = install_call}} =
Call.decode(serialized_call)
assert %InstallVolatileTrigger{
realm_name: @realm,
device_id: @device_id
} = install_call
{:ok, @encoded_generic_ok_reply}
end)
|> stub(:rpc_call, fn _serialized_call, @dup_rpc_destination ->
{:ok, @encoded_generic_ok_reply}
end)
watch_payload = %{
"device_id" => @device_id,
"name" => @name,
"simple_trigger" => @data_simple_trigger
}
ref = push(socket, "watch", watch_payload)
assert_broadcast("watch_added", _)
assert_reply(ref, :ok, %{})
ref = push(socket, "watch", watch_payload)
assert_reply(ref, :error, %{reason: "already existing"})
watch_cleanup(socket, @name)
end
test "succeeds on authorized regex path", %{socket: socket, room_process: room_process} do
MockRPCClient
|> allow(self(), room_process)
|> expect(:rpc_call, fn serialized_call, @dup_rpc_destination ->
assert %Call{call: {:install_volatile_trigger, %InstallVolatileTrigger{} = install_call}} =
Call.decode(serialized_call)
assert %InstallVolatileTrigger{
realm_name: @realm,
device_id: @device_id
} = install_call
{:ok, @encoded_generic_ok_reply}
end)
|> stub(:rpc_call, fn _serialized_call, @dup_rpc_destination ->
{:ok, @encoded_generic_ok_reply}
end)
regex_trigger =
@data_simple_trigger
|> Map.put("interface_name", @interface_regex)
|> Map.put("match_path", "/a/random/path")
watch_payload = %{
"device_id" => @device_id,
"name" => @name,
"simple_trigger" => regex_trigger
}
ref = push(socket, "watch", watch_payload)
assert_broadcast("watch_added", _)
assert_reply(ref, :ok, %{})
watch_cleanup(socket, @name)
end
test "fails on device_trigger with conflicting device_ids", %{socket: socket} do
other_device_id = "0JS2C1qlTiS0JTmUC4vCKQ"
wrong_device_id_trigger =
@device_simple_trigger
|> Map.put("device_id", other_device_id)
conflicting_device_id_payload_1 = %{
"device_id" => @device_id,
"name" => @name,
"simple_trigger" => wrong_device_id_trigger
}
ref = push(socket, "watch", conflicting_device_id_payload_1)
assert_reply(ref, :error, @unauthorized_reason)
conflicting_device_id_payload_2 = %{
"device_id" => other_device_id,
"name" => @name,
"simple_trigger" => @device_simple_trigger
}
ref = push(socket, "watch", conflicting_device_id_payload_2)
assert_reply(ref, :error, @unauthorized_reason)
end
test "succeeds on authorized device_id", %{socket: socket, room_process: room_process} do
MockRPCClient
|> allow(self(), room_process)
|> expect(:rpc_call, fn serialized_call, @dup_rpc_destination ->
assert %Call{call: {:install_volatile_trigger, %InstallVolatileTrigger{} = install_call}} =
Call.decode(serialized_call)
assert %InstallVolatileTrigger{
realm_name: @realm,
device_id: @device_id
} = install_call
{:ok, @encoded_generic_ok_reply}
end)
|> stub(:rpc_call, fn _serialized_call, @dup_rpc_destination ->
{:ok, @encoded_generic_ok_reply}
end)
watch_payload = %{
"device_id" => @device_id,
"name" => @name,
"simple_trigger" => @device_simple_trigger
}
ref = push(socket, "watch", watch_payload)
assert_broadcast("watch_added", _)
assert_reply(ref, :ok, %{})
watch_cleanup(socket, @name)
end
test "installs volatile trigger to all devices with group WatchRequest", %{
socket: socket,
room_process: room_process
} do
MockRPCClient
|> allow(self(), room_process)
|> expect(:rpc_call, fn serialized_call, @dup_rpc_destination ->
assert %Call{call: {:install_volatile_trigger, %InstallVolatileTrigger{} = install_call}} =
Call.decode(serialized_call)
assert %InstallVolatileTrigger{
realm_name: @realm,
device_id: @grouped_device_id_1
} = install_call
{:ok, @encoded_generic_ok_reply}
end)
|> expect(:rpc_call, fn serialized_call, @dup_rpc_destination ->
assert %Call{call: {:install_volatile_trigger, %InstallVolatileTrigger{} = install_call}} =
Call.decode(serialized_call)
assert %InstallVolatileTrigger{
realm_name: @realm,
device_id: @grouped_device_id_2
} = install_call
{:ok, @encoded_generic_ok_reply}
end)
|> stub(:rpc_call, fn _serialized_call, @dup_rpc_destination ->
{:ok, @encoded_generic_ok_reply}
end)
watch_payload = %{
"group_name" => @group_name,
"name" => @name,
"simple_trigger" => @data_simple_trigger
}
ref = push(socket, "watch", watch_payload)
assert_broadcast "watch_added", _
assert_reply ref, :ok, %{}
watch_cleanup(socket, @name)
end
end
describe "unwatch" do
setup [:join_socket_and_authorize_watch, :verify_on_exit!]
test "fails with invalid params", %{socket: socket} do
invalid_payload = %{}
ref = push(socket, "unwatch", invalid_payload)
assert_reply(ref, :error, _)
end
test "fails for non existing", %{socket: socket} do
nonexisting_payload = %{"name" => "nonexisting"}
ref = push(socket, "unwatch", nonexisting_payload)
assert_reply(ref, :error, %{reason: "not found"})
end
test "fails if RPC replies with an error", %{socket: socket, room_process: room_process} do
MockRPCClient
|> allow(self(), room_process)
|> expect(:rpc_call, fn _serialized_install, @dup_rpc_destination ->
{:ok, @encoded_generic_ok_reply}
end)
|> expect(:rpc_call, fn _serialized_delete, @dup_rpc_destination ->
{:ok, @encoded_generic_error_reply}
end)
|> stub(:rpc_call, fn _serialized_call, @dup_rpc_destination ->
{:ok, @encoded_generic_ok_reply}
end)
watch_payload = %{
"device_id" => @device_id,
"name" => @name,
"simple_trigger" => @data_simple_trigger
}
ref = push(socket, "watch", watch_payload)
assert_broadcast("watch_added", _)
assert_reply(ref, :ok, %{})
unwatch_payload = %{"name" => @name}
ref = push(socket, "unwatch", unwatch_payload)
assert_reply(ref, :error, %{reason: "unwatch failed"})
watch_cleanup(socket, @name)
end
test "succeeds with valid name", %{socket: socket, room_process: room_process} do
MockRPCClient
|> allow(self(), room_process)
|> expect(:rpc_call, fn _serialized_install, @dup_rpc_destination ->
{:ok, @encoded_generic_ok_reply}
end)
|> expect(:rpc_call, fn _serialized_delete, @dup_rpc_destination ->
{:ok, @encoded_generic_ok_reply}
end)
|> stub(:rpc_call, fn _serialized_call, @dup_rpc_destination ->
{:ok, @encoded_generic_ok_reply}
end)
watch_payload = %{
"device_id" => @device_id,
"name" => @name,
"simple_trigger" => @data_simple_trigger
}
ref = push(socket, "watch", watch_payload)
assert_broadcast("watch_added", _)
assert_reply(ref, :ok, %{})
unwatch_payload = %{"name" => @name}
ref = push(socket, "unwatch", unwatch_payload)
assert_broadcast "watch_removed", _
assert_reply ref, :ok, %{}
end
test "correctly handles group volatile triggers", %{
socket: socket,
room_process: room_process
} do
MockRPCClient
|> allow(self(), room_process)
|> expect(:rpc_call, fn _serialized_install_1, @dup_rpc_destination ->
{:ok, @encoded_generic_ok_reply}
end)
|> expect(:rpc_call, fn _serialized_install_2, @dup_rpc_destination ->
{:ok, @encoded_generic_ok_reply}
end)
|> expect(:rpc_call, fn serialized_call, @dup_rpc_destination ->
assert %Call{call: {:delete_volatile_trigger, %DeleteVolatileTrigger{} = delete_call}} =
Call.decode(serialized_call)
assert %DeleteVolatileTrigger{
realm_name: @realm,
device_id: @grouped_device_id_1
} = delete_call
{:ok, @encoded_generic_ok_reply}
end)
|> expect(:rpc_call, fn serialized_call, @dup_rpc_destination ->
assert %Call{call: {:delete_volatile_trigger, %DeleteVolatileTrigger{} = delete_call}} =
Call.decode(serialized_call)
assert %DeleteVolatileTrigger{
realm_name: @realm,
device_id: @grouped_device_id_2
} = delete_call
{:ok, @encoded_generic_ok_reply}
end)
|> stub(:rpc_call, fn _serialized_call, @dup_rpc_destination ->
{:ok, @encoded_generic_ok_reply}
end)
watch_payload = %{
"group_name" => @group_name,
"name" => @name,
"simple_trigger" => @data_simple_trigger
}
ref = push(socket, "watch", watch_payload)
assert_broadcast "watch_added", _
assert_reply ref, :ok, %{}
unwatch_payload = %{"name" => @name}
ref = push(socket, "unwatch", unwatch_payload)
assert_broadcast "watch_removed", _
assert_reply ref, :ok, %{}
end
end
describe "incoming events" do
setup [:join_socket_and_authorize_watch, :verify_on_exit!]
test "an event directed towards an unexisting room uninstalls the trigger", %{
room_process: room_process
} do
MockRPCClient
|> allow(self(), room_process)
|> expect(:rpc_call, fn serialized_call, @dup_rpc_destination ->
assert %Call{
call: {
:delete_volatile_trigger,
serialized_delete
}
} = Call.decode(serialized_call)
assert %DeleteVolatileTrigger{
realm_name: @realm,
device_id: @device_id,
trigger_id: @event_simple_trigger_id
} = serialized_delete
{:ok, @encoded_generic_ok_reply}
end)
|> stub(:rpc_call, fn _serialized_call, @dup_rpc_destination ->
{:ok, @encoded_generic_ok_reply}
end)
unexisting_room_serialized_event =
%{@simple_event | parent_trigger_id: Utils.get_uuid()}
|> SimpleEvent.encode()
assert {:error, :no_room_for_event} =
EventsDispatcher.dispatch(unexisting_room_serialized_event)
refute_broadcast "new_event", %{"device_id" => @device_id, "event" => _event}
end
test "an event for an unwatched trigger uninstalls the trigger and doesn't trigger a broadcast",
%{room_process: room_process} do
MockRPCClient
|> allow(self(), room_process)
|> expect(:rpc_call, fn serialized_call, @dup_rpc_destination ->
assert %Call{
call: {
:delete_volatile_trigger,
serialized_delete
}
} = Call.decode(serialized_call)
assert %DeleteVolatileTrigger{
realm_name: @realm,
device_id: @device_id,
trigger_id: @event_simple_trigger_id
} = serialized_delete
{:ok, @encoded_generic_ok_reply}
end)
%{room_uuid: room_uuid} = :sys.get_state(room_process)
existing_room_serialized_event =
%{@simple_event | parent_trigger_id: room_uuid}
|> SimpleEvent.encode()
assert {:error, :trigger_not_found} =
EventsDispatcher.dispatch(existing_room_serialized_event)
refute_broadcast "new_event", %{"device_id" => @device_id, "event" => _event}
end
test "an event for a watched trigger belonging to a room triggers a broadcast", %{
socket: socket,
room_process: room_process
} do
MockRPCClient
|> allow(self(), room_process)
|> expect(:rpc_call, fn serialized_call, @dup_rpc_destination ->
assert %Call{call: {:install_volatile_trigger, %InstallVolatileTrigger{} = install_call}} =
Call.decode(serialized_call)
assert %InstallVolatileTrigger{
realm_name: @realm,
device_id: @device_id
} = install_call
{:ok, @encoded_generic_ok_reply}
end)
|> stub(:rpc_call, fn _serialized_call, @dup_rpc_destination ->
{:ok, @encoded_generic_ok_reply}
end)
watch_payload = %{
"device_id" => @device_id,
"name" => @name,
"simple_trigger" => @data_simple_trigger
}
ref = push(socket, "watch", watch_payload)
assert_broadcast("watch_added", _)
assert_reply(ref, :ok, %{})
%{room_uuid: room_uuid, watch_id_to_request: watch_map} = :sys.get_state(room_process)
[simple_trigger_id | _] = Map.keys(watch_map)
existing_room_serialized_event =
%{@simple_event | parent_trigger_id: room_uuid, simple_trigger_id: simple_trigger_id}
|> SimpleEvent.encode()
assert :ok = EventsDispatcher.dispatch(existing_room_serialized_event)
timestamp = DateTime.from_unix!(@timestamp, :millisecond)
assert_broadcast("new_event", %{
"device_id" => @device_id,
"timestamp" => ^timestamp,
"event" => event
})
assert %{
"type" => "incoming_data",
"interface" => @interface_exact,
"path" => @path,
"value" => @event_value
}
|> Jason.encode() == Jason.encode(event)
watch_cleanup(socket, @name)
end
test "work also with nil timestamp", %{
socket: socket,
room_process: room_process
} do
MockRPCClient
|> allow(self(), room_process)
|> expect(:rpc_call, fn serialized_call, @dup_rpc_destination ->
assert %Call{call: {:install_volatile_trigger, %InstallVolatileTrigger{} = install_call}} =
Call.decode(serialized_call)
assert %InstallVolatileTrigger{
realm_name: @realm,
device_id: @device_id
} = install_call
{:ok, @encoded_generic_ok_reply}
end)
|> stub(:rpc_call, fn _serialized_call, @dup_rpc_destination ->
{:ok, @encoded_generic_ok_reply}
end)
watch_payload = %{
"device_id" => @device_id,
"name" => @name,
"simple_trigger" => @data_simple_trigger
}
ref = push(socket, "watch", watch_payload)
assert_broadcast("watch_added", _)
assert_reply(ref, :ok, %{})
%{room_uuid: room_uuid, watch_id_to_request: watch_map} = :sys.get_state(room_process)
[simple_trigger_id | _] = Map.keys(watch_map)
existing_room_serialized_event =
%{
@simple_event
| parent_trigger_id: room_uuid,
simple_trigger_id: simple_trigger_id,
timestamp: nil
}
|> SimpleEvent.encode()
now_ms =
DateTime.utc_now()
|> DateTime.to_unix(:millisecond)
assert :ok = EventsDispatcher.dispatch(existing_room_serialized_event)
assert_broadcast("new_event", %{
"device_id" => @device_id,
"timestamp" => timestamp,
"event" => event
})
timestamp_ms = DateTime.to_unix(timestamp, :millisecond)
assert_in_delta(now_ms, timestamp_ms, 1_000)
assert %{
"type" => "incoming_data",
"interface" => @interface_exact,
"path" => @path,
"value" => @event_value
}
|> Jason.encode() == Jason.encode(event)
watch_cleanup(socket, @name)
end
end
defp room_join_authorized_socket(_context) do
token = JWTTestHelper.gen_channels_jwt_token(["JOIN::#{@authorized_room_name}"])
{:ok, socket} = connect(UserSocket, %{"realm" => @realm, "token" => token})
{:ok, socket: socket}
end
defp join_socket_and_authorize_watch(_context) do
token =
JWTTestHelper.gen_channels_jwt_token([
"JOIN::#{@authorized_room_name}",
"WATCH::#{@authorized_watch_path_exact}",
"WATCH::#{@authorized_watch_path_regex}",
"WATCH::#{@authorized_group_watch_path}",
"WATCH::#{@authorized_group}",
"WATCH::#{@device_id}"
])
room_name = "#{@realm}:#{@authorized_room_name}"
{:ok, socket} = connect(UserSocket, %{"realm" => @realm, "token" => token})
{:ok, _reply, socket} = subscribe_and_join(socket, RoomsChannel, "rooms:#{room_name}")
room_process = room_process(room_name)
{:ok, socket: socket, room_process: room_process}
end
defp room_process(room_name) do
case Registry.lookup(Registry.AstarteRooms, room_name) do
[{pid, _opts}] -> pid
end
end
defp watch_cleanup(socket, watch_name) do
# Manually cleanup watches to avoid MockRPC complaining about missing
# expectations due to the socket terminating (and cleaning up watches)
# after Mox on_exit callback has already been called (and expectations emptied)
payload = %{"name" => watch_name}
ref = push(socket, "unwatch", payload)
assert_broadcast "watch_removed", _
assert_reply ref, :ok, %{}
end
end
| 32.568312 | 100 | 0.627913 |
f71d6a263943d2e862c749223e02e172bb72836a | 2,333 | ex | Elixir | lib/chat_api_web/channels/user_socket.ex | ZmagoD/papercups | dff9a5822b809edc4fd8ecf198566f9b14ab613f | [
"MIT"
] | 4,942 | 2020-07-20T22:35:28.000Z | 2022-03-31T15:38:51.000Z | lib/chat_api_web/channels/user_socket.ex | ZmagoD/papercups | dff9a5822b809edc4fd8ecf198566f9b14ab613f | [
"MIT"
] | 552 | 2020-07-22T01:39:04.000Z | 2022-02-01T00:26:35.000Z | lib/chat_api_web/channels/user_socket.ex | ZmagoD/papercups | dff9a5822b809edc4fd8ecf198566f9b14ab613f | [
"MIT"
] | 396 | 2020-07-22T19:27:48.000Z | 2022-03-31T05:25:24.000Z | defmodule ChatApiWeb.UserSocket do
use Phoenix.Socket
## Channels
channel("room:*", ChatApiWeb.RoomChannel)
channel("conversation:*", ChatApiWeb.ConversationChannel)
channel("notification:*", ChatApiWeb.NotificationChannel)
channel("events:*", ChatApiWeb.EventChannel)
channel("issue:*", ChatApiWeb.IssueChannel)
# Socket params are passed from the client and can
# be used to verify and authenticate a user. After
# verification, you can put default assigns into
# the socket that will be set for all channels, ie
#
# {:ok, assign(socket, :user_id, verified_user_id)}
#
# To deny connection, return `:error`.
#
# See `Phoenix.Token` documentation for examples in
# performing token verification on connect.
@impl true
def connect(%{"token" => token}, socket, _connect_info) do
case get_credentials(socket, token, otp_app: :chat_api) do
nil -> :error
user -> {:ok, assign(socket, :current_user, user)}
end
end
def connect(_params, socket, _connect_info) do
{:ok, socket}
end
# Socket id's are topics that allow you to identify all sockets for a given user:
#
# def id(socket), do: "user_socket:#{socket.assigns.user_id}"
#
# Would allow you to broadcast a "disconnect" event and terminate
# all active sockets and channels for a given user:
#
# ChatApiWeb.Endpoint.broadcast("user_socket:#{user.id}", "disconnect", %{})
#
# Returning `nil` makes this socket anonymous.
@impl true
def id(_socket), do: nil
defp get_credentials(socket, signed_token, config) do
conn = %Plug.Conn{secret_key_base: socket.endpoint.config(:secret_key_base)}
store_config = [backend: store_config_backend()]
salt = Atom.to_string(ChatApiWeb.APIAuthPlug)
with {:ok, token} <- Pow.Plug.verify_token(conn, salt, signed_token, config),
{user, _metadata} <- Pow.Store.CredentialsCache.get(store_config, token) do
Sentry.Context.set_user_context(%{
id: user.id,
email: user.email,
account_id: user.account_id
})
user
else
_any -> nil
end
end
defp store_config_backend() do
# Uses Pow config :cache_store_backend, defaulting to ETS cache
Application.get_env(:chat_api, :pow)
|> Keyword.get(:cache_store_backend, Pow.Store.Backend.EtsCache)
end
end
| 32.402778 | 84 | 0.69267 |
f71d97f62937a470427b23c183fdaf58d0447587 | 1,547 | exs | Elixir | apps/wechat_base/test/wechat_base/api/endpoint/body_type/json_test.exs | secretworry/exwechat | 2d3a8bf03135eebd58452122c2f7b3718b5f5b3d | [
"Apache-2.0"
] | null | null | null | apps/wechat_base/test/wechat_base/api/endpoint/body_type/json_test.exs | secretworry/exwechat | 2d3a8bf03135eebd58452122c2f7b3718b5f5b3d | [
"Apache-2.0"
] | null | null | null | apps/wechat_base/test/wechat_base/api/endpoint/body_type/json_test.exs | secretworry/exwechat | 2d3a8bf03135eebd58452122c2f7b3718b5f5b3d | [
"Apache-2.0"
] | null | null | null | defmodule WechatBase.Api.Endpoint.BodyType.JsonTest do
use WechatBase.Api.Endpoint.BodyType.Case
alias WechatBase.Api.Endpoint.BodyType.Json
alias Maxwell.Conn
test "should embed a valid body" do
opts = Json.init([
{:string, "string", %{}, []},
{:integer, "integer", %{}, []},
{:float, "float", %{}, []},
{:object, "object", %{}, [
{:string, "key", %{}, []},
{:string, "value", %{}, []}
]},
{{:array, :string}, "array_of_string", %{}, []},
{{:map, :string}, "map_of_string", %{}, []}])
body = %{
"string" => "test",
"integer" => 42,
"float" => 4.2,
"object" => %{
"key" => "key",
"value" => "value"
},
"array_of_string" => ["a", "b"],
"map_of_string" => %{
"key0" => "value0",
"key1" => "value1"
}
}
{:ok, conn} = Json.embed(Conn.new("http://test.com"), body, opts)
assert conn.req_body == Poison.encode!(body)
assert conn.req_headers == %{"content-type" => "application/json"}
end
test "should reject a non-map body" do
opts = Json.init([])
assert_error Json.embed(Conn.new("http://test.com"), [], opts),
{:illegal_body, "Expect a map as body but got %{body}", %{body: []}}
end
test "should reject a invalid body" do
opts = Json.init([
{:string, "string", %{required?: true}, []}
])
assert_body_errors Json.embed(Conn.new("http://test.com"), %{}, opts),
[{"string", {"is required", []}}]
end
end | 30.333333 | 85 | 0.50808 |
f71dada897e8413deb64c18327ed2870ca4487d2 | 1,027 | exs | Elixir | test/edgedb/protocol/codecs/custom/short_str_test.exs | nsidnev/edgedb-elixir | bade2b9daba2e83bfaa5915b2addb74f41610968 | [
"MIT"
] | 30 | 2021-05-19T08:54:44.000Z | 2022-03-11T22:52:25.000Z | test/edgedb/protocol/codecs/custom/short_str_test.exs | nsidnev/edgedb-elixir | bade2b9daba2e83bfaa5915b2addb74f41610968 | [
"MIT"
] | 3 | 2021-11-17T21:26:01.000Z | 2022-03-12T09:49:25.000Z | test/edgedb/protocol/codecs/custom/short_str_test.exs | nsidnev/edgedb-elixir | bade2b9daba2e83bfaa5915b2addb74f41610968 | [
"MIT"
] | 3 | 2021-08-29T14:55:41.000Z | 2022-03-12T01:30:35.000Z | defmodule Tests.EdgeDB.Protocol.Codecs.Custom.ShortStrTest do
use Tests.Support.EdgeDBCase
alias EdgeDB.Protocol.Error
alias Tests.Support.Codecs
setup do
{:ok, conn} =
start_supervised(
{EdgeDB, codecs: [Codecs.ShortStr], show_sensitive_data_on_connection_error: true}
)
%{conn: conn}
end
test "decoding default::short_str value", %{conn: conn} do
value = "short"
assert ^value = EdgeDB.query_single!(conn, "SELECT <short_str>\"short\"")
end
test "encoding default::short_str value", %{conn: conn} do
value = "short"
assert ^value = EdgeDB.query_single!(conn, "SELECT <short_str>$0", [value])
end
test "error when passing value that can't be encoded by custom codec as default::short_str argument",
%{conn: conn} do
value = "too long string"
exc =
assert_raise Error, fn ->
EdgeDB.query_single!(conn, "SELECT <short_str>$0", [value])
end
assert exc == Error.invalid_argument_error("string is too long")
end
end
| 25.675 | 103 | 0.669912 |
f71dc6896700f4cbd6019dbe8b7a7507ef736cd9 | 1,429 | ex | Elixir | lib/ex_slack_notifier/attachment.ex | giraphme/ex_slack_notifier | 065ae95d4c3eb1deb4b407e3751833d6691060ee | [
"MIT"
] | null | null | null | lib/ex_slack_notifier/attachment.ex | giraphme/ex_slack_notifier | 065ae95d4c3eb1deb4b407e3751833d6691060ee | [
"MIT"
] | null | null | null | lib/ex_slack_notifier/attachment.ex | giraphme/ex_slack_notifier | 065ae95d4c3eb1deb4b407e3751833d6691060ee | [
"MIT"
] | null | null | null | defmodule ExSlackNotifier.Attachment do
@type t :: %__MODULE__{
fallback: String.t(),
color: String.t(),
pretext: String.t(),
author_name: String.t(),
author_link: String.t(),
author_icon: String.t(),
title: String.t(),
title_link: String.t(),
text: String.t(),
fields: list(),
image_url: String.t(),
thumb_url: String.t(),
footer: String.t(),
footer_icon: String.t(),
ts: integer
}
@fields [
:fallback,
:color,
:pretext,
:author_name,
:author_link,
:author_icon,
:title,
:title_link,
:text,
:fields,
:image_url,
:thumb_url,
:footer,
:footer_icon,
:ts
]
defstruct @fields
def build() do
%__MODULE__{}
end
@spec put(__MODULE__.t(), atom, String.t()) :: __MODULE__.t()
def put(%__MODULE__{} = this, key, value) when key in @fields do
%{this | key => value}
end
@spec append(__MODULE__.t(), atom, String.t()) :: __MODULE__.t()
def append(%__MODULE__{} = this, key, value) when key in @fields do
%{this | key => (Map.get(this, key, []) || []) ++ [value]}
end
def to_map(%__MODULE__{} = this) do
Enum.reduce(@fields, %{}, fn field, acc ->
value = Map.get(this, field, nil)
if is_nil(value), do: acc, else: Map.put_new(acc, field, value)
end)
end
end
| 23.42623 | 69 | 0.541638 |
f71e0b4808b26f127c37fefc12777cc04035c437 | 1,287 | exs | Elixir | mix.exs | wesleimp/vroom-elixir | 5c0bc5a8c9ce02f6415eb06a568f3310dfd8977d | [
"MIT"
] | 5 | 2021-04-14T15:02:59.000Z | 2021-04-28T19:18:00.000Z | mix.exs | wesleimp/vroom-elixir | 5c0bc5a8c9ce02f6415eb06a568f3310dfd8977d | [
"MIT"
] | 5 | 2021-04-13T22:03:29.000Z | 2021-05-12T12:47:41.000Z | mix.exs | wesleimp/vroom-elixir | 5c0bc5a8c9ce02f6415eb06a568f3310dfd8977d | [
"MIT"
] | 2 | 2021-04-14T16:39:35.000Z | 2021-04-28T19:17:53.000Z | defmodule VROOM.MixProject do
use Mix.Project
@version "0.1.6"
@source_url "https://github.com/wesleimp/vroom-elixir"
def project do
[
app: :vroom,
version: @version,
elixir: "~> 1.10",
start_permanent: Mix.env() == :prod,
deps: deps(),
description:
"Implementation of VROOM (Vehicle Routing Open-Source Optimization Machine) HTTP client",
package: package(),
docs: docs()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:tesla, "~> 1.4"},
{:jason, "~> 1.2"},
{:mint, "~> 1.3"},
{:castore, "~> 0.1"},
{:ex_doc, "~> 0.23", only: :dev, runtime: false},
{:credo, "~> 1.5", only: [:dev]}
]
end
defp package do
[
files: ["lib", "mix.exs", "README.md", "LICENSE"],
maintainers: ["Weslei Juan Moser Pereira"],
licenses: ["MIT"],
links: %{GitHub: @source_url}
]
end
defp docs do
[
main: "readme",
source_url: @source_url,
source_ref: "v#{@version}",
formatter_opts: [gfm: true],
extras: [
"README.md"
]
]
end
end
| 21.098361 | 97 | 0.540793 |
f71e4d97771c7d7dd592f565b92ed80eb1a4c2f9 | 1,743 | exs | Elixir | config/dev.exs | douglastofoli/rocketpay | 66dfe3b4d21cf3f1d23a98639f56c797156d6816 | [
"MIT"
] | 1 | 2021-02-27T00:16:26.000Z | 2021-02-27T00:16:26.000Z | config/dev.exs | douglastofoli/rocketpay | 66dfe3b4d21cf3f1d23a98639f56c797156d6816 | [
"MIT"
] | null | null | null | config/dev.exs | douglastofoli/rocketpay | 66dfe3b4d21cf3f1d23a98639f56c797156d6816 | [
"MIT"
] | 1 | 2021-02-27T01:26:17.000Z | 2021-02-27T01:26:17.000Z | use Mix.Config
# Configure your database
config :rocketpay, Rocketpay.Repo,
username: System.get_env("DB_DEV_USERNAME"),
password: System.get_env("DB_DEV_PASSWORD"),
database: System.get_env("DB_DEV_DATABASE"),
hostname: System.get_env("DB_DEV_HOST"),
show_sensitive_data_on_connection_error: true,
pool_size: 10
# For development, we disable any cache and enable
# debugging and code reloading.
#
# The watchers configuration can be used to run external
# watchers to your application. For example, we use it
# with webpack to recompile .js and .css sources.
config :rocketpay, RocketpayWeb.Endpoint,
http: [port: 4000],
debug_errors: true,
code_reloader: true,
check_origin: false,
watchers: []
# ## SSL Support
#
# In order to use HTTPS in development, a self-signed
# certificate can be generated by running the following
# Mix task:
#
# mix phx.gen.cert
#
# Note that this task requires Erlang/OTP 20 or later.
# Run `mix help phx.gen.cert` for more information.
#
# The `http:` config above can be replaced with:
#
# https: [
# port: 4001,
# cipher_suite: :strong,
# keyfile: "priv/cert/selfsigned_key.pem",
# certfile: "priv/cert/selfsigned.pem"
# ],
#
# If desired, both `http:` and `https:` keys can be
# configured to run both http and https servers on
# different ports.
# Do not include metadata nor timestamps in development logs
config :logger, :console, format: "[$level] $message\n"
# Set a higher stacktrace during development. Avoid configuring such
# in production as building large stacktraces may be expensive.
config :phoenix, :stacktrace_depth, 20
# Initialize plugs at runtime for faster development compilation
config :phoenix, :plug_init_mode, :runtime
| 30.051724 | 68 | 0.733792 |
f71e4efc7a1c5595d279069e563bc7c3cd696416 | 1,183 | exs | Elixir | installer/templates/new/test/views/error_view_test.exs | manukall/phoenix | 5ce19ebb63b1b31e37da5fe6465edb6c4850772e | [
"MIT"
] | 1 | 2019-06-11T20:22:21.000Z | 2019-06-11T20:22:21.000Z | installer/templates/new/test/views/error_view_test.exs | DavidAlphaFox/phoenix | 560131ab3b48c6b6cf864a3d20b7667e40990237 | [
"MIT"
] | null | null | null | installer/templates/new/test/views/error_view_test.exs | DavidAlphaFox/phoenix | 560131ab3b48c6b6cf864a3d20b7667e40990237 | [
"MIT"
] | null | null | null | defmodule <%= application_module %>.ErrorViewTest do
use <%= application_module %>.ConnCase, async: true
# Bring render/3 and render_to_string/3 for testing custom views
import Phoenix.View
<%= if html do %>test "renders 404.html" do
assert render_to_string(<%= application_module %>.ErrorView, "404.html", []) ==
"Page not found"
end
test "render 500.html" do
assert render_to_string(<%= application_module %>.ErrorView, "500.html", []) ==
"Server internal error"
end
test "render any other" do
assert render_to_string(<%= application_module %>.ErrorView, "505.html", []) ==
"Server internal error"
end<% else %>test "renders 404.json" do
assert render(<%= application_module %>.ErrorView, "404.json", []) ==
%{errors: %{detail: "Page not found"}}
end
test "render 500.json" do
assert render(<%= application_module %>.ErrorView, "500.json", []) ==
%{errors: %{detail: "Server internal error"}}
end
test "render any other" do
assert render(<%= application_module %>.ErrorView, "505.json", []) ==
%{errors: %{detail: "Server internal error"}}
end<% end %>
end
| 33.8 | 83 | 0.6306 |
f71e548a0a157bfa89bd3494770630bc6a06a619 | 1,381 | ex | Elixir | test/support/data_case.ex | spawnfest/fuchsia-team | 26aa4ee5a6e8ab023ef9038a35b35f4deed16a7d | [
"MIT"
] | 2 | 2019-05-25T18:34:43.000Z | 2020-01-20T17:35:31.000Z | test/support/data_case.ex | spawnfest/fuchsia-team | 26aa4ee5a6e8ab023ef9038a35b35f4deed16a7d | [
"MIT"
] | 1 | 2019-01-25T19:16:23.000Z | 2019-08-30T18:40:10.000Z | test/support/data_case.ex | spawnfest/fuchsia-team | 26aa4ee5a6e8ab023ef9038a35b35f4deed16a7d | [
"MIT"
] | null | null | null | defmodule Eligit.DataCase do
@moduledoc """
This module defines the setup for tests requiring
access to the application's data layer.
You may define functions here to be used as helpers in
your tests.
Finally, if the test case interacts with the database,
it cannot be async. For this reason, every test runs
inside a transaction which is reset at the beginning
of the test unless the test case is marked as async.
"""
use ExUnit.CaseTemplate
using do
quote do
alias Eligit.Repo
import Ecto
import Ecto.Changeset
import Ecto.Query
import Eligit.DataCase
end
end
setup tags do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Eligit.Repo)
unless tags[:async] do
Ecto.Adapters.SQL.Sandbox.mode(Eligit.Repo, {:shared, self()})
end
:ok
end
@doc """
A helper that transforms changeset errors into a map of messages.
assert {:error, changeset} = Accounts.create_user(%{password: "short"})
assert "password is too short" in errors_on(changeset).password
assert %{password: ["password is too short"]} = errors_on(changeset)
"""
def errors_on(changeset) do
Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
Enum.reduce(opts, message, fn {key, value}, acc ->
String.replace(acc, "%{#{key}}", to_string(value))
end)
end)
end
end
| 25.574074 | 77 | 0.679218 |
f71e7f0c8fb5660395f14ec2e883978938e744d4 | 776 | ex | Elixir | lib/anchore_engine_api_server/model/api_error_response.ex | michaeljguarino/anchore-elixir-client | 156a44f429ecb62433729a2b4c52de5dc0ef44d2 | [
"MIT"
] | null | null | null | lib/anchore_engine_api_server/model/api_error_response.ex | michaeljguarino/anchore-elixir-client | 156a44f429ecb62433729a2b4c52de5dc0ef44d2 | [
"MIT"
] | null | null | null | lib/anchore_engine_api_server/model/api_error_response.ex | michaeljguarino/anchore-elixir-client | 156a44f429ecb62433729a2b4c52de5dc0ef44d2 | [
"MIT"
] | null | null | null | # NOTE: This class is auto generated by the swagger code generator program.
# https://github.com/swagger-api/swagger-codegen.git
# Do not edit the class manually.
defmodule AnchoreEngineAPIServer.Model.ApiErrorResponse do
@moduledoc """
Generic HTTP API error response
"""
@derive [Poison.Encoder]
defstruct [
:code,
:detail,
:error_type,
:message
]
@type t :: %__MODULE__{
:code => integer(),
:detail => Object,
:error_type => String.t,
:message => String.t
}
end
defimpl Poison.Decoder, for: AnchoreEngineAPIServer.Model.ApiErrorResponse do
import AnchoreEngineAPIServer.Deserializer
def decode(value, options) do
value
|> deserialize(:detail, :struct, AnchoreEngineAPIServer.Model.Object, options)
end
end
| 22.823529 | 82 | 0.706186 |
f71e8810141e7a873b144bf6cdb71987ee2f139b | 1,641 | exs | Elixir | config/dev.exs | c18t/elixir-phx-websocket-chat | 4dc921599b263a856a23d04200631bfee83e3fc3 | [
"WTFPL"
] | null | null | null | config/dev.exs | c18t/elixir-phx-websocket-chat | 4dc921599b263a856a23d04200631bfee83e3fc3 | [
"WTFPL"
] | null | null | null | config/dev.exs | c18t/elixir-phx-websocket-chat | 4dc921599b263a856a23d04200631bfee83e3fc3 | [
"WTFPL"
] | 1 | 2020-11-17T08:23:18.000Z | 2020-11-17T08:23:18.000Z | use Mix.Config
# For development, we disable any cache and enable
# debugging and code reloading.
#
# The watchers configuration can be used to run external
# watchers to your application. For example, we use it
# with brunch.io to recompile .js and .css sources.
config :websocket_chat, WebsocketChatWeb.Endpoint,
http: [port: 4000],
debug_errors: true,
code_reloader: true,
check_origin: false,
watchers: []
# ## SSL Support
#
# In order to use HTTPS in development, a self-signed
# certificate can be generated by running the following
# command from your terminal:
#
# openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 -subj "/C=US/ST=Denial/L=Springfield/O=Dis/CN=www.example.com" -keyout priv/server.key -out priv/server.pem
#
# The `http:` config above can be replaced with:
#
# https: [port: 4000, keyfile: "priv/server.key", certfile: "priv/server.pem"],
#
# If desired, both `http:` and `https:` keys can be
# configured to run both http and https servers on
# different ports.
# Watch static and templates for browser reloading.
config :websocket_chat, WebsocketChatWeb.Endpoint,
live_reload: [
patterns: [
~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
~r{priv/gettext/.*(po)$},
~r{lib/websocket_chat_web/views/.*(ex)$},
~r{lib/websocket_chat_web/templates/.*(eex)$}
]
]
# Do not include metadata nor timestamps in development logs
config :logger, :console, format: "[$level] $message\n"
# Set a higher stacktrace during development. Avoid configuring such
# in production as building large stacktraces may be expensive.
config :phoenix, :stacktrace_depth, 20
| 33.489796 | 170 | 0.718464 |
f71e9ed6d769fa0f013dc3b66aad1123ec69b4db | 753 | ex | Elixir | web/router.ex | ssuprunenko/phoenix-vue-2-example | 78498514927ed507ef911877f9fea8ef88541193 | [
"MIT"
] | 67 | 2016-10-01T03:17:18.000Z | 2021-01-17T15:04:27.000Z | web/router.ex | marvelperseus/phoenix-vue-2-example | 78498514927ed507ef911877f9fea8ef88541193 | [
"MIT"
] | 1 | 2017-01-03T11:30:20.000Z | 2017-01-03T11:30:20.000Z | web/router.ex | marvelperseus/phoenix-vue-2-example | 78498514927ed507ef911877f9fea8ef88541193 | [
"MIT"
] | 10 | 2016-10-15T15:36:46.000Z | 2019-07-29T01:58:03.000Z | defmodule Web.Router do
use Web.Web, :router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
pipeline :api do
plug :accepts, ["json"]
end
scope "/", Web do
pipe_through :browser # Use the default browser stack
get "/", PageController, :index
get "/sample", PageController, :sample
get "/chat", PageController, :chat
resources "/links", LinkController, only: [:index, :show]
end
# Other scopes may use custom stacks.
scope "/api", Web do
pipe_through :api
get "/random", PageController, :random
resources "/links", LinkController, only: [:create, :update, :delete]
end
end
| 22.818182 | 73 | 0.667995 |
f71ea26b00e5795a5dcecd7b57063547b922c676 | 216 | exs | Elixir | priv/repo/migrations/20160327180557_add_email_index.exs | simwms/apiv4 | c3da7407eaf3580b759f49726028439b4b8ea9d0 | [
"MIT"
] | 2 | 2016-02-25T20:12:35.000Z | 2018-01-03T00:03:12.000Z | priv/repo/migrations/20160327180557_add_email_index.exs | simwms/apiv4 | c3da7407eaf3580b759f49726028439b4b8ea9d0 | [
"MIT"
] | 1 | 2016-01-11T04:50:39.000Z | 2016-01-12T05:00:08.000Z | priv/repo/migrations/20160327180557_add_email_index.exs | simwms/apiv4 | c3da7407eaf3580b759f49726028439b4b8ea9d0 | [
"MIT"
] | null | null | null | defmodule Apiv4.Repo.Migrations.AddEmailIndex do
use Ecto.Migration
def change do
create unique_index(:users, [:email])
create index(:employees, [:email])
create index(:sessions, [:email])
end
end
| 21.6 | 48 | 0.708333 |
f71ea2bbbf9166fb0fbbaabc8d325ce7c78507a0 | 2,594 | ex | Elixir | clients/service_usage/lib/google_api/service_usage/v1/model/o_auth_requirements.ex | pojiro/elixir-google-api | 928496a017d3875a1929c6809d9221d79404b910 | [
"Apache-2.0"
] | 1 | 2021-12-20T03:40:53.000Z | 2021-12-20T03:40:53.000Z | clients/service_usage/lib/google_api/service_usage/v1/model/o_auth_requirements.ex | pojiro/elixir-google-api | 928496a017d3875a1929c6809d9221d79404b910 | [
"Apache-2.0"
] | 1 | 2020-08-18T00:11:23.000Z | 2020-08-18T00:44:16.000Z | clients/service_usage/lib/google_api/service_usage/v1/model/o_auth_requirements.ex | pojiro/elixir-google-api | 928496a017d3875a1929c6809d9221d79404b910 | [
"Apache-2.0"
] | null | null | null | # Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE: This file is auto generated by the elixir code generator program.
# Do not edit this file manually.
defmodule GoogleApi.ServiceUsage.V1.Model.OAuthRequirements do
@moduledoc """
OAuth scopes are a way to define data and permissions on data. For example, there are scopes defined for "Read-only access to Google Calendar" and "Access to Cloud Platform". Users can consent to a scope for an application, giving it permission to access that data on their behalf. OAuth scope specifications should be fairly coarse grained; a user will need to see and understand the text description of what your scope means. In most cases: use one or at most two OAuth scopes for an entire family of products. If your product has multiple APIs, you should probably be sharing the OAuth scope across all of those APIs. When you need finer grained OAuth consent screens: talk with your product management about how developers will use them in practice. Please note that even though each of the canonical scopes is enough for a request to be accepted and passed to the backend, a request can still fail due to the backend requiring additional scopes or permissions.
## Attributes
* `canonicalScopes` (*type:* `String.t`, *default:* `nil`) - The list of publicly documented OAuth scopes that are allowed access. An OAuth token containing any of these scopes will be accepted. Example: canonical_scopes: https://www.googleapis.com/auth/calendar, https://www.googleapis.com/auth/calendar.read
"""
use GoogleApi.Gax.ModelBase
@type t :: %__MODULE__{
:canonicalScopes => String.t() | nil
}
field(:canonicalScopes)
end
defimpl Poison.Decoder, for: GoogleApi.ServiceUsage.V1.Model.OAuthRequirements do
def decode(value, options) do
GoogleApi.ServiceUsage.V1.Model.OAuthRequirements.decode(value, options)
end
end
defimpl Poison.Encoder, for: GoogleApi.ServiceUsage.V1.Model.OAuthRequirements do
def encode(value, options) do
GoogleApi.Gax.ModelBase.encode(value, options)
end
end
| 55.191489 | 967 | 0.771781 |
f71eaa1574f7bca55df367ef435db06d5dffdcca | 116 | ex | Elixir | assets/resolvers.ex | valerybugakov/gqlSlides | 7ca310b222738673abbecbfa7345acd316b28008 | [
"MIT"
] | null | null | null | assets/resolvers.ex | valerybugakov/gqlSlides | 7ca310b222738673abbecbfa7345acd316b28008 | [
"MIT"
] | null | null | null | assets/resolvers.ex | valerybugakov/gqlSlides | 7ca310b222738673abbecbfa7345acd316b28008 | [
"MIT"
] | null | null | null | function getViewer(request) {
return request.auth.user
}
function getUserName(user) {
return user.getName()
}
| 12.888889 | 29 | 0.732759 |
f71eaa8af4ce330d116f2b0f2c1870cac8f69350 | 1,858 | ex | Elixir | clients/gmail_postmaster_tools/lib/google_api/gmail_postmaster_tools/v1beta1/model/list_domains_response.ex | MasashiYokota/elixir-google-api | 975dccbff395c16afcb62e7a8e411fbb58e9ab01 | [
"Apache-2.0"
] | null | null | null | clients/gmail_postmaster_tools/lib/google_api/gmail_postmaster_tools/v1beta1/model/list_domains_response.ex | MasashiYokota/elixir-google-api | 975dccbff395c16afcb62e7a8e411fbb58e9ab01 | [
"Apache-2.0"
] | 1 | 2020-12-18T09:25:12.000Z | 2020-12-18T09:25:12.000Z | clients/gmail_postmaster_tools/lib/google_api/gmail_postmaster_tools/v1beta1/model/list_domains_response.ex | MasashiYokota/elixir-google-api | 975dccbff395c16afcb62e7a8e411fbb58e9ab01 | [
"Apache-2.0"
] | 1 | 2020-10-04T10:12:44.000Z | 2020-10-04T10:12:44.000Z | # Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE: This file is auto generated by the elixir code generator program.
# Do not edit this file manually.
defmodule GoogleApi.GmailPostmasterTools.V1beta1.Model.ListDomainsResponse do
@moduledoc """
Response message for ListDomains.
## Attributes
* `domains` (*type:* `list(GoogleApi.GmailPostmasterTools.V1beta1.Model.Domain.t)`, *default:* `nil`) - The list of domains.
* `nextPageToken` (*type:* `String.t`, *default:* `nil`) - Token to retrieve the next page of results, or empty if there are no more results in the list.
"""
use GoogleApi.Gax.ModelBase
@type t :: %__MODULE__{
:domains => list(GoogleApi.GmailPostmasterTools.V1beta1.Model.Domain.t()),
:nextPageToken => String.t()
}
field(:domains, as: GoogleApi.GmailPostmasterTools.V1beta1.Model.Domain, type: :list)
field(:nextPageToken)
end
defimpl Poison.Decoder, for: GoogleApi.GmailPostmasterTools.V1beta1.Model.ListDomainsResponse do
def decode(value, options) do
GoogleApi.GmailPostmasterTools.V1beta1.Model.ListDomainsResponse.decode(value, options)
end
end
defimpl Poison.Encoder, for: GoogleApi.GmailPostmasterTools.V1beta1.Model.ListDomainsResponse do
def encode(value, options) do
GoogleApi.Gax.ModelBase.encode(value, options)
end
end
| 37.16 | 157 | 0.748116 |
f71eb19861fbef63e11126c590faf041c89c0e87 | 435 | ex | Elixir | lib/pippo/flow.ex | pippo-ex/pippo | 5d8666a53414855647ed95b122dcf43f299c81be | [
"MIT"
] | null | null | null | lib/pippo/flow.ex | pippo-ex/pippo | 5d8666a53414855647ed95b122dcf43f299c81be | [
"MIT"
] | null | null | null | lib/pippo/flow.ex | pippo-ex/pippo | 5d8666a53414855647ed95b122dcf43f299c81be | [
"MIT"
] | null | null | null | defmodule Pippo.Flow do
use Supervisor
def start_link(opts) do
Supervisor.start_link(__MODULE__, opts, name: __MODULE__)
end
def init(_opts) do
children =
Enum.map(Application.get_env(:pippo, :producers), fn {mod, args} -> worker(mod, args) end) ++
Enum.map(Application.get_env(:pippo, :consumers), fn {mod, args} -> worker(mod, args) end)
Supervisor.init(children, strategy: :one_for_one)
end
end
| 27.1875 | 99 | 0.689655 |
f71eb7839b7c108f9dc55b342750b35499c13da8 | 2,890 | ex | Elixir | rustler_mix/lib/mix/tasks/rustler.new.ex | BurntCaramel/rustler | 9ece1e1da22f1a99383c04302549d6a5cd6abe34 | [
"Apache-2.0",
"MIT"
] | null | null | null | rustler_mix/lib/mix/tasks/rustler.new.ex | BurntCaramel/rustler | 9ece1e1da22f1a99383c04302549d6a5cd6abe34 | [
"Apache-2.0",
"MIT"
] | null | null | null | rustler_mix/lib/mix/tasks/rustler.new.ex | BurntCaramel/rustler | 9ece1e1da22f1a99383c04302549d6a5cd6abe34 | [
"Apache-2.0",
"MIT"
] | null | null | null | defmodule Mix.Tasks.Rustler.New do
use Mix.Task
import Mix.Generator
@shortdoc "Creates a new Rustler project"
@moduledoc """
Generates boilerplate for a new Rustler project.
Usage:
mix rustler.new path
"""
@basic [
{:eex, "basic/.cargo/config", ".cargo/config"},
{:eex, "basic/README.md", "README.md"},
{:eex, "basic/Cargo.toml.eex", "Cargo.toml"},
{:eex, "basic/src/lib.rs", "src/lib.rs"}
]
root = Path.join(:code.priv_dir(:rustler), "templates/")
for {format, source, _} <- @basic do
unless format == :keep do
@external_resource Path.join(root, source)
def render(unquote(source)), do: unquote(File.read!(Path.join(root, source)))
end
end
@switches []
def run(argv) do
{opts, _argv, _} = OptionParser.parse(argv, switches: @switches)
module =
prompt(
"This is the name of the Elixir module the NIF module will be registered to.\nModule name"
)
name =
prompt_default(
"This is the name used for the generated Rust crate. The default is most likely fine.\nLibrary name",
format_module_name_as_name(module)
)
check_module_name_validity!(module)
path = Path.join([File.cwd!(), "native/", name])
new(path, module, name, opts)
end
def new(path, module, name, _opts) do
module_elixir = "Elixir." <> module
binding = [
project_name: module_elixir,
native_module: module_elixir,
module: module,
library_name: name,
rustler_version: Rustler.rustler_version()
]
copy_from(path, binding, @basic)
Mix.Shell.IO.info([:green, "Ready to go! See #{path}/README.md for further instructions."])
end
defp check_module_name_validity!(name) do
unless name =~ ~r/^[A-Z]\w*(\.[A-Z]\w*)*$/ do
Mix.raise(
"Module name must be a valid Elixir alias (for example: Foo.Bar), got: #{inspect(name)}"
)
end
end
defp format_module_name_as_name(module_name) do
String.replace(String.downcase(module_name), ".", "_")
end
defp copy_from(target_dir, binding, mapping) when is_list(mapping) do
for {format, source, target_path} <- mapping do
target = Path.join(target_dir, target_path)
case format do
:keep ->
File.mkdir_p!(target)
:text ->
create_file(target, render(source))
:eex ->
contents = EEx.eval_string(render(source), binding, file: source)
create_file(target, contents)
end
end
end
def prompt_default(message, default) do
response = prompt([message, :white, " (", default, ")"])
case response do
"" -> default
_ -> response
end
end
def prompt(message) do
Mix.Shell.IO.print_app()
resp = IO.gets(IO.ANSI.format([message, :white, " > "]))
?\n = :binary.last(resp)
:binary.part(resp, {0, byte_size(resp) - 1})
end
end
| 25.575221 | 109 | 0.624913 |
f71f2df182ee3c16df81509cadddb7d24e7e2f91 | 120 | ex | Elixir | tags_service/lib/nlw07_heat_tags/repo.ex | miguelriosoliveira/dowhile-mural | 3f616bf7d536f0442b41f6f8795af43ed54e61a0 | [
"MIT"
] | null | null | null | tags_service/lib/nlw07_heat_tags/repo.ex | miguelriosoliveira/dowhile-mural | 3f616bf7d536f0442b41f6f8795af43ed54e61a0 | [
"MIT"
] | null | null | null | tags_service/lib/nlw07_heat_tags/repo.ex | miguelriosoliveira/dowhile-mural | 3f616bf7d536f0442b41f6f8795af43ed54e61a0 | [
"MIT"
] | null | null | null | defmodule Nlw07HeatTags.Repo do
use Ecto.Repo,
otp_app: :nlw07_heat_tags,
adapter: Ecto.Adapters.Postgres
end
| 20 | 35 | 0.758333 |
f71f8908438d209b4986aad944064b33996cbcd2 | 1,543 | ex | Elixir | apps/pipeline/lib/pipeline/writer/table_writer/statement.ex | calebcarroll1/smartcitiesdata | b0f03496f6c592c82ba14aebf6c5996311cf3cd0 | [
"Apache-2.0"
] | 26 | 2019-09-20T23:54:45.000Z | 2020-08-20T14:23:32.000Z | apps/pipeline/lib/pipeline/writer/table_writer/statement.ex | calebcarroll1/smartcitiesdata | b0f03496f6c592c82ba14aebf6c5996311cf3cd0 | [
"Apache-2.0"
] | 757 | 2019-08-15T18:15:07.000Z | 2020-09-18T20:55:31.000Z | apps/pipeline/lib/pipeline/writer/table_writer/statement.ex | calebcarroll1/smartcitiesdata | b0f03496f6c592c82ba14aebf6c5996311cf3cd0 | [
"Apache-2.0"
] | 9 | 2019-11-12T16:43:46.000Z | 2020-03-25T16:23:16.000Z | defmodule Pipeline.Writer.TableWriter.Statement do
@moduledoc false
alias Pipeline.Writer.TableWriter.Statement.{Create, Insert}
require Logger
defmodule FieldTypeError do
@moduledoc false
defexception message: "Encountered an unsupported field type"
end
def create(%{table: name, as: select}) do
{:ok, "create table #{name} as (#{select})"}
end
def create(%{table: name, schema: schema, format: format}) do
{:ok, Create.compose(name, schema, format)}
rescue
e in FieldTypeError ->
{:error, e.message}
e ->
{:error, "Unable to parse schema: #{inspect(e)}"}
end
def create(%{table: name, schema: schema}) do
{:ok, Create.compose(name, schema)}
rescue
e in FieldTypeError ->
{:error, e.message}
e ->
{:error, "Unable to parse schema: #{inspect(e)}"}
end
def insert(config, content) do
with {:ok, statement} <- Insert.compose(config, content) do
statement
end
end
def drop(%{table: table}) do
"drop table if exists #{table}"
end
def truncate(%{table: table}) do
"delete from #{table}"
end
def alter(%{table: table, alteration: change}) do
"alter table #{table} #{change}"
end
def union(table_one, table_two) do
"select * from #{table_one} union all select * from #{table_two}"
end
def create_new_table_with_existing_table(%{new_table_name: new_table_name, table_name: table_name}) do
%{table: "#{new_table_name}", as: "select * from #{table_name}"}
|> create()
|> elem(1)
end
end
| 23.738462 | 104 | 0.648088 |
f71fab9aff5423144a6765aafae68c3f50d2bfe6 | 18,323 | exs | Elixir | test/manager_test.exs | rentpath/slack_queue_bot | 0fc6b8b729f05e752511baca810df1f9f9d425a6 | [
"MIT"
] | 1 | 2020-01-13T22:09:09.000Z | 2020-01-13T22:09:09.000Z | test/manager_test.exs | rentpath/slack_queue_bot | 0fc6b8b729f05e752511baca810df1f9f9d425a6 | [
"MIT"
] | 5 | 2017-10-23T19:33:42.000Z | 2019-01-18T15:16:13.000Z | test/manager_test.exs | rentpath/slack_queue_bot | 0fc6b8b729f05e752511baca810df1f9f9d425a6 | [
"MIT"
] | null | null | null | defmodule QueueBot.ManagerTest do
use ExUnit.Case, async: true
setup do
{:ok, %{channel: make_ref()}}
end
describe "#help" do
test "returns help items", %{channel: channel} do
name = Application.get_env(:queue_bot, :slack)[:name]
help_items = QueueBot.Manager.call({channel, {:help}})
assert Enum.all?(help_items, &(String.starts_with?(&1, "/#{name}")))
end
end
describe "#pop" do
test "removes the top item", %{channel: channel} do
items = ["so", "ti", "fa"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:display, 100, "llama"}})
assert get_item_texts(queue) == ["so", "ti", "fa"]
%{"queue" => new_queue} = QueueBot.Manager.call({channel, {:pop, 100, "llama"}})
assert get_item_texts(new_queue) == ["ti", "fa"]
end
test "with no items in the queue returns new_first? false", %{channel: channel} do
%{"queue" => queue} = QueueBot.Manager.call({channel, {:display, 100, "llama"}})
assert length(queue) == 0
%{"new_first?" => new_first?} = QueueBot.Manager.call({channel, {:pop, 100, "llama"}})
assert new_first? == false
end
test "with any items in the queue returns new_first? true", %{channel: channel} do
items = ["Alan", "Chris", "Toulson"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:display, 100, "llama"}})
assert length(queue) == 3
%{"queue" => new_queue, "new_first?" => new_first?} = QueueBot.Manager.call({channel, {:pop, 100, "llama"}})
assert length(new_queue) == 2
assert new_first? == true
end
end
describe "#push" do
test "adds an item", %{channel: channel} do
item = "alan"
%{"queue" => queue} = QueueBot.Manager.call({channel, {:display, 100, "llama"}})
assert length(queue) == 0
add_item(channel, item)
%{"queue" => queue} = QueueBot.Manager.call({channel, {:display, 100, "llama"}})
assert length(queue) == 1
assert get_item_texts(queue) == [item]
end
test "with no items in the queue returns new_first? true", %{channel: channel} do
%{"queue" => queue} = QueueBot.Manager.call({channel, {:display, 100, "llama"}})
assert length(queue) == 0
%{"new_first?" => new_first?} = add_item(channel, "write a song")
assert new_first? == true
end
test "with one item in the queue returns new_first? true", %{channel: channel} do
%{"queue" => queue} = QueueBot.Manager.call({channel, {:display, 100, "llama"}})
assert length(queue) == 0
%{"new_first?" => new_first?} = add_item(channel, "write a song")
assert new_first? == true
%{"new_first?" => new_first?} = add_item(channel, "write another song")
assert new_first? == true
end
test "with items in the queue returns new_first? false", %{channel: channel} do
%{"queue" => queue} = QueueBot.Manager.call({channel, {:display, 100, "llama"}})
assert length(queue) == 0
items = ["this", "that", "the other"]
Enum.each(items, &(add_item(channel, &1)))
%{"new_first?" => new_first?} = add_item(channel, "do another task")
assert new_first? == false
end
end
describe "#display" do
test "returns the current queue", %{channel: channel} do
items = ["fruit", "vegetables", "circus peanuts"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:display, 100, "llama"}})
assert length(queue) == length(items)
item_texts = get_item_texts(queue)
assert Enum.all?(Enum.zip(items, item_texts), fn {item, queue_item} -> item == queue_item end)
end
test "returns new_first? false", %{channel: channel} do
items = ["zip", "zap", "zoom"]
Enum.each(items, &(add_item(channel, &1)))
%{"new_first?" => new_first?} = QueueBot.Manager.call({channel, {:display, 100, "llama"}})
assert new_first? == false
end
end
describe "#broadcast" do
test "returns the current queue", %{channel: channel} do
items = ["lemons", "limes", "limons"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:broadcast, 100, "llama"}})
assert length(queue) == length(items)
item_texts = get_item_texts(queue)
assert Enum.all?(Enum.zip(items, item_texts), fn {item, queue_item} -> item == queue_item end)
end
test "returns new_first? false", %{channel: channel} do
items = ["coke", "pepsi", "shasta"]
Enum.each(items, &(add_item(channel, &1)))
%{"new_first?" => new_first?} = QueueBot.Manager.call({channel, {:broadcast, 100, "llama"}})
assert new_first? == false
end
end
describe "#edit" do
test "returns the current queue, each with an id and item", %{channel: channel} do
items = ["medicine", "broth"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
assert length(queue) == length(items)
assert Enum.all?(Enum.zip(items, queue), fn {item, %{"id" => _, "item" => queue_item}} -> item == queue_item end)
end
test "returns new_first? false", %{channel: channel} do
items = ["totally", "radical", "english", "words"]
Enum.each(items, &(add_item(channel, &1)))
%{"new_first?" => new_first?} = QueueBot.Manager.call({channel, {:edit}})
assert new_first? == false
end
end
describe "#remove" do
test "removes an item from the queue", %{channel: channel} do
items = ["do", "re", "mi", "fa"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
assert length(queue) == length(items)
[%{"id" => id} | _] = queue
QueueBot.Manager.call({channel, {:remove, id, "llama"}})
%{"queue" => queue} = QueueBot.Manager.call({channel, {:display, 100, "llama"}})
assert length(queue) == length(items) - 1
end
test "removes the second item correctly in a two item queue", %{channel: channel} do
items = ["pi", "co"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
assert length(queue) == length(items)
[%{"id" => id1, "item" => item1}, %{"id" => id2}] = queue
QueueBot.Manager.call({channel, {:remove, id2, "llama"}})
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
[%{"id" => new_id1, "item" => new_item1}] = queue
assert length(queue) == length(items) - 1
assert new_id1 == id1
assert new_id1 != id2
assert new_item1 == item1
end
test "with multiple items, removing the first, returns new_first? true", %{channel: channel} do
items = ["so", "do", "la", "fa"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
assert length(queue) == length(items)
[%{"id" => id} | _] = queue
%{"new_first?" => new_first?} = QueueBot.Manager.call({channel, {:remove, id, "llama"}})
assert new_first? == true
end
test "with multiple items, removing the second, returns new_first? true", %{channel: channel} do
items = ["la", "mi", "fa", "do"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
assert length(queue) == length(items)
%{"id" => id} = Enum.at(queue, 1)
%{"new_first?" => new_first?} = QueueBot.Manager.call({channel, {:remove, id, "llama"}})
assert new_first? == true
end
test "with many items, removing any but the first two, returns new_first? false", %{channel: channel} do
items = ["do", "re", "do"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
assert length(queue) == length(items)
%{"id" => id} = List.last(queue)
%{"new_first?" => new_first?} = QueueBot.Manager.call({channel, {:remove, id, "llama"}})
assert new_first? == false
end
end
describe "#up" do
test "moves an item up in the queue", %{channel: channel} do
items = ["sam", "sausage"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
assert length(queue) == length(items)
[%{"id" => first_id}, %{"id" => last_id}] = queue
assert first_id != last_id
QueueBot.Manager.call({channel, {:up, last_id, "llama"}})
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
assert length(queue) == length(items)
[%{"id" => new_first_id}, %{"id" => new_last_id}] = queue
assert new_first_id == last_id
assert new_last_id == first_id
end
test "on the first item returns the same queue and new_first? false", %{channel: channel} do
items = ["simple", "simon"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
[%{"id" => id} | _] = queue
%{"queue" => new_queue, "new_first?" => new_first?} = QueueBot.Manager.call({channel, {:up, id, "llama"}})
assert queue == new_queue
assert new_first? == false
end
test "on the second, returns new_first? true", %{channel: channel} do
items = ["so", "do", "la", "fa"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
%{"id" => id} = Enum.at(queue, 1)
%{"queue" => new_queue, "new_first?" => new_first?} = QueueBot.Manager.call({channel, {:up, id, "llama"}})
assert queue != new_queue
assert equal_contents(queue, new_queue)
assert new_first? == true
end
test "on the third, returns new_first? true", %{channel: channel} do
items = ["do", "re", "do"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
%{"id" => id} = Enum.at(queue, 2)
%{"queue" => new_queue, "new_first?" => new_first?} = QueueBot.Manager.call({channel, {:up, id, "llama"}})
assert queue != new_queue
assert equal_contents(queue, new_queue)
assert new_first? == true
end
test "on the fourth, returns new_first? false", %{channel: channel} do
items = ["mi", "do", "re", "fa"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
%{"id" => id} = Enum.at(queue, 3)
%{"queue" => new_queue, "new_first?" => new_first?} = QueueBot.Manager.call({channel, {:up, id, "llama"}})
assert queue != new_queue
assert equal_contents(queue, new_queue)
assert new_first? == false
end
end
describe "#move_to_top" do
test "moves an item to the top of the queue", %{channel: channel} do
items = ["simmy", "swanny", "samsonite"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
assert length(queue) == length(items)
[%{"id" => first_id}, %{"id" => middle_id}, %{"id" => last_id}] = queue
assert first_id != last_id
QueueBot.Manager.call({channel, {:move_to_top, last_id, "llama"}})
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
assert length(queue) == length(items)
[%{"id" => new_first_id}, %{"id" => new_middle_id}, %{"id" => new_last_id}] = queue
assert new_first_id == last_id
assert new_middle_id == first_id
assert new_last_id == middle_id
end
test "on the first item returns the same queue and new_first? false", %{channel: channel} do
items = ["simple", "simon", "pieman"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
[%{"id" => id} | _] = queue
%{"queue" => new_queue, "new_first?" => new_first?} = QueueBot.Manager.call({channel, {:move_to_top, id, "llama"}})
assert queue == new_queue
assert new_first? == false
end
test "on any other, returns new_first? true", %{channel: channel} do
items = ["p", "q", "m", "n"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
%{"id" => id} = Enum.at(queue, 2)
%{"queue" => new_queue, "new_first?" => new_first?} = QueueBot.Manager.call({channel, {:move_to_top, id, "llama"}})
assert queue != new_queue
assert equal_contents(queue, new_queue)
assert new_first? == true
end
end
describe "#down" do
test "moves an item down in the queue", %{channel: channel} do
items = ["sam", "sausage"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
assert length(queue) == length(items)
[%{"id" => first_id}, %{"id" => last_id}] = queue
assert first_id != last_id
QueueBot.Manager.call({channel, {:down, first_id, "llama"}})
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
assert length(queue) == length(items)
[%{"id" => new_first_id}, %{"id" => new_last_id}] = queue
assert new_first_id == last_id
assert new_last_id == first_id
end
test "on the last item returns the same queue and new_first? false", %{channel: channel} do
items = ["m", "o"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
%{"id" => id} = List.last(queue)
%{"queue" => new_queue, "new_first?" => new_first?} = QueueBot.Manager.call({channel, {:down, id, "llama"}})
assert queue == new_queue
assert new_first? == false
end
test "on the first, returns new_first? true", %{channel: channel} do
items = ["x", "y", "a", "b"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
[%{"id" => id} | _] = queue
%{"queue" => new_queue, "new_first?" => new_first?} = QueueBot.Manager.call({channel, {:down, id, "llama"}})
assert queue != new_queue
assert equal_contents(queue, new_queue)
assert new_first? == true
end
test "on the second, returns new_first? true", %{channel: channel} do
items = ["o", "p", "q", "r"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
%{"id" => id} = Enum.at(queue, 1)
%{"queue" => new_queue, "new_first?" => new_first?} = QueueBot.Manager.call({channel, {:down, id, "llama"}})
assert queue != new_queue
assert equal_contents(queue, new_queue)
assert new_first? == true
end
test "on the third, returns new_first? false", %{channel: channel} do
items = ["so", "do", "la", "fa"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
%{"id" => id} = Enum.at(queue, 2)
%{"queue" => new_queue, "new_first?" => new_first?} = QueueBot.Manager.call({channel, {:down, id, "llama"}})
assert queue != new_queue
assert equal_contents(queue, new_queue)
assert new_first? == false
end
end
describe "#add_review" do
test "adds review to item in queue", %{channel: channel} do
items = ["so", "do", "la", "fa"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
assert length(queue) == length(items)
[%{"id" => first_id}| _] = queue
QueueBot.Manager.call({channel, {:add_review, first_id, "llama"}})
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
[%{"reviewers" => reviewers}| _] = queue
assert reviewers == ["llama"]
end
test "adds only one review to item in queue per username", %{channel: channel} do
items = ["so", "do", "la", "fa"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
assert length(queue) == length(items)
[_, %{"id" => second_id}| _] = queue
QueueBot.Manager.call({channel, {:add_review, second_id, "llama"}})
QueueBot.Manager.call({channel, {:add_review, second_id, "llama"}})
QueueBot.Manager.call({channel, {:add_review, second_id, "alpaca"}})
QueueBot.Manager.call({channel, {:add_review, second_id, "llama"}})
QueueBot.Manager.call({channel, {:add_review, second_id, "alpaca"}})
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
[_, %{"reviewers" => reviewers}| _] = queue
assert reviewers == ["llama", "alpaca"]
end
end
describe "#remove_review" do
test "removes single review in queue", %{channel: channel} do
items = ["so", "do", "la", "fa"]
Enum.each(items, &(add_item(channel, &1)))
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
assert length(queue) == length(items)
[%{"id" => first_id}, %{"id" => second_id}| _] = queue
QueueBot.Manager.call({channel, {:add_review, first_id, "llama"}})
QueueBot.Manager.call({channel, {:add_review, second_id, "llama"}})
%{"queue" => queue} = QueueBot.Manager.call({channel, {:edit}})
[%{"reviewers" => first_reviewers}, %{"reviewers" => second_reviewers}| _] = queue
assert first_reviewers == ["llama"]
assert second_reviewers == ["llama"]
QueueBot.Manager.call({channel, {:remove_review, first_id, "llama"}})
%{"queue" => updated_queue} = QueueBot.Manager.call({channel, {:edit}})
[%{"reviewers" => updated_first_reviewers}, %{"reviewers" => updated_second_reviewers}| _] = updated_queue
assert updated_first_reviewers == []
assert updated_second_reviewers == ["llama"]
end
end
defp add_item(channel, item) do
QueueBot.Manager.call({channel, {:push, make_ref(), item}})
end
def get_item_texts(queue) do
Enum.map(queue, &(&1["item"]))
end
defp equal_contents(queue1, queue2) do
order_contents(queue1) == order_contents(queue2)
end
defp order_contents(queue) do
Enum.sort_by(queue, fn %{"id" => id} -> id end)
end
end
| 43.834928 | 121 | 0.594226 |
f71fb304453806b24d9ec2993c364189af58b3f7 | 2,400 | ex | Elixir | pragprog/sab.ex | jnj16180340/elixir-notes | db0ec5a1725491848572272ade4a81891610002d | [
"Unlicense"
] | null | null | null | pragprog/sab.ex | jnj16180340/elixir-notes | db0ec5a1725491848572272ade4a81891610002d | [
"Unlicense"
] | null | null | null | pragprog/sab.ex | jnj16180340/elixir-notes | db0ec5a1725491848572272ade4a81891610002d | [
"Unlicense"
] | null | null | null | defmodule SAB do
@exercise "StringsAndBinaries-1"
# The (? ) to get char code syntax is really bad,
# is there another way to get char code?
# Sigils example: Note that
# SAB.printable?(~c'123\n') => false
# SAB.printable?(~C'123\n') => true
def printable?(lin) do
List.foldl(lin, true, fn(val, acc) -> acc and val<=(?~) and val>=(? ) end )
end
@exercise "StringsAndBinaries-2"
# - What's the difference between string and binary? (there's no Binary mnodule!)
# - Cleaner way of implementing polymorphism besides guards for each param?
def anagram?(lin, lintoo) when is_binary(lin), do: anagram?(String.to_charlist(lin), lintoo)
def anagram?(lin, lintoo) when is_binary(lintoo), do: anagram?(lin, String.to_charlist(lintoo))
def anagram?(lin, lintoo) do
# should also catch string case and convert to char list
# string doesn't implement enumerable
Enum.sort(lin) == Enum.sort(lintoo)
end
@exercise "StringsAndBinaries-5"
# in: list of "stuff"
# out: print centered column width=longest string
# it should work with multibyte unicode
# total padding is maxlength - length
# pad left + r half of it
defp padit(s, total_length) do
# how do you make a closure?
# just return an anonymous function i think
sl = String.length(s)
s
|> String.pad_leading(sl+div(total_length-sl,2))
|> String.pad_trailing(total_length)
end
def centerr(lodqs) do
ml = maxlen(lodqs)
Enum.map(lodqs, fn s -> padit(s, ml) end)
end
def center(lodqs), do: centerr(lodqs) |> Enum.map(&IO.puts/1)
# This should be guarded or patternmatched for [string] only...
# this syntax fucks up Kate's Elixir highlighting. It's the /1 that does it, jesus wept
defp maxlen(l), do: l |> Enum.map(&String.length/1) |> Enum.max # / the slash undoes the fucked highlighting
@exercise "StringsAndBinaries-6"
# There's probably a way to do it with binary pattern matching
# but I can't figure it out yet
def capitalize_sentences(sentence) do
sentence
|> String.split(". ", trim: true) # trim doesn't matter; left in as example of keyword option
|> Enum.map(&String.capitalize/1) #/
|> Enum.reduce("", fn(x, acc) -> "#{acc}#{x}. " end)
end
@exercise "StringsAndBinaries-7"
# Look up the answer, this will be a better description of binary pattern matching
# than the actual book chapter.
end
| 37.5 | 111 | 0.680833 |
f71fee667379296e6f37f9eca02bf1e0de07fff3 | 2,518 | exs | Elixir | test/scanner_test.exs | myhobnob/exmoji | 08ddcf90ff51942f70674be79f36195d56bf7f11 | [
"MIT"
] | null | null | null | test/scanner_test.exs | myhobnob/exmoji | 08ddcf90ff51942f70674be79f36195d56bf7f11 | [
"MIT"
] | 1 | 2019-03-08T18:55:47.000Z | 2019-03-08T19:24:39.000Z | test/scanner_test.exs | myhobnob/exmoji | 08ddcf90ff51942f70674be79f36195d56bf7f11 | [
"MIT"
] | null | null | null | defmodule ScannerTest do
use ExUnit.Case, async: true
alias Exmoji.Scanner
@case_exact "🚀"
@case_multi "\u{0023}\u{FE0F}\u{20E3}"
@case_variant "flying on my 🚀 to visit the 👾 people."
@case_multivariant "first a \u{0023}\u{FE0F}\u{20E3} then a 🚀"
@case_duplicates "flying my 🚀 to visit the 👾 people who have their own 🚀 omg!"
@case_none "i like turtles"
#
# #scan
#
test ".scan - should find the proper EmojiChar from a single string char" do
results = Scanner.scan(@case_exact)
assert Enum.count(results) == 1
assert Enum.at(results,0).__struct__ == Exmoji.EmojiChar
assert Enum.at(results,0).name == "ROCKET"
end
test ".scan - should find the proper EmojiChar from a variant encoded char" do
results = Scanner.scan(@case_multi)
assert Enum.count(results) == 1
assert Enum.at(results,0).name == "HASH KEY"
end
test ".scan - should match multiple chars from within a string" do
results = Scanner.scan(@case_variant)
assert Enum.count(results) == 2
end
test ".scan - should return multiple matches in proper order" do
results = Scanner.scan(@case_variant)
assert Enum.at(results,0).name == "ROCKET"
assert Enum.at(results,1).name == "ALIEN MONSTER"
end
test ".scan - should return multiple matches in proper order for variants" do
results = Scanner.scan(@case_multivariant)
assert Enum.count(results) == 2
assert Enum.at(results,0).name == "HASH KEY"
assert Enum.at(results,1).name == "ROCKET"
end
test ".scan - should return multiple matches including duplicates" do
results = Scanner.scan(@case_duplicates)
assert Enum.count(results) == 3
assert Enum.at(results,0).name == "ROCKET"
assert Enum.at(results,1).name == "ALIEN MONSTER"
assert Enum.at(results,2).name == "ROCKET"
end
test ".scan - returns and empty list if nothing is found" do
assert Scanner.scan(@case_none) == []
end
test ".strip" do
assert Scanner.strip_emoji(@case_exact) == ""
assert Scanner.strip_emoji(@case_multi) == ""
assert Scanner.strip_emoji(@case_variant) == "flying on my to visit the people."
assert Scanner.strip_emoji(@case_multivariant) == "first a then a "
assert Scanner.strip_emoji(@case_duplicates) == "flying my to visit the people who have their own omg!"
assert Scanner.strip_emoji(@case_none) == "i like turtles"
foreign1 = "طويلبون فيلادلفيا"
assert Scanner.strip_emoji(foreign1) == foreign1
end
end
| 35.464789 | 110 | 0.677919 |
f720307c27c02bc0f4bb3a2b7d8268e932d120a6 | 48,377 | exs | Elixir | lib/elixir/test/elixir/typespec_test.exs | joshnuss/elixir | 10ef56fdfa6f1634c0b167a6ddfda44b91bd9bd4 | [
"Apache-2.0"
] | null | null | null | lib/elixir/test/elixir/typespec_test.exs | joshnuss/elixir | 10ef56fdfa6f1634c0b167a6ddfda44b91bd9bd4 | [
"Apache-2.0"
] | null | null | null | lib/elixir/test/elixir/typespec_test.exs | joshnuss/elixir | 10ef56fdfa6f1634c0b167a6ddfda44b91bd9bd4 | [
"Apache-2.0"
] | null | null | null | Code.require_file("test_helper.exs", __DIR__)
# Holds tests for both Kernel.Typespec and Code.Typespec
defmodule TypespecTest do
use ExUnit.Case, async: true
alias TypespecTest.TypespecSample
defstruct [:hello]
defmacrop test_module(do: block) do
quote do
{:module, _, bytecode, _} =
defmodule TypespecSample do
unquote(block)
end
:code.delete(TypespecSample)
:code.purge(TypespecSample)
bytecode
end
end
defp types(bytecode) do
bytecode
|> Code.Typespec.fetch_types()
|> elem(1)
|> Enum.sort()
end
@skip_specs [__info__: 1]
defp specs(bytecode) do
bytecode
|> Code.Typespec.fetch_specs()
|> elem(1)
|> Enum.reject(fn {sign, _} -> sign in @skip_specs end)
|> Enum.sort()
end
defp callbacks(bytecode) do
bytecode
|> Code.Typespec.fetch_callbacks()
|> elem(1)
|> Enum.sort()
end
describe "Kernel.Typespec errors" do
test "invalid type specification" do
assert_raise CompileError, ~r"invalid type specification: my_type = 1", fn ->
test_module do
@type my_type = 1
end
end
end
test "unexpected expression in typespec" do
assert_raise CompileError, ~r"unexpected expression in typespec: \"foobar\"", fn ->
test_module do
@type my_type :: "foobar"
end
end
end
test "invalid function specification" do
assert_raise CompileError, ~r"invalid type specification: \"not a spec\"", fn ->
test_module do
@spec "not a spec"
end
end
assert_raise CompileError, ~r"invalid type specification: 1 :: 2", fn ->
test_module do
@spec 1 :: 2
end
end
end
test "undefined type" do
assert_raise CompileError, ~r"type foo/0 undefined", fn ->
test_module do
@type omg :: foo
end
end
assert_raise CompileError, ~r"type foo/2 undefined", fn ->
test_module do
@type omg :: foo(atom, integer)
end
end
assert_raise CompileError, ~r"type bar/0 undefined", fn ->
test_module do
@spec foo(bar, integer) :: {atom, integer}
def foo(var1, var2), do: {var1, var2}
end
end
assert_raise CompileError, ~r"type foo/0 undefined", fn ->
test_module do
@type omg :: __MODULE__.foo()
end
end
end
test "redefined type" do
assert_raise CompileError, ~r"type foo/0 is already defined", fn ->
test_module do
@type foo :: atom
@type foo :: integer
end
end
assert_raise CompileError, ~r"type foo/2 is already defined", fn ->
test_module do
@type foo :: atom
@type foo(var1, var2) :: {var1, var2}
@type foo(x, y) :: {x, y}
end
end
assert_raise CompileError, ~r"type foo/0 is already defined", fn ->
test_module do
@type foo :: atom
@typep foo :: integer
end
end
end
test "type variable unused (singleton type variable)" do
assert_raise CompileError, ~r"type variable x is unused", fn ->
test_module do
@type foo(x) :: integer
end
end
end
test "@type with a variable starting with underscore" do
test_module do
assert @type(foo(_hello) :: integer) == :ok
end
end
test "type variable _ should be invalid" do
assert_raise CompileError, ~r"type variable '_' is invalid", fn ->
test_module do
@type foo(_) :: integer
end
end
assert_raise CompileError, ~r"type variable '_' is invalid", fn ->
test_module do
@type foo(_, _) :: integer
end
end
end
test "spec for undefined function" do
assert_raise CompileError, ~r"spec for undefined function omg/0", fn ->
test_module do
@spec omg :: atom
end
end
end
test "spec variable unused (singleton type variable)" do
assert_raise CompileError, ~r"type variable x is unused", fn ->
test_module do
@spec foo(x, integer) :: integer when x: var
def foo(x, y), do: x + y
end
end
end
test "ill defined optional callback" do
assert_raise CompileError, ~r"invalid optional callback :foo", fn ->
test_module do
@optional_callbacks :foo
end
end
end
test "unknown optional callback" do
assert_raise CompileError, ~r"unknown callback foo/1 given as optional callback", fn ->
test_module do
@optional_callbacks foo: 1
end
end
end
test "repeated optional callback" do
message = ~r"foo/1 has been specified as optional callback more than once"
assert_raise CompileError, message, fn ->
test_module do
@callback foo(:ok) :: :ok
@optional_callbacks foo: 1, foo: 1
end
end
end
test "behaviour_info/1 explicitly defined alongside @callback/@macrocallback" do
message = ~r"cannot define @callback attribute for foo/1 when behaviour_info/1"
assert_raise CompileError, message, fn ->
test_module do
@callback foo(:ok) :: :ok
def behaviour_info(_), do: []
end
end
message = ~r"cannot define @macrocallback attribute for foo/1 when behaviour_info/1"
assert_raise CompileError, message, fn ->
test_module do
@macrocallback foo(:ok) :: :ok
def behaviour_info(_), do: []
end
end
end
test "default is not supported" do
assert_raise ArgumentError, fn ->
test_module do
@callback hello(num \\ 0 :: integer) :: integer
end
end
assert_raise ArgumentError, fn ->
test_module do
@callback hello(num :: integer \\ 0) :: integer
end
end
assert_raise ArgumentError, fn ->
test_module do
@macrocallback hello(num \\ 0 :: integer) :: Macro.t()
end
end
assert_raise ArgumentError, fn ->
test_module do
@macrocallback hello(num :: integer \\ 0) :: Macro.t()
end
end
assert_raise ArgumentError, fn ->
test_module do
@spec hello(num \\ 0 :: integer) :: integer
end
end
assert_raise ArgumentError, fn ->
test_module do
@spec hello(num :: integer \\ 0) :: integer
end
end
end
test "@spec shows readable error message when return type is missing" do
message = ~r"type specification missing return type: my_fun\(integer\)"
assert_raise CompileError, message, fn ->
test_module do
@spec my_fun(integer)
end
end
end
end
describe "Kernel.Typespec definitions" do
test "typespec declarations return :ok" do
test_module do
def foo(), do: nil
assert @type(foo :: any()) == :ok
assert @typep(foop :: any()) == :ok
assert @spec(foo() :: nil) == :ok
assert @opaque(my_type :: atom) == :ok
assert @callback(foo(foop) :: integer) == :ok
assert @macrocallback(foo(integer) :: integer) == :ok
end
end
test "@type with a single type" do
bytecode =
test_module do
@type my_type :: term
end
assert [type: {:my_type, {:type, _, :term, []}, []}] = types(bytecode)
end
test "@type with an atom" do
bytecode =
test_module do
@type my_type :: :foo
end
assert [type: {:my_type, {:atom, _, :foo}, []}] = types(bytecode)
end
test "@type with an atom alias" do
bytecode =
test_module do
@type my_type :: Atom
end
assert [type: {:my_type, {:atom, _, Atom}, []}] = types(bytecode)
end
test "@type with an integer" do
bytecode =
test_module do
@type my_type :: 10
end
assert [type: {:my_type, {:integer, _, 10}, []}] = types(bytecode)
end
test "@type with a negative integer" do
bytecode =
test_module do
@type my_type :: -10
end
assert [type: {:my_type, {:op, _, :-, {:integer, _, 10}}, []}] = types(bytecode)
end
test "@type with a remote type" do
bytecode =
test_module do
@type my_type :: Remote.Some.type()
@type my_type_arg :: Remote.type(integer)
end
assert [type: my_type, type: my_type_arg] = types(bytecode)
assert {:my_type, type, []} = my_type
assert {:remote_type, _, [{:atom, _, Remote.Some}, {:atom, _, :type}, []]} = type
assert {:my_type_arg, type, []} = my_type_arg
assert {:remote_type, _, args} = type
assert [{:atom, _, Remote}, {:atom, _, :type}, [{:type, _, :integer, []}]] = args
end
test "@type with a binary" do
bytecode =
test_module do
@type my_type :: binary
end
assert [type: {:my_type, {:type, _, :binary, []}, []}] = types(bytecode)
end
test "@type with an empty binary" do
bytecode =
test_module do
@type my_type :: <<>>
end
assert [type: {:my_type, {:type, _, :binary, [{:integer, _, 0}, {:integer, _, 0}]}, []}] =
types(bytecode)
end
test "@type with a binary with a base size" do
bytecode =
test_module do
@type my_type :: <<_::3>>
end
assert [type: {:my_type, {:type, _, :binary, [{:integer, _, 3}, {:integer, _, 0}]}, []}] =
types(bytecode)
end
test "@type with a binary with a unit size" do
bytecode =
test_module do
@type my_type :: <<_::_*8>>
end
assert [type: {:my_type, {:type, _, :binary, [{:integer, _, 0}, {:integer, _, 8}]}, []}] =
types(bytecode)
end
test "@type with a binary with a size and unit size" do
bytecode =
test_module do
@type my_type :: <<_::3, _::_*8>>
end
assert [type: {:my_type, {:type, _, :binary, [{:integer, _, 3}, {:integer, _, 8}]}, []}] =
types(bytecode)
end
test "@type with invalid binary spec" do
assert_raise CompileError, ~r"invalid binary specification", fn ->
test_module do
@type my_type :: <<_::3*8>>
end
end
assert_raise CompileError, ~r"invalid binary specification", fn ->
test_module do
@type my_type :: <<_::atom>>
end
end
assert_raise CompileError, ~r"invalid binary specification", fn ->
test_module do
@type my_type :: <<_::(-4)>>
end
end
assert_raise CompileError, ~r"invalid binary specification", fn ->
test_module do
@type my_type :: <<_::3, _::_*atom>>
end
end
assert_raise CompileError, ~r"invalid binary specification", fn ->
test_module do
@type my_type :: <<_::3, _::_*(-8)>>
end
end
end
test "@type with a range op" do
bytecode =
test_module do
@type range1 :: 1..10
@type range2 :: -1..1
end
assert [
{:type, {:range1, {:type, _, :range, range1_args}, []}},
{:type, {:range2, {:type, _, :range, range2_args}, []}}
] = types(bytecode)
assert [{:integer, _, 1}, {:integer, _, 10}] = range1_args
assert [{:op, _, :-, {:integer, _, 1}}, {:integer, _, 1}] = range2_args
end
test "@type with invalid range" do
assert_raise CompileError, ~r"invalid range specification", fn ->
test_module do
@type my_type :: atom..10
end
end
end
test "@type with a keyword map" do
bytecode =
test_module do
@type my_type :: %{hello: :world}
end
assert [type: {:my_type, type, []}] = types(bytecode)
assert {:type, _, :map, [arg]} = type
assert {:type, _, :map_field_exact, [{:atom, _, :hello}, {:atom, _, :world}]} = arg
end
test "@type with a map" do
bytecode =
test_module do
@type my_type :: %{required(:a) => :b, optional(:c) => :d}
end
assert [type: {:my_type, type, []}] = types(bytecode)
assert {:type, _, :map, [arg1, arg2]} = type
assert {:type, _, :map_field_exact, [{:atom, _, :a}, {:atom, _, :b}]} = arg1
assert {:type, _, :map_field_assoc, [{:atom, _, :c}, {:atom, _, :d}]} = arg2
end
test "@type with a struct" do
bytecode =
test_module do
defstruct hello: nil, other: nil
@type my_type :: %TypespecSample{hello: :world}
end
assert [type: {:my_type, type, []}] = types(bytecode)
assert {:type, _, :map, [struct, arg1, arg2]} = type
assert {:type, _, :map_field_exact, struct_args} = struct
assert [{:atom, _, :__struct__}, {:atom, _, TypespecSample}] = struct_args
assert {:type, _, :map_field_exact, [{:atom, _, :hello}, {:atom, _, :world}]} = arg1
assert {:type, _, :map_field_exact, [{:atom, _, :other}, {:type, _, :term, []}]} = arg2
end
@fields Enum.map(10..42, &{:"f#{&1}", :ok})
test "@type with a large struct" do
bytecode =
test_module do
defstruct unquote(@fields)
@type my_type :: %TypespecSample{unquote_splicing(@fields)}
end
assert [type: {:my_type, type, []}] = types(bytecode)
assert {:type, _, :map, [struct, arg1, arg2 | _]} = type
assert {:type, _, :map_field_exact, struct_args} = struct
assert [{:atom, _, :__struct__}, {:atom, _, TypespecSample}] = struct_args
assert {:type, _, :map_field_exact, [{:atom, _, :f10}, {:atom, _, :ok}]} = arg1
assert {:type, _, :map_field_exact, [{:atom, _, :f11}, {:atom, _, :ok}]} = arg2
end
test "@type with struct does not @enforce_keys" do
bytecode =
test_module do
@enforce_keys [:other]
defstruct hello: nil, other: nil
@type my_type :: %TypespecSample{hello: :world}
end
assert [type: {:my_type, _type, []}] = types(bytecode)
end
test "@type with undefined struct" do
assert_raise CompileError, ~r"ThisModuleDoesNotExist.__struct__/0 is undefined", fn ->
test_module do
@type my_type :: %ThisModuleDoesNotExist{}
end
end
assert_raise CompileError, ~r"cannot access struct TypespecTest.TypespecSample", fn ->
test_module do
@type my_type :: %TypespecSample{}
end
end
end
test "@type with a struct with undefined field" do
assert_raise CompileError, ~r"undefined field :no_field on struct TypespecSample", fn ->
test_module do
defstruct [:hello, :eric]
@type my_type :: %TypespecSample{no_field: :world}
end
end
end
test "@type when overriding Elixir built-in" do
assert_raise CompileError, ~r"type struct/0 is a built-in type", fn ->
test_module do
@type struct :: :oops
end
end
end
test "@type when overriding Erlang built-in" do
assert_raise CompileError, ~r"type list/0 is a built-in type", fn ->
test_module do
@type list :: :oops
end
end
end
test "@type with public record" do
bytecode =
test_module do
require Record
Record.defrecord(:timestamp, date: 1, time: 2)
@type my_type :: record(:timestamp, time: :foo)
end
assert [type: {:my_type, type, []}] = types(bytecode)
assert {:type, _, :tuple, [timestamp, term, foo]} = type
assert {:atom, 0, :timestamp} = timestamp
assert {:ann_type, 0, [{:var, 0, :date}, {:type, 0, :term, []}]} = term
assert {:ann_type, 0, [{:var, 0, :time}, {:atom, 0, :foo}]} = foo
end
test "@type with private record" do
bytecode =
test_module do
require Record
Record.defrecordp(:timestamp, date: 1, time: 2)
@type my_type :: record(:timestamp, time: :foo)
end
assert [type: {:my_type, type, []}] = types(bytecode)
assert {:type, _, :tuple, args} = type
assert [
{:atom, 0, :timestamp},
{:ann_type, 0, [{:var, 0, :date}, {:type, 0, :term, []}]},
{:ann_type, 0, [{:var, 0, :time}, {:atom, 0, :foo}]}
] = args
end
test "@type with named record" do
bytecode =
test_module do
require Record
Record.defrecord(:timestamp, :my_timestamp, date: 1, time: 2)
@type my_type :: record(:timestamp, time: :foo)
end
assert [type: {:my_type, type, []}] = types(bytecode)
assert {:type, _, :tuple, [my_timestamp, term, _foo]} = type
assert {:atom, 0, :my_timestamp} = my_timestamp
assert {:ann_type, 0, [{:var, 0, :date}, {:type, 0, :term, []}]} = term
assert {:ann_type, 0, [{:var, 0, :time}, {:atom, 0, :foo}]}
end
test "@type with undefined record" do
assert_raise CompileError, ~r"unknown record :this_record_does_not_exist", fn ->
test_module do
@type my_type :: record(:this_record_does_not_exist, [])
end
end
end
test "@type with a record with undefined field" do
assert_raise CompileError, ~r"undefined field no_field on record :timestamp", fn ->
test_module do
require Record
Record.defrecord(:timestamp, date: 1, time: 2)
@type my_type :: record(:timestamp, no_field: :foo)
end
end
end
test "@type with a record which declares the name as the type `atom` rather than an atom literal" do
assert_raise CompileError, ~r"expected the record name to be an atom literal", fn ->
test_module do
@type my_type :: record(atom, field: :foo)
end
end
end
test "@type can be named record" do
bytecode =
test_module do
@type record :: binary
@spec foo?(record) :: boolean
def foo?(_), do: true
end
assert [type: {:record, {:type, _, :binary, []}, []}] = types(bytecode)
end
test "@type with an invalid map notation" do
assert_raise CompileError, ~r"invalid map specification", fn ->
test_module do
@type content :: %{atom | String.t() => term}
end
end
end
test "@type with list shortcuts" do
bytecode =
test_module do
@type my_type :: []
@type my_type1 :: [integer]
@type my_type2 :: [integer, ...]
end
assert [
type: {:my_type, {:type, _, nil, []}, []},
type: {:my_type1, {:type, _, :list, [{:type, _, :integer, []}]}, []},
type: {:my_type2, {:type, _, :nonempty_list, [{:type, _, :integer, []}]}, []}
] = types(bytecode)
end
test "@type with a fun" do
bytecode =
test_module do
@type my_type :: (... -> any)
end
assert [type: {:my_type, {:type, _, :fun, []}, []}] = types(bytecode)
end
test "@type with a fun with multiple arguments and return type" do
bytecode =
test_module do
@type my_type :: (integer, integer -> integer)
end
assert [type: {:my_type, type, []}] = types(bytecode)
assert {:type, _, :fun, [args, return_type]} = type
assert {:type, _, :product, [{:type, _, :integer, []}, {:type, _, :integer, []}]} = args
assert {:type, _, :integer, []} = return_type
end
test "@type with a fun with no arguments and return type" do
bytecode =
test_module do
@type my_type :: (() -> integer)
end
assert [type: {:my_type, type, []}] = types(bytecode)
assert {:type, _, :fun, [{:type, _, :product, []}, {:type, _, :integer, []}]} = type
end
test "@type with a fun with any arity and return type" do
bytecode =
test_module do
@type my_type :: (... -> integer)
end
assert [type: {:my_type, type, []}] = types(bytecode)
assert {:type, _, :fun, [{:type, _, :any}, {:type, _, :integer, []}]} = type
end
test "@type with a union" do
bytecode =
test_module do
@type my_type :: integer | charlist | atom
end
assert [type: {:my_type, type, []}] = types(bytecode)
assert {:type, _, :union, [integer, charlist, atom]} = type
assert {:type, _, :integer, []} = integer
assert {:remote_type, _, [{:atom, _, :elixir}, {:atom, _, :charlist}, []]} = charlist
assert {:type, _, :atom, []} = atom
end
test "@type with keywords" do
bytecode =
test_module do
@type my_type :: [first: integer, step: integer, last: integer]
end
assert [type: {:my_type, type, []}] = types(bytecode)
assert {:type, _, :list, [{:type, _, :union, union_types}]} = type
assert [
{:type, _, :tuple, [{:atom, _, :first}, {:type, _, :integer, []}]},
{:type, _, :tuple, [{:atom, _, :step}, {:type, _, :integer, []}]},
{:type, _, :tuple, [{:atom, _, :last}, {:type, _, :integer, []}]}
] = union_types
end
test "@type with parameters" do
bytecode =
test_module do
@type my_type(x) :: x
@type my_type1(x) :: list(x)
@type my_type2(x, y) :: {x, y}
end
assert [
type: {:my_type, {:var, _, :x}, [{:var, _, :x}]},
type: {:my_type1, {:type, _, :list, [{:var, _, :x}]}, [{:var, _, :x}]},
type: {:my_type2, my_type2, [{:var, _, :x}, {:var, _, :y}]}
] = types(bytecode)
assert {:type, _, :tuple, [{:var, _, :x}, {:var, _, :y}]} = my_type2
end
test "@type with annotations" do
bytecode =
test_module do
@type my_type :: named :: integer
@type my_type1 :: (a :: integer -> integer)
end
assert [type: {:my_type, my_type, []}, type: {:my_type1, my_type1, []}] = types(bytecode)
assert {:ann_type, _, [{:var, _, :named}, {:type, _, :integer, []}]} = my_type
assert {:type, _, :fun, [fun_args, fun_return]} = my_type1
assert {:type, _, :product, [{:ann_type, _, [a, {:type, _, :integer, []}]}]} = fun_args
assert {:var, _, :a} = a
assert {:type, _, :integer, []} = fun_return
end
test "@opaque(type)" do
bytecode =
test_module do
@opaque my_type(x) :: x
end
assert [opaque: {:my_type, {:var, _, :x}, [{:var, _, :x}]}] = types(bytecode)
end
test "@type + opaque" do
bytecode =
test_module do
@type my_type :: tuple
@opaque my_type1 :: {}
end
assert [opaque: {:my_type1, _, []}, type: {:my_type, _, []}] = types(bytecode)
end
test "@type unquote fragment" do
quoted =
quote unquote: false do
name = :my_type
type = :foo
@type unquote(name)() :: unquote(type)
end
bytecode =
test_module do
Module.eval_quoted(__MODULE__, quoted)
end
assert [type: {:my_type, {:atom, _, :foo}, []}] = types(bytecode)
end
test "@type with module attributes" do
bytecode =
test_module do
@keyword Keyword
@type kw :: @keyword.t
@type kw(value) :: @keyword.t(value)
end
assert [type: {:kw, kw, _}, type: {:kw, kw_with_value, [{:var, _, :value}]}] =
types(bytecode)
assert {:remote_type, _, [{:atom, _, Keyword}, {:atom, _, :t}, []]} = kw
assert {:remote_type, _, kw_with_value_args} = kw_with_value
assert [{:atom, _, Keyword}, {:atom, _, :t}, [{:var, _, :value}]] = kw_with_value_args
end
test "invalid remote @type with module attribute that does not evaluate to a module" do
assert_raise CompileError, ~r/\(@foo is "bar"\)/, fn ->
test_module do
@foo "bar"
@type t :: @foo.t
end
end
end
test "defines_type?" do
test_module do
@type my_type :: tuple
@type my_type(a) :: [a]
assert Kernel.Typespec.defines_type?(__MODULE__, {:my_type, 0})
assert Kernel.Typespec.defines_type?(__MODULE__, {:my_type, 1})
refute Kernel.Typespec.defines_type?(__MODULE__, {:my_type, 2})
end
end
test "spec_to_callback/2" do
bytecode =
test_module do
@spec foo() :: term()
def foo(), do: :ok
Kernel.Typespec.spec_to_callback(__MODULE__, {:foo, 0})
end
assert specs(bytecode) == callbacks(bytecode)
end
test "@spec(spec)" do
bytecode =
test_module do
def my_fun1(x), do: x
def my_fun2(), do: :ok
def my_fun3(x, y), do: {x, y}
def my_fun4(x), do: x
@spec my_fun1(integer) :: integer
@spec my_fun2() :: integer
@spec my_fun3(integer, integer) :: {integer, integer}
@spec my_fun4(x :: integer) :: integer
end
assert [my_fun1, my_fun2, my_fun3, my_fun4] = specs(bytecode)
assert {{:my_fun1, 1}, [{:type, _, :fun, args}]} = my_fun1
assert [{:type, _, :product, [{:type, _, :integer, []}]}, {:type, _, :integer, []}] = args
assert {{:my_fun2, 0}, [{:type, _, :fun, args}]} = my_fun2
assert [{:type, _, :product, []}, {:type, _, :integer, []}] = args
assert {{:my_fun3, 2}, [{:type, _, :fun, [arg1, arg2]}]} = my_fun3
assert {:type, _, :product, [{:type, _, :integer, []}, {:type, _, :integer, []}]} = arg1
assert {:type, _, :tuple, [{:type, _, :integer, []}, {:type, _, :integer, []}]} = arg2
assert {{:my_fun4, 1}, [{:type, _, :fun, args}]} = my_fun4
assert [x, {:type, _, :integer, []}] = args
assert {:type, _, :product, [{:ann_type, _, [{:var, _, :x}, {:type, _, :integer, []}]}]} = x
end
test "@spec(spec) with tuples and tuple vars" do
bytecode =
test_module do
def my_fun1(x), do: x
def my_fun2(x), do: x
@spec my_fun1(tuple) :: tuple
@spec my_fun2(tuple) :: tuple when tuple: {integer, integer}
end
assert [my_fun1, my_fun2] = specs(bytecode)
assert {{:my_fun1, 1}, [{:type, _, :fun, args}]} = my_fun1
assert [{:type, _, :product, [{:type, _, :tuple, :any}]}, {:type, _, :tuple, :any}] = args
assert {{:my_fun2, 1}, [{:type, _, :bounded_fun, args}]} = my_fun2
assert [type, _] = args
assert {:type, _, :fun, [{:type, _, :product, [{:var, _, :tuple}]}, {:var, _, :tuple}]} =
type
end
test "@spec(spec) with guards" do
bytecode =
test_module do
def my_fun1(x), do: x
@spec my_fun1(x) :: boolean when x: integer
def my_fun2(x), do: x
@spec my_fun2(x) :: x when x: var
def my_fun3(_x, y), do: y
@spec my_fun3(x, y) :: y when y: x, x: var
end
assert [my_fun1, my_fun2, my_fun3] = specs(bytecode)
assert {{:my_fun1, 1}, [{:type, _, :bounded_fun, args}]} = my_fun1
assert [{:type, _, :fun, [product, {:type, _, :boolean, []}]}, constraints] = args
assert {:type, _, :product, [{:var, _, :x}]} = product
assert [{:type, _, :constraint, subtype}] = constraints
assert [{:atom, _, :is_subtype}, [{:var, _, :x}, {:type, _, :integer, []}]] = subtype
assert {{:my_fun2, 1}, [{:type, _, :fun, args}]} = my_fun2
assert [{:type, _, :product, [{:var, _, :x}]}, {:var, _, :x}] = args
assert {{:my_fun3, 2}, [{:type, _, :bounded_fun, args}]} = my_fun3
assert [{:type, _, :fun, fun_type}, [{:type, _, :constraint, constraint_type}]] = args
assert [{:type, _, :product, [{:var, _, :x}, {:var, _, :y}]}, {:var, _, :y}] = fun_type
assert [{:atom, _, :is_subtype}, [{:var, _, :y}, {:var, _, :x}]] = constraint_type
end
test "@type, @opaque, and @typep as module attributes" do
defmodule TypeModuleAttributes do
@type type1 :: boolean
@opaque opaque1 :: boolean
@typep typep1 :: boolean
def type1, do: @type
def opaque1, do: @opaque
def typep1, do: @typep
@type type2 :: atom
@type type3 :: pid
@opaque opaque2 :: atom
@opaque opaque3 :: pid
@typep typep2 :: atom
def type2, do: @type
def opaque2, do: @opaque
def typep2, do: @typep
# Avoid unused warnings
@spec foo(typep1) :: typep2
def foo(_x), do: :ok
end
assert [
{:type, {:"::", _, [{:type1, _, _}, {:boolean, _, _}]}, {TypeModuleAttributes, _}}
] = TypeModuleAttributes.type1()
assert [
{:type, {:"::", _, [{:type3, _, _}, {:pid, _, _}]}, {TypeModuleAttributes, _}},
{:type, {:"::", _, [{:type2, _, _}, {:atom, _, _}]}, {TypeModuleAttributes, _}},
{:type, {:"::", _, [{:type1, _, _}, {:boolean, _, _}]}, {TypeModuleAttributes, _}}
] = TypeModuleAttributes.type2()
assert [
{:opaque, {:"::", _, [{:opaque1, _, _}, {:boolean, _, _}]},
{TypeModuleAttributes, _}}
] = TypeModuleAttributes.opaque1()
assert [
{:opaque, {:"::", _, [{:opaque3, _, _}, {:pid, _, _}]}, {TypeModuleAttributes, _}},
{:opaque, {:"::", _, [{:opaque2, _, _}, {:atom, _, _}]},
{TypeModuleAttributes, _}},
{:opaque, {:"::", _, [{:opaque1, _, _}, {:boolean, _, _}]},
{TypeModuleAttributes, _}}
] = TypeModuleAttributes.opaque2()
assert [
{:typep, {:"::", _, [{:typep1, _, _}, {:boolean, _, _}]},
{TypeModuleAttributes, _}}
] = TypeModuleAttributes.typep1()
assert [
{:typep, {:"::", _, [{:typep2, _, _}, {:atom, _, _}]}, {TypeModuleAttributes, _}},
{:typep, {:"::", _, [{:typep1, _, _}, {:boolean, _, _}]},
{TypeModuleAttributes, _}}
] = TypeModuleAttributes.typep2()
after
:code.delete(TypeModuleAttributes)
:code.purge(TypeModuleAttributes)
end
test "@spec, @callback, and @macrocallback as module attributes" do
defmodule SpecModuleAttributes do
@callback callback1 :: integer
@macrocallback macrocallback1 :: integer
@spec spec1 :: boolean
def spec1, do: @spec
@callback callback2 :: var when var: boolean
@macrocallback macrocallback2 :: var when var: boolean
@spec spec2 :: atom
def spec2, do: @spec
@spec spec3 :: pid
def spec3, do: :ok
def spec4, do: @spec
def callback, do: @callback
def macrocallback, do: @macrocallback
end
assert [
{:spec, {:"::", _, [{:spec1, _, _}, {:boolean, _, _}]}, {SpecModuleAttributes, _}}
] = SpecModuleAttributes.spec1()
assert [
{:spec, {:"::", _, [{:spec2, _, _}, {:atom, _, _}]}, {SpecModuleAttributes, _}},
{:spec, {:"::", _, [{:spec1, _, _}, {:boolean, _, _}]}, {SpecModuleAttributes, _}}
] = SpecModuleAttributes.spec2()
assert [
{:spec, {:"::", _, [{:spec3, _, _}, {:pid, _, _}]}, {SpecModuleAttributes, _}},
{:spec, {:"::", _, [{:spec2, _, _}, {:atom, _, _}]}, {SpecModuleAttributes, _}},
{:spec, {:"::", _, [{:spec1, _, _}, {:boolean, _, _}]}, {SpecModuleAttributes, _}}
] = SpecModuleAttributes.spec4()
assert [
{:callback,
{:when, _,
[{:"::", _, [{:callback2, _, _}, {:var, _, _}]}, [var: {:boolean, _, _}]]},
{SpecModuleAttributes, _}},
{:callback, {:"::", _, [{:callback1, _, _}, {:integer, _, _}]},
{SpecModuleAttributes, _}}
] = SpecModuleAttributes.callback()
assert [
{:macrocallback,
{:when, _,
[{:"::", _, [{:macrocallback2, _, _}, {:var, _, _}]}, [var: {:boolean, _, _}]]},
{SpecModuleAttributes, _}},
{:macrocallback, {:"::", _, [{:macrocallback1, _, _}, {:integer, _, _}]},
{SpecModuleAttributes, _}}
] = SpecModuleAttributes.macrocallback()
after
:code.delete(SpecModuleAttributes)
:code.purge(SpecModuleAttributes)
end
test "@callback(callback)" do
bytecode =
test_module do
@callback my_fun(integer) :: integer
@callback my_fun(list) :: list
@callback my_fun() :: integer
@callback my_fun(integer, integer) :: {integer, integer}
end
assert [my_fun_0, my_fun_1, my_fun_2] = callbacks(bytecode)
assert {{:my_fun, 0}, [{:type, _, :fun, args}]} = my_fun_0
assert [{:type, _, :product, []}, {:type, _, :integer, []}] = args
assert {{:my_fun, 1}, [clause1, clause2]} = my_fun_1
assert {:type, _, :fun, args1} = clause1
assert [{:type, _, :product, [{:type, _, :integer, []}]}, {:type, _, :integer, []}] = args1
assert {:type, _, :fun, args2} = clause2
assert [{:type, _, :product, [{:type, _, :list, []}]}, {:type, _, :list, []}] = args2
assert {{:my_fun, 2}, [{:type, _, :fun, [args_type, return_type]}]} = my_fun_2
assert {:type, _, :product, [{:type, _, :integer, []}, {:type, _, :integer, []}]} =
args_type
assert {:type, _, :tuple, [{:type, _, :integer, []}, {:type, _, :integer, []}]} =
return_type
end
test "@spec + @callback" do
bytecode =
test_module do
def my_fun(x), do: x
@spec my_fun(integer) :: integer
@spec my_fun(charlist) :: charlist
@callback cb(integer) :: integer
end
assert [{{:cb, 1}, [{:type, _, :fun, args}]}] = callbacks(bytecode)
assert [{:type, _, :product, [{:type, _, :integer, []}]}, {:type, _, :integer, []}] = args
assert [{{:my_fun, 1}, [integer_clause, charlist_clause]}] = specs(bytecode)
assert {:type, _, :fun, [{:type, _, :product, [arg]}, return]} = integer_clause
assert {:type, _, :integer, []} = arg
assert {:type, _, :integer, []} = return
assert {:type, _, :fun, [{:type, _, :product, [arg]}, return]} = charlist_clause
assert {:remote_type, _, [{:atom, _, :elixir}, {:atom, _, :charlist}, []]} = arg
assert {:remote_type, _, [{:atom, _, :elixir}, {:atom, _, :charlist}, []]} = return
end
test "block handling" do
bytecode =
test_module do
@spec foo((() -> [integer])) :: integer
def foo(_), do: 1
end
assert [{{:foo, 1}, [{:type, _, :fun, [args, return]}]}] = specs(bytecode)
assert {:type, _, :product, [{:type, _, :fun, fun_args}]} = args
assert [{:type, _, :product, []}, {:type, _, :list, [{:type, _, :integer, []}]}] = fun_args
assert {:type, _, :integer, []} = return
end
end
describe "Code.Typespec" do
test "type_to_quoted" do
quoted =
Enum.sort([
quote(do: @type(with_ann() :: t :: atom())),
quote(do: @type(a_tuple() :: tuple())),
quote(do: @type(empty_tuple() :: {})),
quote(do: @type(one_tuple() :: {:foo})),
quote(do: @type(two_tuple() :: {:foo, :bar})),
quote(do: @type(imm_type_1() :: 1)),
quote(do: @type(imm_type_2() :: :foo)),
quote(do: @type(simple_type() :: integer())),
quote(do: @type(param_type(p) :: [p])),
quote(do: @type(union_type() :: integer() | binary() | boolean())),
quote(do: @type(binary_type1() :: <<_::_*8>>)),
quote(do: @type(binary_type2() :: <<_::3>>)),
quote(do: @type(binary_type3() :: <<_::3, _::_*8>>)),
quote(do: @type(tuple_type() :: {integer()})),
quote(
do: @type(ftype() :: (() -> any()) | (() -> integer()) | (integer() -> integer()))
),
quote(do: @type(cl() :: charlist())),
quote(do: @type(st() :: struct())),
quote(do: @type(ab() :: as_boolean(term()))),
quote(do: @type(kw() :: keyword())),
quote(do: @type(kwt() :: keyword(term()))),
quote(do: @type(vaf() :: (... -> any()))),
quote(do: @type(rng() :: 1..10)),
quote(do: @type(opts() :: [first: integer(), step: integer(), last: integer()])),
quote(do: @type(ops() :: {+1, -1})),
quote(do: @type(a_map() :: map())),
quote(do: @type(empty_map() :: %{})),
quote(do: @type(my_map() :: %{hello: :world})),
quote(do: @type(my_req_map() :: %{required(0) => :foo})),
quote(do: @type(my_opt_map() :: %{optional(0) => :foo})),
quote(do: @type(my_struct() :: %TypespecTest{hello: :world})),
quote(do: @type(list1() :: list())),
quote(do: @type(list2() :: [0])),
quote(do: @type(list3() :: [...])),
quote(do: @type(list4() :: [0, ...])),
quote(do: @type(nil_list() :: []))
])
bytecode =
test_module do
Module.eval_quoted(__MODULE__, quoted)
end
types = types(bytecode)
Enum.each(Enum.zip(types, quoted), fn {{:type, type}, definition} ->
ast = Code.Typespec.type_to_quoted(type)
assert Macro.to_string(quote(do: @type(unquote(ast)))) == Macro.to_string(definition)
end)
end
test "type_to_quoted for paren_type" do
type = {:my_type, {:paren_type, 0, [{:type, 0, :integer, []}]}, []}
assert Code.Typespec.type_to_quoted(type) ==
{:"::", [], [{:my_type, [], []}, {:integer, [line: 0], []}]}
end
test "spec_to_quoted" do
quoted =
Enum.sort([
quote(do: @spec(foo() :: integer())),
quote(do: @spec(foo(atom()) :: integer() | [{}])),
quote(do: @spec(foo(arg) :: integer() when [arg: integer()])),
quote(do: @spec(foo(arg) :: arg when [arg: var])),
quote(do: @spec(foo(arg :: atom()) :: atom()))
])
bytecode =
test_module do
def foo(), do: 1
def foo(arg), do: arg
Module.eval_quoted(__MODULE__, quote(do: (unquote_splicing(quoted))))
end
specs =
Enum.flat_map(specs(bytecode), fn {{_, _}, specs} ->
Enum.map(specs, fn spec ->
quote(do: @spec(unquote(Code.Typespec.spec_to_quoted(:foo, spec))))
end)
end)
specs_with_quoted = specs |> Enum.sort() |> Enum.zip(quoted)
Enum.each(specs_with_quoted, fn {spec, definition} ->
assert Macro.to_string(spec) == Macro.to_string(definition)
end)
end
test "non-variables are given as arguments" do
msg = ~r/The type one_bad_variable\/1 has an invalid argument\(s\): String.t\(\)/
assert_raise CompileError, msg, fn ->
test_module do
@type one_bad_variable(String.t()) :: String.t()
end
end
msg = ~r/The type two_bad_variables\/2 has an invalid argument\(s\): :ok, Enum.t\(\)/
assert_raise CompileError, msg, fn ->
test_module do
@type two_bad_variables(:ok, Enum.t()) :: {:ok, []}
end
end
msg = ~r/The type one_bad_one_good\/2 has an invalid argument\(s\): \"\"/
assert_raise CompileError, msg, fn ->
test_module do
@type one_bad_one_good(input1, "") :: {:ok, input1}
end
end
end
test "retrieval invalid data" do
assert Code.Typespec.fetch_types(Unknown) == :error
assert Code.Typespec.fetch_specs(Unknown) == :error
end
# This is a test that implements all types specified in lib/elixir/pages/Typespecs.md
test "documented types and their AST" do
defmodule SomeStruct do
defstruct [:key]
end
quoted =
Enum.sort([
## Basic types
quote(do: @type(basic_any() :: any())),
quote(do: @type(basic_none() :: none())),
quote(do: @type(basic_atom() :: atom())),
quote(do: @type(basic_map() :: map())),
quote(do: @type(basic_pid() :: pid())),
quote(do: @type(basic_port() :: port())),
quote(do: @type(basic_reference() :: reference())),
quote(do: @type(basic_struct() :: struct())),
quote(do: @type(basic_tuple() :: tuple())),
# Numbers
quote(do: @type(basic_float() :: float())),
quote(do: @type(basic_integer() :: integer())),
quote(do: @type(basic_neg_integer() :: neg_integer())),
quote(do: @type(basic_non_neg_integer() :: non_neg_integer())),
quote(do: @type(basic_pos_integer() :: pos_integer())),
# Lists
quote(do: @type(basic_list_type() :: list(integer()))),
quote(do: @type(basic_nonempty_list_type() :: nonempty_list(integer()))),
quote do
@type basic_maybe_improper_list_type() :: maybe_improper_list(integer(), atom())
end,
quote do
@type basic_nonempty_improper_list_type() :: nonempty_improper_list(integer(), atom())
end,
quote do
@type basic_nonempty_maybe_improper_list_type() ::
nonempty_maybe_improper_list(integer(), atom())
end,
## Literals
quote(do: @type(literal_atom() :: :atom)),
quote(do: @type(literal_integer() :: 1)),
quote(do: @type(literal_integers() :: 1..10)),
quote(do: @type(literal_empty_bitstring() :: <<>>)),
quote(do: @type(literal_size_0() :: <<_::0>>)),
quote(do: @type(literal_unit_1() :: <<_::_*1>>)),
quote(do: @type(literal_size_1_unit_8() :: <<_::100, _::_*256>>)),
quote(do: @type(literal_function_arity_any() :: (... -> integer()))),
quote(do: @type(literal_function_arity_0() :: (() -> integer()))),
quote(do: @type(literal_function_arity_2() :: (integer(), atom() -> integer()))),
quote(do: @type(literal_list_type() :: [integer()])),
quote(do: @type(literal_empty_list() :: [])),
quote(do: @type(literal_list_nonempty() :: [...])),
quote(do: @type(literal_nonempty_list_type() :: [atom(), ...])),
quote(do: @type(literal_keyword_list_fixed_key() :: [key: integer()])),
quote(do: @type(literal_keyword_list_fixed_key2() :: [{:key, integer()}])),
quote(do: @type(literal_keyword_list_type_key() :: [{binary(), integer()}])),
quote(do: @type(literal_empty_map() :: %{})),
quote(do: @type(literal_map_with_key() :: %{key: integer()})),
quote(
do: @type(literal_map_with_required_key() :: %{required(bitstring()) => integer()})
),
quote(
do: @type(literal_map_with_optional_key() :: %{optional(bitstring()) => integer()})
),
quote(do: @type(literal_struct_all_fields_any_type() :: %SomeStruct{})),
quote(do: @type(literal_struct_all_fields_key_type() :: %SomeStruct{key: integer()})),
quote(do: @type(literal_empty_tuple() :: {})),
quote(do: @type(literal_2_element_tuple() :: {1, 2})),
## Built-in types
quote(do: @type(built_in_term() :: term())),
quote(do: @type(built_in_arity() :: arity())),
quote(do: @type(built_in_as_boolean() :: as_boolean(:t))),
quote(do: @type(built_in_binary() :: binary())),
quote(do: @type(built_in_bitstring() :: bitstring())),
quote(do: @type(built_in_boolean() :: boolean())),
quote(do: @type(built_in_byte() :: byte())),
quote(do: @type(built_in_char() :: char())),
quote(do: @type(built_in_charlist() :: charlist())),
quote(do: @type(built_in_nonempty_charlist() :: nonempty_charlist())),
quote(do: @type(built_in_fun() :: fun())),
quote(do: @type(built_in_function() :: function())),
quote(do: @type(built_in_identifier() :: identifier())),
quote(do: @type(built_in_iodata() :: iodata())),
quote(do: @type(built_in_iolist() :: iolist())),
quote(do: @type(built_in_keyword() :: keyword())),
quote(do: @type(built_in_keyword_value_type() :: keyword(:t))),
quote(do: @type(built_in_list() :: list())),
quote(do: @type(built_in_nonempty_list() :: nonempty_list())),
quote(do: @type(built_in_maybe_improper_list() :: maybe_improper_list())),
quote(
do: @type(built_in_nonempty_maybe_improper_list() :: nonempty_maybe_improper_list())
),
quote(do: @type(built_in_mfa() :: mfa())),
quote(do: @type(built_in_module() :: module())),
quote(do: @type(built_in_no_return() :: no_return())),
quote(do: @type(built_in_node() :: node())),
quote(do: @type(built_in_number() :: number())),
quote(do: @type(built_in_struct() :: struct())),
quote(do: @type(built_in_timeout() :: timeout())),
## Remote types
quote(do: @type(remote_enum_t0() :: Enum.t())),
quote(do: @type(remote_keyword_t1() :: Keyword.t(integer())))
])
bytecode =
test_module do
Module.eval_quoted(__MODULE__, quoted)
end
types = types(bytecode)
Enum.each(Enum.zip(types, quoted), fn {{:type, type}, definition} ->
ast = Code.Typespec.type_to_quoted(type)
ast_string = Macro.to_string(quote(do: @type(unquote(ast))))
case type do
# These cases do not translate directly to their own string version.
{:basic_list_type, _, _} ->
assert ast_string == "@type(basic_list_type() :: [integer()])"
{:basic_nonempty_list_type, _, _} ->
assert ast_string == "@type(basic_nonempty_list_type() :: [integer(), ...])"
{:literal_empty_bitstring, _, _} ->
assert ast_string == "@type(literal_empty_bitstring() :: <<_::0>>)"
{:literal_keyword_list_fixed_key, _, _} ->
assert ast_string == "@type(literal_keyword_list_fixed_key() :: [{:key, integer()}])"
{:literal_keyword_list_fixed_key2, _, _} ->
assert ast_string == "@type(literal_keyword_list_fixed_key2() :: [{:key, integer()}])"
{:literal_struct_all_fields_any_type, _, _} ->
assert ast_string ==
"@type(literal_struct_all_fields_any_type() :: %TypespecTest.SomeStruct{key: term()})"
{:literal_struct_all_fields_key_type, _, _} ->
assert ast_string ==
"@type(literal_struct_all_fields_key_type() :: %TypespecTest.SomeStruct{key: integer()})"
{:built_in_fun, _, _} ->
assert ast_string == "@type(built_in_fun() :: (... -> any()))"
{:built_in_nonempty_list, _, _} ->
assert ast_string == "@type(built_in_nonempty_list() :: [...])"
_ ->
assert ast_string == Macro.to_string(definition)
end
end)
end
end
describe "behaviour_info" do
defmodule SampleCallbacks do
@callback first(integer) :: integer
@callback foo(atom(), binary) :: binary
@callback bar(External.hello(), my_var :: binary) :: binary
@callback guarded(my_var) :: my_var when my_var: binary
@callback orr(atom | integer) :: atom
@callback literal(123, {atom}, :foo, [integer], true) :: atom
@macrocallback last(integer) :: Macro.t()
@macrocallback last() :: atom
@optional_callbacks bar: 2, last: 0
@optional_callbacks first: 1
end
test "defines callbacks" do
expected_callbacks = [
"MACRO-last": 1,
"MACRO-last": 2,
bar: 2,
first: 1,
foo: 2,
guarded: 1,
literal: 5,
orr: 1
]
assert Enum.sort(SampleCallbacks.behaviour_info(:callbacks)) == expected_callbacks
end
test "defines optional callbacks" do
assert Enum.sort(SampleCallbacks.behaviour_info(:optional_callbacks)) ==
["MACRO-last": 1, bar: 2, first: 1]
end
end
end
| 33.688719 | 110 | 0.534758 |
f7204f7dd022be886af666f0273dd762b3f80851 | 6,210 | exs | Elixir | test/madari_web/controllers/user_auth_test.exs | yoossaland/yoossa | 1e1ab968d12c7690a76fc670c47c91c29efb2979 | [
"BSD-2-Clause"
] | null | null | null | test/madari_web/controllers/user_auth_test.exs | yoossaland/yoossa | 1e1ab968d12c7690a76fc670c47c91c29efb2979 | [
"BSD-2-Clause"
] | null | null | null | test/madari_web/controllers/user_auth_test.exs | yoossaland/yoossa | 1e1ab968d12c7690a76fc670c47c91c29efb2979 | [
"BSD-2-Clause"
] | null | null | null | defmodule MadariWeb.UserAuthTest do
use MadariWeb.ConnCase
alias Madari.Accounts
alias MadariWeb.UserAuth
import Madari.AccountsFixtures
@remember_me_cookie "_madari_web_user_remember_me"
setup %{conn: conn} do
conn =
conn
|> Map.replace!(:secret_key_base, MadariWeb.Endpoint.config(:secret_key_base))
|> init_test_session(%{})
%{user: user_fixture(), conn: conn}
end
describe "log_in_user/3" do
test "stores the user token in the session", %{conn: conn, user: user} do
conn = UserAuth.log_in_user(conn, user)
assert token = get_session(conn, :user_token)
assert get_session(conn, :live_socket_id) == "users_sessions:#{Base.url_encode64(token)}"
assert redirected_to(conn) == "/"
assert Accounts.get_user_by_session_token(token)
end
test "clears everything previously stored in the session", %{conn: conn, user: user} do
conn = conn |> put_session(:to_be_removed, "value") |> UserAuth.log_in_user(user)
refute get_session(conn, :to_be_removed)
end
test "redirects to the configured path", %{conn: conn, user: user} do
conn = conn |> put_session(:user_return_to, "/hello") |> UserAuth.log_in_user(user)
assert redirected_to(conn) == "/hello"
end
test "writes a cookie if remember_me is configured", %{conn: conn, user: user} do
conn = conn |> fetch_cookies() |> UserAuth.log_in_user(user, %{"remember_me" => "true"})
assert get_session(conn, :user_token) == conn.cookies[@remember_me_cookie]
assert %{value: signed_token, max_age: max_age} = conn.resp_cookies[@remember_me_cookie]
assert signed_token != get_session(conn, :user_token)
assert max_age == 5_184_000
end
end
describe "logout_user/1" do
test "erases session and cookies", %{conn: conn, user: user} do
user_token = Accounts.generate_user_session_token(user)
conn =
conn
|> put_session(:user_token, user_token)
|> put_req_cookie(@remember_me_cookie, user_token)
|> fetch_cookies()
|> UserAuth.log_out_user()
refute get_session(conn, :user_token)
refute conn.cookies[@remember_me_cookie]
assert %{max_age: 0} = conn.resp_cookies[@remember_me_cookie]
assert redirected_to(conn) == "/"
refute Accounts.get_user_by_session_token(user_token)
end
test "broadcasts to the given live_socket_id", %{conn: conn} do
live_socket_id = "users_sessions:abcdef-token"
MadariWeb.Endpoint.subscribe(live_socket_id)
conn
|> put_session(:live_socket_id, live_socket_id)
|> UserAuth.log_out_user()
assert_receive %Phoenix.Socket.Broadcast{event: "disconnect", topic: ^live_socket_id}
end
test "works even if user is already logged out", %{conn: conn} do
conn = conn |> fetch_cookies() |> UserAuth.log_out_user()
refute get_session(conn, :user_token)
assert %{max_age: 0} = conn.resp_cookies[@remember_me_cookie]
assert redirected_to(conn) == "/"
end
end
describe "fetch_current_user/2" do
test "authenticates user from session", %{conn: conn, user: user} do
user_token = Accounts.generate_user_session_token(user)
conn = conn |> put_session(:user_token, user_token) |> UserAuth.fetch_current_user([])
assert conn.assigns.current_user.id == user.id
end
test "authenticates user from cookies", %{conn: conn, user: user} do
logged_in_conn =
conn |> fetch_cookies() |> UserAuth.log_in_user(user, %{"remember_me" => "true"})
user_token = logged_in_conn.cookies[@remember_me_cookie]
%{value: signed_token} = logged_in_conn.resp_cookies[@remember_me_cookie]
conn =
conn
|> put_req_cookie(@remember_me_cookie, signed_token)
|> UserAuth.fetch_current_user([])
assert get_session(conn, :user_token) == user_token
assert conn.assigns.current_user.id == user.id
end
test "does not authenticate if data is missing", %{conn: conn, user: user} do
_ = Accounts.generate_user_session_token(user)
conn = UserAuth.fetch_current_user(conn, [])
refute get_session(conn, :user_token)
refute conn.assigns.current_user
end
end
describe "redirect_if_user_is_authenticated/2" do
test "redirects if user is authenticated", %{conn: conn, user: user} do
conn = conn |> assign(:current_user, user) |> UserAuth.redirect_if_user_is_authenticated([])
assert conn.halted
assert redirected_to(conn) == "/"
end
test "does not redirect if user is not authenticated", %{conn: conn} do
conn = UserAuth.redirect_if_user_is_authenticated(conn, [])
refute conn.halted
refute conn.status
end
end
describe "require_authenticated_user/2" do
test "redirects if user is not authenticated", %{conn: conn} do
conn = conn |> fetch_flash() |> UserAuth.require_authenticated_user([])
assert conn.halted
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
assert get_flash(conn, :error) == "You must log in to access this page."
end
test "stores the path to redirect to on GET", %{conn: conn} do
halted_conn =
%{conn | path_info: ["foo"], query_string: ""}
|> fetch_flash()
|> UserAuth.require_authenticated_user([])
assert halted_conn.halted
assert get_session(halted_conn, :user_return_to) == "/foo"
halted_conn =
%{conn | path_info: ["foo"], query_string: "bar=baz"}
|> fetch_flash()
|> UserAuth.require_authenticated_user([])
assert halted_conn.halted
assert get_session(halted_conn, :user_return_to) == "/foo?bar=baz"
halted_conn =
%{conn | path_info: ["foo"], query_string: "bar", method: "POST"}
|> fetch_flash()
|> UserAuth.require_authenticated_user([])
assert halted_conn.halted
refute get_session(halted_conn, :user_return_to)
end
test "does not redirect if user is authenticated", %{conn: conn, user: user} do
conn = conn |> assign(:current_user, user) |> UserAuth.require_authenticated_user([])
refute conn.halted
refute conn.status
end
end
end
| 36.315789 | 98 | 0.675845 |
f72081032316d03276466843cabc457381f7cf51 | 9,765 | ex | Elixir | lib/sanbase/clickhouse/historical_balance/historical_balance.ex | rmoorman/sanbase2 | 226784ab43a24219e7332c49156b198d09a6dd85 | [
"MIT"
] | 1 | 2022-01-30T19:51:39.000Z | 2022-01-30T19:51:39.000Z | lib/sanbase/clickhouse/historical_balance/historical_balance.ex | rmoorman/sanbase2 | 226784ab43a24219e7332c49156b198d09a6dd85 | [
"MIT"
] | null | null | null | lib/sanbase/clickhouse/historical_balance/historical_balance.ex | rmoorman/sanbase2 | 226784ab43a24219e7332c49156b198d09a6dd85 | [
"MIT"
] | null | null | null | defmodule Sanbase.Clickhouse.HistoricalBalance do
@moduledoc ~s"""
Module providing functions for historical balances and balance changes.
This module dispatches to underlaying modules and serves as common interface
for many different database tables and schemas.
"""
use AsyncWith
import Sanbase.Utils.Transform, only: [maybe_apply_function: 2]
alias Sanbase.Model.Project
alias Sanbase.BlockchainAddress
alias Sanbase.Clickhouse.HistoricalBalance.XrpBalance
@balances_aggregated_blockchains ["ethereum", "bitcoin", "bitcoin-cash", "litecoin", "binance"]
@supported_infrastructures ["BCH", "BNB", "BEP2", "BTC", "LTC", "XRP", "ETH"]
def supported_infrastructures(), do: @supported_infrastructures
@type selector :: %{
optional(:infrastructure) => String.t(),
optional(:currency) => String.t(),
optional(:slug) => String.t(),
optional(:contract) => String.t(),
optional(:decimals) => non_neg_integer()
}
@type slug :: String.t()
@type address :: String.t() | list(String.t())
@typedoc ~s"""
An interval represented as string. It has the format of number followed by one of:
ns, ms, s, m, h, d or w - each representing some time unit
"""
@type interval :: String.t()
@typedoc ~s"""
The type returned by the historical_balance/5 function
"""
@type historical_balance_return ::
{:ok, []}
| {:ok, list(%{datetime: DateTime.t(), balance: number()})}
| {:error, String.t()}
defguard balances_aggregated_blockchain?(blockchain)
when blockchain in @balances_aggregated_blockchains
@doc ~s"""
Return a list of the assets that a given address currently holds or
has held in the past.
This can be combined with the historical balance query to see the historical
balance of all currently owned assets
"""
@spec assets_held_by_address(map()) :: {:ok, list(map())} | {:error, String.t()}
def assets_held_by_address(%{infrastructure: infr, address: address}) do
case selector_to_args(%{infrastructure: infr}) do
%{blockchain: blockchain} when balances_aggregated_blockchain?(blockchain) ->
Sanbase.Balance.assets_held_by_address(address)
%{module: module} ->
module.assets_held_by_address(address)
{:error, error} ->
{:error, error}
end
|> maybe_apply_function(fn data -> Enum.sort_by(data, &Map.get(&1, :balance), :desc) end)
end
@doc ~s"""
For a given address or list of addresses returns the `slug` balance change for the
from-to period. The returned lists indicates the address, before balance, after balance
and the balance change
"""
@spec balance_change(selector, address, from :: DateTime.t(), to :: DateTime.t()) ::
__MODULE__.Behaviour.balance_change_result()
def balance_change(selector, address, from, to) do
case selector_to_args(selector) do
%{blockchain: blockchain, slug: slug} when balances_aggregated_blockchain?(blockchain) ->
Sanbase.Balance.balance_change(address, slug, from, to)
%{module: module, asset: asset, decimals: decimals} ->
module.balance_change(address, asset, decimals, from, to)
{:error, error} ->
{:error, error}
end
end
@doc ~s"""
For a given address or list of addresses returns the combined `slug` balance for each bucket
of size `interval` in the from-to time period
"""
@spec historical_balance(selector, address, from :: DateTime.t(), to :: DateTime.t(), interval) ::
__MODULE__.Behaviour.historical_balance_result()
def historical_balance(selector, address, from, to, interval) do
case selector_to_args(selector) do
%{blockchain: blockchain, slug: slug} when balances_aggregated_blockchain?(blockchain) ->
Sanbase.Balance.historical_balance(address, slug, from, to, interval)
%{module: module, asset: asset, decimals: decimals} ->
module.historical_balance(address, asset, decimals, from, to, interval)
{:error, error} ->
{:error, error}
end
end
@spec current_balance(selector, address | list(address)) ::
__MODULE__.Behaviour.current_balance_result()
def current_balance(selector, address) do
case selector_to_args(selector) do
%{blockchain: blockchain, slug: slug} when balances_aggregated_blockchain?(blockchain) ->
Sanbase.Balance.current_balance(address, slug)
%{module: module, asset: asset, decimals: decimals} ->
module.current_balance(address, asset, decimals)
{:error, error} ->
{:error, error}
end
end
defguard is_ethereum(map)
when (is_map_key(map, :slug) and map.slug == "ethereum") or
(is_map_key(map, :contract) and map.contract == "ETH") or
(is_map_key(map, :infrastructure) and not is_map_key(map, :slug) and
map.infrastructure == "ETH")
def selector_to_args(
%{infrastructure: "ETH", contract: contract, decimals: decimals} = selector
)
when is_binary(contract) and is_number(decimals) and decimals > 0 and
not is_ethereum(selector) do
%{
module: :none,
asset: String.downcase(contract),
contract: String.downcase(contract),
blockchain: BlockchainAddress.blockchain_from_infrastructure("ETH"),
slug: Map.get(selector, :slug),
decimals: decimals
}
end
def selector_to_args(%{} = selector) when is_ethereum(selector) do
selector = Map.put_new(selector, :slug, "ethereum")
with %{slug: slug, contract: contract, decimals: decimals, infrastructure: "ETH"} <-
get_project_details(selector) do
%{
module: :none,
asset: contract,
contract: contract,
blockchain: BlockchainAddress.blockchain_from_infrastructure("ETH"),
slug: slug,
decimals: decimals
}
end
end
def selector_to_args(%{infrastructure: "ETH", slug: slug} = selector) when is_binary(slug) do
with %{contract: contract, decimals: decimals} <- get_project_details(selector) do
%{
module: :none,
asset: contract,
contract: contract,
blockchain: BlockchainAddress.blockchain_from_infrastructure("ETH"),
slug: slug,
decimals: decimals
}
end
end
def selector_to_args(%{infrastructure: "XRP"} = selector) do
%{
module: XrpBalance,
asset: Map.get(selector, :currency, "XRP"),
currency: Map.get(selector, :currency, "XRP"),
blockchain: BlockchainAddress.blockchain_from_infrastructure("XRP"),
slug: "ripple",
decimals: 0
}
end
def selector_to_args(%{infrastructure: "BTC"} = selector) do
selector = Map.put_new(selector, :slug, "bitcoin")
with %{slug: slug, contract: contract, decimals: decimals} <- get_project_details(selector) do
%{
module: :none,
asset: contract,
contract: contract,
blockchain: BlockchainAddress.blockchain_from_infrastructure("BTC"),
slug: slug,
decimals: decimals
}
end
end
def selector_to_args(%{infrastructure: "BCH"} = selector) do
selector = Map.put_new(selector, :slug, "bitcoin-cash")
with %{slug: slug, contract: contract, decimals: decimals} <- get_project_details(selector) do
%{
module: :none,
asset: contract,
contract: contract,
blockchain: BlockchainAddress.blockchain_from_infrastructure("BCH"),
slug: slug,
decimals: decimals
}
end
end
def selector_to_args(%{infrastructure: "LTC"} = selector) do
selector = Map.put_new(selector, :slug, "litecoin")
with %{slug: slug, contract: contract, decimals: decimals} <- get_project_details(selector) do
%{
module: :none,
asset: contract,
contract: contract,
blockchain: BlockchainAddress.blockchain_from_infrastructure("LTC"),
slug: slug,
decimals: decimals
}
end
end
def selector_to_args(%{infrastructure: "BNB"} = selector) do
selector = Map.put_new(selector, :slug, "binance-coin")
with %{slug: slug, contract: contract, decimals: decimals} <- get_project_details(selector) do
%{
module: :none,
asset: contract,
contract: contract,
blockchain: BlockchainAddress.blockchain_from_infrastructure("BNB"),
slug: slug,
decimals: decimals
}
end
end
def selector_to_args(%{infrastructure: infrastructure} = selector) do
{:error,
"Invalid historical balance selector. The infrastructure #{inspect(infrastructure)} is not supported. Provided selector: #{inspect(selector)}"}
end
def selector_to_args(%{slug: slug} = selector) when not is_nil(slug) do
with %{infrastructure: _} = map <- get_project_details(%{slug: slug}) do
%{original_selector: selector} |> Map.merge(map) |> selector_to_args()
else
{:error, {:missing_contract, _}} ->
{:error,
"Invalid historical balance selector. The provided slug has no contract data available. Provided selector: #{inspect(selector)}"}
error ->
error
end
end
def selector_to_args(selector) do
original_selector = Map.get(selector, :original_selector) || selector
{:error, "Invalid historical balance selector: #{inspect(original_selector)}"}
end
defp get_project_details(%{contract: _, decimals: _, slug: _, infrastructure: _} = data) do
data
end
defp get_project_details(%{slug: slug}) do
with {:ok, contract, decimals, infrastructure} <-
Project.contract_info_infrastructure_by_slug(slug) do
%{contract: contract, decimals: decimals, slug: slug, infrastructure: infrastructure}
end
end
end
| 34.62766 | 148 | 0.664209 |
f720b6d604e9bc8228d656ca760249b163fe1c86 | 1,007 | ex | Elixir | lib/azk_dns/options.ex | azukiapp/azk-dns | 88fe8d4ec94c817401be970f0a334db1e3b6a127 | [
"Apache-2.0"
] | 2 | 2015-06-13T03:34:57.000Z | 2015-10-25T05:25:00.000Z | lib/azk_dns/options.ex | azukiapp/azk-dns | 88fe8d4ec94c817401be970f0a334db1e3b6a127 | [
"Apache-2.0"
] | null | null | null | lib/azk_dns/options.ex | azukiapp/azk-dns | 88fe8d4ec94c817401be970f0a334db1e3b6a127 | [
"Apache-2.0"
] | null | null | null | defmodule AzkDns.Options do
@fields [ip: nil, domains: "", pattern: nil]
Record.deffunctions(@fields, __ENV__)
Record.import __MODULE__, as: :opts
def new(ip, domains // "dev.azk.io") do
opts().domains(domains).ip(ip)
end
defoverridable ip: 2
def ip(address, opts() = opts) when is_bitstring(address) do
{:ok, ip} = :inet.ip('#{address}')
super(ip, opts)
end
def ip(ip, opts() = opts) do
super(ip, opts)
end
defoverridable domains: 2
def domains(value, opts() = opts) do
opts(opts, domains: value, pattern: make_pattern(value))
end
def lookup(address, opts(ip: ip, pattern: pattern, domains: domains)) do
case Regex.match?(pattern, address) do
true -> {:ok, ip}
_ -> {:error, "#{address} not found in #{domains}"}
end
end
defp make_pattern(domains) when is_bitstring(domains) do
domains = Enum.map(String.split(domains, ","), String.strip(&1))
domains = Enum.join(domains, "|")
%r/^(.*\.?(#{domains}))$/gi
end
end
| 25.820513 | 74 | 0.632572 |
f720c137e7d4277f3b07ef6f9754d63b9e1f2b24 | 2,110 | ex | Elixir | clients/network_connectivity/lib/google_api/network_connectivity/v1/model/set_iam_policy_request.ex | yoshi-code-bot/elixir-google-api | cdb6032f01fac5ab704803113c39f2207e9e019d | [
"Apache-2.0"
] | null | null | null | clients/network_connectivity/lib/google_api/network_connectivity/v1/model/set_iam_policy_request.ex | yoshi-code-bot/elixir-google-api | cdb6032f01fac5ab704803113c39f2207e9e019d | [
"Apache-2.0"
] | null | null | null | clients/network_connectivity/lib/google_api/network_connectivity/v1/model/set_iam_policy_request.ex | yoshi-code-bot/elixir-google-api | cdb6032f01fac5ab704803113c39f2207e9e019d | [
"Apache-2.0"
] | null | null | null | # Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE: This file is auto generated by the elixir code generator program.
# Do not edit this file manually.
defmodule GoogleApi.NetworkConnectivity.V1.Model.SetIamPolicyRequest do
@moduledoc """
Request message for `SetIamPolicy` method.
## Attributes
* `policy` (*type:* `GoogleApi.NetworkConnectivity.V1.Model.Policy.t`, *default:* `nil`) - REQUIRED: The complete policy to be applied to the `resource`. The size of the policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Google Cloud services (such as Projects) might reject them.
* `updateMask` (*type:* `String.t`, *default:* `nil`) - OPTIONAL: A FieldMask specifying which fields of the policy to modify. Only the fields in the mask will be modified. If no mask is provided, the following default mask is used: `paths: "bindings, etag"`
"""
use GoogleApi.Gax.ModelBase
@type t :: %__MODULE__{
:policy => GoogleApi.NetworkConnectivity.V1.Model.Policy.t() | nil,
:updateMask => String.t() | nil
}
field(:policy, as: GoogleApi.NetworkConnectivity.V1.Model.Policy)
field(:updateMask)
end
defimpl Poison.Decoder, for: GoogleApi.NetworkConnectivity.V1.Model.SetIamPolicyRequest do
def decode(value, options) do
GoogleApi.NetworkConnectivity.V1.Model.SetIamPolicyRequest.decode(value, options)
end
end
defimpl Poison.Encoder, for: GoogleApi.NetworkConnectivity.V1.Model.SetIamPolicyRequest do
def encode(value, options) do
GoogleApi.Gax.ModelBase.encode(value, options)
end
end
| 42.2 | 317 | 0.745972 |
f720d31bf2809160867b6b6dd4ae96f11146e4cb | 3,652 | ex | Elixir | clients/page_speed_online/lib/google_api/page_speed_online/v2/api/pagespeedapi.ex | GoNZooo/elixir-google-api | cf3ad7392921177f68091f3d9001f1b01b92f1cc | [
"Apache-2.0"
] | null | null | null | clients/page_speed_online/lib/google_api/page_speed_online/v2/api/pagespeedapi.ex | GoNZooo/elixir-google-api | cf3ad7392921177f68091f3d9001f1b01b92f1cc | [
"Apache-2.0"
] | null | null | null | clients/page_speed_online/lib/google_api/page_speed_online/v2/api/pagespeedapi.ex | GoNZooo/elixir-google-api | cf3ad7392921177f68091f3d9001f1b01b92f1cc | [
"Apache-2.0"
] | 1 | 2018-07-28T20:50:50.000Z | 2018-07-28T20:50:50.000Z | # Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE: This class is auto generated by the swagger code generator program.
# https://github.com/swagger-api/swagger-codegen.git
# Do not edit the class manually.
defmodule GoogleApi.PageSpeedOnline.V2.Api.Pagespeedapi do
@moduledoc """
API calls for all endpoints tagged `Pagespeedapi`.
"""
alias GoogleApi.PageSpeedOnline.V2.Connection
import GoogleApi.PageSpeedOnline.V2.RequestBuilder
@doc """
Runs PageSpeed analysis on the page at the specified URL, and returns PageSpeed scores, a list of suggestions to make that page faster, and other information.
## Parameters
- connection (GoogleApi.PageSpeedOnline.V2.Connection): Connection to server
- url (String): The URL to fetch and analyze
- opts (KeywordList): [optional] Optional parameters
- :alt (String): Data format for the response.
- :fields (String): Selector specifying which fields to include in a partial response.
- :key (String): API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
- :oauth_token (String): OAuth 2.0 token for the current user.
- :pretty_print (Boolean): Returns response with indentations and line breaks.
- :quota_user (String): Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters. Overrides userIp if both are provided.
- :user_ip (String): IP address of the site where the request originates. Use this if you want to enforce per-user limits.
- :filter_third_party_resources (Boolean): Indicates if third party resources should be filtered out before PageSpeed analysis.
- :locale (String): The locale used to localize formatted results
- :rule (List[String]): A PageSpeed rule to run; if none are given, all rules are run
- :screenshot (Boolean): Indicates if binary data containing a screenshot should be included
- :strategy (String): The analysis strategy to use
## Returns
{:ok, %GoogleApi.PageSpeedOnline.V2.Model.Result{}} on success
{:error, info} on failure
"""
@spec pagespeedonline_pagespeedapi_runpagespeed(Tesla.Env.client, String.t, keyword()) :: {:ok, GoogleApi.PageSpeedOnline.V2.Model.Result.t} | {:error, Tesla.Env.t}
def pagespeedonline_pagespeedapi_runpagespeed(connection, url, opts \\ []) do
optional_params = %{
:"alt" => :query,
:"fields" => :query,
:"key" => :query,
:"oauth_token" => :query,
:"prettyPrint" => :query,
:"quotaUser" => :query,
:"userIp" => :query,
:"filter_third_party_resources" => :query,
:"locale" => :query,
:"rule" => :query,
:"screenshot" => :query,
:"strategy" => :query
}
%{}
|> method(:get)
|> url("/runPagespeed")
|> add_param(:query, :"url", url)
|> add_optional_params(optional_params, opts)
|> Enum.into([])
|> (&Connection.request(connection, &1)).()
|> decode(%GoogleApi.PageSpeedOnline.V2.Model.Result{})
end
end
| 45.08642 | 217 | 0.709474 |
f720ea4268d41136e5dfad93c713cbdcce6d39ba | 1,516 | ex | Elixir | clients/storage/lib/google_api/storage/v1/model/bucket_lifecycle_action.ex | GoNZooo/elixir-google-api | cf3ad7392921177f68091f3d9001f1b01b92f1cc | [
"Apache-2.0"
] | null | null | null | clients/storage/lib/google_api/storage/v1/model/bucket_lifecycle_action.ex | GoNZooo/elixir-google-api | cf3ad7392921177f68091f3d9001f1b01b92f1cc | [
"Apache-2.0"
] | null | null | null | clients/storage/lib/google_api/storage/v1/model/bucket_lifecycle_action.ex | GoNZooo/elixir-google-api | cf3ad7392921177f68091f3d9001f1b01b92f1cc | [
"Apache-2.0"
] | 1 | 2018-07-28T20:50:50.000Z | 2018-07-28T20:50:50.000Z | # Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE: This class is auto generated by the swagger code generator program.
# https://github.com/swagger-api/swagger-codegen.git
# Do not edit the class manually.
defmodule GoogleApi.Storage.V1.Model.BucketLifecycleAction do
@moduledoc """
The action to take.
## Attributes
- storageClass (String.t): Target storage class. Required iff the type of the action is SetStorageClass. Defaults to: `null`.
- type (String.t): Type of the action. Currently, only Delete and SetStorageClass are supported. Defaults to: `null`.
"""
defstruct [
:storageClass,
:type
]
end
defimpl Poison.Decoder, for: GoogleApi.Storage.V1.Model.BucketLifecycleAction do
def decode(value, _options) do
value
end
end
defimpl Poison.Encoder, for: GoogleApi.Storage.V1.Model.BucketLifecycleAction do
def encode(value, options) do
GoogleApi.Storage.V1.Deserializer.serialize_non_nil(value, options)
end
end
| 32.956522 | 127 | 0.754617 |
f72120ae4f7dc167b0c6fe0f3a1258df7b9ad797 | 1,624 | ex | Elixir | clients/dlp/lib/google_api/dlp/v2beta1/model/google_privacy_dlp_v2beta1_cloud_storage_options.ex | GoNZooo/elixir-google-api | cf3ad7392921177f68091f3d9001f1b01b92f1cc | [
"Apache-2.0"
] | null | null | null | clients/dlp/lib/google_api/dlp/v2beta1/model/google_privacy_dlp_v2beta1_cloud_storage_options.ex | GoNZooo/elixir-google-api | cf3ad7392921177f68091f3d9001f1b01b92f1cc | [
"Apache-2.0"
] | null | null | null | clients/dlp/lib/google_api/dlp/v2beta1/model/google_privacy_dlp_v2beta1_cloud_storage_options.ex | GoNZooo/elixir-google-api | cf3ad7392921177f68091f3d9001f1b01b92f1cc | [
"Apache-2.0"
] | 1 | 2018-07-28T20:50:50.000Z | 2018-07-28T20:50:50.000Z | # Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE: This class is auto generated by the swagger code generator program.
# https://github.com/swagger-api/swagger-codegen.git
# Do not edit the class manually.
defmodule GoogleApi.DLP.V2beta1.Model.GooglePrivacyDlpV2beta1CloudStorageOptions do
@moduledoc """
Options defining a file or a set of files (path ending with *) within a Google Cloud Storage bucket.
## Attributes
- fileSet (GooglePrivacyDlpV2beta1FileSet): Defaults to: `null`.
"""
defstruct [
:"fileSet"
]
end
defimpl Poison.Decoder, for: GoogleApi.DLP.V2beta1.Model.GooglePrivacyDlpV2beta1CloudStorageOptions do
import GoogleApi.DLP.V2beta1.Deserializer
def decode(value, options) do
value
|> deserialize(:"fileSet", :struct, GoogleApi.DLP.V2beta1.Model.GooglePrivacyDlpV2beta1FileSet, options)
end
end
defimpl Poison.Encoder, for: GoogleApi.DLP.V2beta1.Model.GooglePrivacyDlpV2beta1CloudStorageOptions do
def encode(value, options) do
GoogleApi.DLP.V2beta1.Deserializer.serialize_non_nil(value, options)
end
end
| 33.833333 | 108 | 0.77032 |
f72121c8c43f7e731919ffdcadd03ea509a5a4fd | 646 | ex | Elixir | lib/sonata_seed/numeric.ex | exstruct/sonata_seed | 965c88251190b22356326bd147ad60b191f7d439 | [
"MIT"
] | null | null | null | lib/sonata_seed/numeric.ex | exstruct/sonata_seed | 965c88251190b22356326bd147ad60b191f7d439 | [
"MIT"
] | null | null | null | lib/sonata_seed/numeric.ex | exstruct/sonata_seed | 965c88251190b22356326bd147ad60b191f7d439 | [
"MIT"
] | null | null | null | defmodule Sonata.Seed.Numeric do
use Bolero
alias Bolero.Generators, as: G
# https://www.postgresql.org/docs/9.1/static/datatype-numeric.html
def smallint() do
int(-32768, 32767)
end
def integer() do
int(-2147483648, 2147483647)
end
def bigint() do
int(-9223372036854775808, 9223372036854775807)
end
# TODO figure out the precision on these
def decimal() do
G.real()
end
def numeric() do
decimal()
end
def real() do
G.real()
end
def double() do
G.real()
end
# let postgres generate the serial values
def serial() do
nil
end
def bigserial() do
nil
end
end
| 14.681818 | 68 | 0.648607 |
f721916307f89b4e375fc1fe9d38aa62b5baf1c4 | 558 | ex | Elixir | lib/aspekt/features/milestone_description.ex | wjanssens/aspekt-elixir | 3b4926fa37cc056cafe7204589e0cac11289c6a8 | [
"Apache-2.0"
] | null | null | null | lib/aspekt/features/milestone_description.ex | wjanssens/aspekt-elixir | 3b4926fa37cc056cafe7204589e0cac11289c6a8 | [
"Apache-2.0"
] | null | null | null | lib/aspekt/features/milestone_description.ex | wjanssens/aspekt-elixir | 3b4926fa37cc056cafe7204589e0cac11289c6a8 | [
"Apache-2.0"
] | null | null | null | defmodule Aspekt.Features.MilestoneDescription do
use Ecto.Schema
import Ecto.Changeset
alias Aspekt.Features.MilestoneDescription
schema "milestone_description" do
field :effort, :integer
field :name, :string
field :node_id, :integer
field :sequence, :integer
timestamps()
end
@doc false
def changeset(%MilestoneDescription{} = milestone_description, attrs) do
milestone_description
|> cast(attrs, [:node_id, :sequence, :name, :effort])
|> validate_required([:node_id, :sequence, :name, :effort])
end
end
| 24.26087 | 74 | 0.718638 |
f721d888cdea6fe3da1256f4254680507e3a5a5a | 594 | exs | Elixir | test/tesla/adapter/hackney_test.exs | hasclass/tesla | c1ee0e3417ea269124869ca1ff33fd2364391154 | [
"MIT"
] | 1 | 2020-12-21T03:45:23.000Z | 2020-12-21T03:45:23.000Z | test/tesla/adapter/hackney_test.exs | hasclass/tesla | c1ee0e3417ea269124869ca1ff33fd2364391154 | [
"MIT"
] | null | null | null | test/tesla/adapter/hackney_test.exs | hasclass/tesla | c1ee0e3417ea269124869ca1ff33fd2364391154 | [
"MIT"
] | null | null | null | defmodule Tesla.Adapter.HackneyTest do
use ExUnit.Case
use Tesla.AdapterCase, adapter: Tesla.Adapter.Hackney
use Tesla.AdapterCase.Basic
use Tesla.AdapterCase.Multipart
use Tesla.AdapterCase.StreamRequestBody
use Tesla.AdapterCase.SSL,
ssl_options: [
cacertfile: "#{:code.priv_dir(:httparrot)}/ssl/server-ca.crt"
]
alias Tesla.Env
test "get with `with_body: true` option" do
request = %Env{
method: :get,
url: "#{@http}/ip"
}
assert {:ok, %Env{} = response} = call(request, with_body: true)
assert response.status == 200
end
end
| 22.846154 | 68 | 0.678451 |
f721d94225fe497a28ed70ed0afa704bc4928a9e | 300 | ex | Elixir | lib/mix/tasks/compile.simple_make.ex | NatTuck/script_tools | 48f3f96599e58360ff815a3d8f266b9255322105 | [
"Apache-2.0"
] | null | null | null | lib/mix/tasks/compile.simple_make.ex | NatTuck/script_tools | 48f3f96599e58360ff815a3d8f266b9255322105 | [
"Apache-2.0"
] | null | null | null | lib/mix/tasks/compile.simple_make.ex | NatTuck/script_tools | 48f3f96599e58360ff815a3d8f266b9255322105 | [
"Apache-2.0"
] | null | null | null | defmodule Mix.Tasks.Compile.SimpleMake do
def run(_args) do
{output, code} = System.cmd("make", [])
if code == 0 do
unless output =~ ~r/up to date/ do
IO.binwrite(output)
end
:ok
else
IO.binwrite(output)
{:error, "compile error"}
end
end
end
| 20 | 43 | 0.57 |
f721fe7de4db15dd73f33fdb55eded8ca2405ca2 | 1,742 | exs | Elixir | mix.exs | G-Corp/rfile | 64464534904c026211f23ab735ea6b15ea17401c | [
"BSD-3-Clause"
] | 5 | 2018-05-11T08:40:11.000Z | 2019-01-26T19:33:17.000Z | mix.exs | G-Corp/rfile | 64464534904c026211f23ab735ea6b15ea17401c | [
"BSD-3-Clause"
] | null | null | null | mix.exs | G-Corp/rfile | 64464534904c026211f23ab735ea6b15ea17401c | [
"BSD-3-Clause"
] | 2 | 2018-06-18T08:41:04.000Z | 2021-08-02T14:40:02.000Z | # File: mix.exs
# This file was generated from rebar.config
# Using rebar3_elixir (https://github.com/G-Corp/rebar3_elixir)
# MODIFY IT AT YOUR OWN RISK AND ONLY IF YOU KNOW WHAT YOU ARE DOING!
defmodule Rfile.Mixfile do
use Mix.Project
def project do
[
app: :rfile,
version: "0.2.0",
elixir: "~> 1.2",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps(),
aliases: aliases()
]
end
def application do
[
applications: [:lager, :erlcloud],
env: [],
mod: {:rfile_app, []}
]
end
defp deps do
[
{:lager, "~> 3.6.1"},
{:bucs, git: "git://github.com/G-Corp/bucs.git", branch: "master"},
{:doteki, git: "git://github.com/G-Corp/doteki.git", branch: "master"},
{:erlcloud, "~> 3.1.4"}
]
end
defp aliases do
[compile: &compile_with_hooks/1]
end
defp compile_with_hooks(args) do
pre_compile_hooks()
result = Mix.Task.run("compile", args)
post_compile_hooks()
result
end
defp pre_compile_hooks() do
run_hook_cmd [
]
end
defp post_compile_hooks() do
run_hook_cmd [
]
end
defp run_hook_cmd(commands) do
{_, os} = :os.type
for command <- commands, do: (fn
({regex, cmd}) ->
if Regex.match?(Regex.compile!(regex), Atom.to_string(os)) do
Mix.Shell.cmd cmd, [], fn(x) -> Mix.Shell.IO.info(trim(x)) end
end
(cmd) ->
Mix.Shell.cmd cmd, [], fn(x) -> Mix.Shell.IO.info(trim(x)) end
end).(command)
end
defp trim(x) do
if Version.compare(System.version, "1.5.0") == :lt do
Kernel.apply(String, :strip, [x])
else
Kernel.apply(String, :trim, [x])
end
end
end | 22.623377 | 77 | 0.578071 |
f721ff74d8927ce6e9f7dce424d777426f3957c9 | 1,946 | ex | Elixir | clients/content/lib/google_api/content/v21/model/accountstatuses_custom_batch_response.ex | medikent/elixir-google-api | 98a83d4f7bfaeac15b67b04548711bb7e49f9490 | [
"Apache-2.0"
] | null | null | null | clients/content/lib/google_api/content/v21/model/accountstatuses_custom_batch_response.ex | medikent/elixir-google-api | 98a83d4f7bfaeac15b67b04548711bb7e49f9490 | [
"Apache-2.0"
] | null | null | null | clients/content/lib/google_api/content/v21/model/accountstatuses_custom_batch_response.ex | medikent/elixir-google-api | 98a83d4f7bfaeac15b67b04548711bb7e49f9490 | [
"Apache-2.0"
] | 1 | 2020-10-04T10:12:44.000Z | 2020-10-04T10:12:44.000Z | # Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# NOTE: This file is auto generated by the elixir code generator program.
# Do not edit this file manually.
defmodule GoogleApi.Content.V21.Model.AccountstatusesCustomBatchResponse do
@moduledoc """
## Attributes
* `entries` (*type:* `list(GoogleApi.Content.V21.Model.AccountstatusesCustomBatchResponseEntry.t)`, *default:* `nil`) - The result of the execution of the batch requests.
* `kind` (*type:* `String.t`, *default:* `content#accountstatusesCustomBatchResponse`) - Identifies what kind of resource this is. Value: the fixed string "content#accountstatusesCustomBatchResponse".
"""
use GoogleApi.Gax.ModelBase
@type t :: %__MODULE__{
:entries =>
list(GoogleApi.Content.V21.Model.AccountstatusesCustomBatchResponseEntry.t()),
:kind => String.t()
}
field(:entries,
as: GoogleApi.Content.V21.Model.AccountstatusesCustomBatchResponseEntry,
type: :list
)
field(:kind)
end
defimpl Poison.Decoder, for: GoogleApi.Content.V21.Model.AccountstatusesCustomBatchResponse do
def decode(value, options) do
GoogleApi.Content.V21.Model.AccountstatusesCustomBatchResponse.decode(value, options)
end
end
defimpl Poison.Encoder, for: GoogleApi.Content.V21.Model.AccountstatusesCustomBatchResponse do
def encode(value, options) do
GoogleApi.Gax.ModelBase.encode(value, options)
end
end
| 35.381818 | 204 | 0.748715 |
f7220447845044e70d7e05d3aa0918311a0620ab | 345 | ex | Elixir | lib/stixex/vocabulary/threat_actor_label.ex | FloatingGhost/stixex | c3b012d0e8596fde6bd512f856f05b0187bb5273 | [
"MIT"
] | 1 | 2019-05-07T22:44:45.000Z | 2019-05-07T22:44:45.000Z | lib/stixex/vocabulary/threat_actor_label.ex | FloatingGhost/stixex | c3b012d0e8596fde6bd512f856f05b0187bb5273 | [
"MIT"
] | null | null | null | lib/stixex/vocabulary/threat_actor_label.ex | FloatingGhost/stixex | c3b012d0e8596fde6bd512f856f05b0187bb5273 | [
"MIT"
] | null | null | null | defmodule StixEx.Vocabulary.ThreatActorLabel do
@behaviour StixEx.Vocabulary
@impl StixEx.Vocabulary
def values do
~w[
activist
competitor
crime-syndicate
criminal
hacker
insider-accidental
insider-disgruntled
nation-state
sensationalist
spy
terrorist
]
end
end
| 16.428571 | 47 | 0.649275 |
f7221ec3eb41628ba791130e1a7b351f317f05c5 | 1,886 | ex | Elixir | lib/nostrum/shard/intents.ex | mckethanor/nostrum | 13a3927c872c1540266e9f1ba4bcad4182baa9bf | [
"MIT"
] | null | null | null | lib/nostrum/shard/intents.ex | mckethanor/nostrum | 13a3927c872c1540266e9f1ba4bcad4182baa9bf | [
"MIT"
] | null | null | null | lib/nostrum/shard/intents.ex | mckethanor/nostrum | 13a3927c872c1540266e9f1ba4bcad4182baa9bf | [
"MIT"
] | null | null | null | defmodule Nostrum.Shard.Intents do
@moduledoc false
import Bitwise
@privileged_intents [
:guild_members,
:guild_presences,
:message_content
]
@spec intent_values :: [{atom, integer()}, ...]
def intent_values do
[
guilds: 1 <<< 0,
guild_members: 1 <<< 1,
guild_bans: 1 <<< 2,
guild_emojis: 1 <<< 3,
guild_integrations: 1 <<< 4,
guild_webhooks: 1 <<< 5,
guild_invites: 1 <<< 6,
guild_voice_states: 1 <<< 7,
guild_presences: 1 <<< 8,
guild_messages: 1 <<< 9,
guild_message_reactions: 1 <<< 10,
guild_message_typing: 1 <<< 11,
direct_messages: 1 <<< 12,
direct_message_reactions: 1 <<< 13,
direct_message_typing: 1 <<< 14,
message_content: 1 <<< 15,
guild_scheduled_events: 1 <<< 16
]
end
@spec get_enabled_intents :: integer()
def get_enabled_intents do
# If no intents are passed in config, default to non-privileged being enabled.
enabled_intents = Application.get_env(:nostrum, :gateway_intents, :nonprivileged)
case enabled_intents do
:all ->
get_intent_value(Keyword.keys(intent_values()))
:nonprivileged ->
get_intent_value(Keyword.keys(intent_values()) -- @privileged_intents)
intents ->
get_intent_value(intents)
end
end
@spec get_intent_value([atom()]) :: integer
def get_intent_value(enabled_intents) do
Enum.reduce(enabled_intents, 0, fn intent, intents ->
case intent_values()[intent] do
nil -> raise "Invalid intent specified: #{intent}"
value -> intents ||| value
end
end)
end
@spec has_intent?(atom()) :: boolean
def has_intent?(requested_intent) do
enabled_integer = get_enabled_intents()
intent_integer = intent_values()[requested_intent]
(enabled_integer &&& intent_integer) == intent_integer
end
end
| 26.942857 | 85 | 0.64316 |
f722656c665062eabf00133c379a895531920a40 | 1,810 | exs | Elixir | mix.exs | qilongxu/tz_world | 010ffae5846006d27fbf613855fb58ee6a40ad33 | [
"MIT"
] | null | null | null | mix.exs | qilongxu/tz_world | 010ffae5846006d27fbf613855fb58ee6a40ad33 | [
"MIT"
] | null | null | null | mix.exs | qilongxu/tz_world | 010ffae5846006d27fbf613855fb58ee6a40ad33 | [
"MIT"
] | null | null | null | defmodule TzWorld.Mixfile do
use Mix.Project
@version "0.4.0"
def project do
[
app: :tz_world,
name: "TzWord",
version: @version,
elixir: "~> 1.6",
start_permanent: Mix.env() == :prod,
deps: deps(),
docs: docs(),
source_url: "https://github.com/kimlai/tz_world",
description: description(),
package: package(),
dialyzer: [
plt_add_apps: ~w(mix inets jason)a
]
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:geo, "~> 1.0 or ~> 2.0 or ~> 3.0"},
{:jason, "~> 1.0"},
{:ex_doc, "~> 0.19", only: :dev, runtime: false},
{:dialyxir, "~> 1.0.0-rc", only: :dev, runtime: false, optional: true},
{:benchee, "~> 1.0", only: :dev, runtime: false}
]
end
defp description do
"""
Resolve timezone names from a location.
"""
end
defp package do
[
licenses: ["MIT"],
links: links(),
maintainers: ["Kim Laï Trinh", "Kip Cole"],
files: [
"lib",
"config",
"mix.exs",
"README*",
"CHANGELOG*",
"LICENSE*"
]
]
end
def links do
%{
"GitHub" => "https://github.com/kimlai/tz_world",
"Readme" => "https://github.com/kimlai/tz_world/blob/v#{@version}/README.md",
"Changelog" => "https://github.com/kimlai/tz_world/blob/v#{@version}/CHANGELOG.md"
}
end
def docs do
[
source_ref: "v#{@version}",
main: "readme",
extras: [
"README.md",
"LICENSE.md",
"CHANGELOG.md"
],
skip_undefined_reference_warnings_on: ["changelog"]
]
end
end
| 21.294118 | 88 | 0.529282 |
f722c5e4b91305b8d795d8659f1b35cc24afc882 | 455 | ex | Elixir | lib/bot/commands/del.ex | iGalaxyYT/lanyard | ff9beca4cae2030bea97b9268fa0598465dbb10c | [
"MIT"
] | null | null | null | lib/bot/commands/del.ex | iGalaxyYT/lanyard | ff9beca4cae2030bea97b9268fa0598465dbb10c | [
"MIT"
] | null | null | null | lib/bot/commands/del.ex | iGalaxyYT/lanyard | ff9beca4cae2030bea97b9268fa0598465dbb10c | [
"MIT"
] | null | null | null | defmodule Lanyard.DiscordBot.Commands.Del do
alias Lanyard.DiscordBot.DiscordApi
def handle([key], payload) do
Lanyard.KV.Interface.del(payload["author"]["id"], key)
DiscordApi.send_message(payload["channel_id"], ":white_check_mark: Deleted key: `#{key}`")
end
def handle(_, payload) do
DiscordApi.send_message(
payload["channel_id"],
"Invalid usage. Example `del` command usage:\n`.del <key>`"
)
:ok
end
end
| 23.947368 | 94 | 0.679121 |
f722c6765ec2f3b776baaa3121d9ef1ef896f640 | 2,868 | exs | Elixir | test/arango/utils_test.exs | mpoeter/arangoex | 161ed0223f4e75ca47ca921660f162d01fdab863 | [
"Apache-2.0"
] | null | null | null | test/arango/utils_test.exs | mpoeter/arangoex | 161ed0223f4e75ca47ca921660f162d01fdab863 | [
"Apache-2.0"
] | null | null | null | test/arango/utils_test.exs | mpoeter/arangoex | 161ed0223f4e75ca47ca921660f162d01fdab863 | [
"Apache-2.0"
] | 3 | 2018-03-27T09:47:04.000Z | 2019-11-04T22:41:46.000Z | defmodule UtilsTest do
use ExUnit.Case
doctest Arango
alias Arango.Utils
test "opts_to_headers" do
assert %{} = Utils.opts_to_headers([], [])
assert %{} = Utils.opts_to_headers([], [:foo])
assert %{"Foo" => 1} = Utils.opts_to_headers([foo: 1], [:foo, :bar, :baz])
assert %{"Foo" => 1, "Bar" => 2, "Baz" => 3} = Utils.opts_to_headers([foo: 1, bar: 2, baz: 3], [:foo, :bar, :baz])
assert %{"Foo" => 1, "Bingo-Boo" => 2} = Utils.opts_to_headers([foo: 1, bingo_boo: 2], [:foo, :bingo_boo])
assert %{"Foo" => 1, "Bingo-Boo" => 2} = Utils.opts_to_headers([foo: 1, bingoBoo: 2], [:foo, :bingoBoo])
assert_raise RuntimeError, "unknown key: bar", fn ->
Utils.opts_to_headers([foo: 1, bar: 2, baz: 3], [:foo, :baz])
end
end
test "opts_to_query" do
assert %{} = Utils.opts_to_query([], [])
assert %{} = Utils.opts_to_query([], [:foo])
assert %{} = Utils.opts_to_query([foo: nil, bar: nil], [:foo, :bar])
assert %{"foo" => 1} = Utils.opts_to_query([foo: 1], [:foo, :bar, :baz])
assert %{"bar" => 2, "baz" => 3, "foo" => 1} = Utils.opts_to_query([foo: 1, bar: 2, baz: 3], [:foo, :bar, :baz])
assert %{"foo" => 1, "bingo_boo" => 2} = Utils.opts_to_query([foo: 1, bingo_boo: 2], [:foo, :bingo_boo])
assert %{"foo" => 1, "bingoBoo" => 2} = Utils.opts_to_query([foo: 1, bingoBoo: 2], [:foo, :bingoBoo])
assert_raise RuntimeError, "unknown key: bar", fn ->
Utils.opts_to_query([foo: 1, bar: 2, baz: 3], [:foo, :baz])
end
end
test "opts_to_vars" do
assert %{} = Utils.opts_to_vars([], [])
assert %{} = Utils.opts_to_vars([], [:foo])
assert %{} = Utils.opts_to_vars([foo: nil, bar: nil], [:foo, :bar])
assert %{"foo" => 1} = Utils.opts_to_vars([foo: 1], [:foo, :bar, :baz])
assert %{"foo" => 1, "bar" => 2, "baz" => 3} = Utils.opts_to_vars([foo: 1, bar: 2, baz: 3], [:foo, :bar, :baz])
assert_raise RuntimeError, "unknown key: bar", fn ->
Utils.opts_to_vars([foo: 1, bar: 2, baz: 3], [:foo, :baz])
end
end
test "ensure_permitted" do
assert [] = Utils.ensure_permitted([], [])
assert [] = Utils.ensure_permitted([], [:foo])
assert [] = Utils.ensure_permitted([foo: nil, bar: nil], [:foo, :bar])
assert [foo: 1] = Utils.ensure_permitted([foo: 1], [:foo, :bar, :baz])
assert [foo: 1, bar: 2, baz: 3] = Utils.ensure_permitted([foo: 1, bar: 2, baz: 3], [:foo, :bar, :baz])
assert_raise RuntimeError, "unknown key: bar", fn ->
Utils.ensure_permitted([foo: 1, bar: 2, baz: 3], [:foo, :baz])
end
end
test "to_header_name" do
assert "One" = Utils.to_header_name(:one)
assert "One-Two" = Utils.to_header_name(:one_two)
assert "One-Two-Three" = Utils.to_header_name(:one_two_three)
assert "One-Two" = Utils.to_header_name(:oneTwo)
assert "One-Two-Three" = Utils.to_header_name(:oneTwoThree)
end
end
| 46.258065 | 118 | 0.589609 |
f722f8209c1bcfcbaf2048ffbabaeb52b2f6d2cf | 376 | ex | Elixir | web/views/error_view.ex | voidlock/ssl_bench | 49dcea2ea8596cfcc7073df90d42536c168351c3 | [
"MIT"
] | null | null | null | web/views/error_view.ex | voidlock/ssl_bench | 49dcea2ea8596cfcc7073df90d42536c168351c3 | [
"MIT"
] | null | null | null | web/views/error_view.ex | voidlock/ssl_bench | 49dcea2ea8596cfcc7073df90d42536c168351c3 | [
"MIT"
] | null | null | null | defmodule SslBench.ErrorView do
use SslBench.Web, :view
def render("404.html", _assigns) do
"Page not found"
end
def render("500.html", _assigns) do
"Server internal error"
end
# In case no render clause matches or no
# template is found, let's render it as 500
def template_not_found(_template, assigns) do
render "500.html", assigns
end
end
| 20.888889 | 47 | 0.699468 |
f72327a8fbde64876a4fcfaf28be4890a8156207 | 1,140 | ex | Elixir | installer/lib/mix/tasks/still.new.ex | fmterrorf/still | fd316bcc38cdf618444dbd36ec9d259fe5256a3e | [
"0BSD"
] | 2 | 2021-02-15T07:55:38.000Z | 2021-03-05T18:04:53.000Z | installer/lib/mix/tasks/still.new.ex | mrmicahcooper/still | ba785b0b068d998d0343f73a1fd1795edbe9831c | [
"0BSD"
] | null | null | null | installer/lib/mix/tasks/still.new.ex | mrmicahcooper/still | ba785b0b068d998d0343f73a1fd1795edbe9831c | [
"0BSD"
] | 1 | 2021-04-14T16:12:32.000Z | 2021-04-14T16:12:32.000Z | defmodule Mix.Tasks.Still.New do
@moduledoc """
Creates a new Still project.
Expects the project name as an argument.
mix still.new my_site [--path PATH] [--module MODULE]
## Options
* `--path` - path where the project should be created.
* `--module` - name of the base module to be generated.
"""
use Mix.Task
@arg_types [
path: :string,
module: :string
]
alias Still.New.{Generator, Project}
@doc false
def run(args) do
case parse_opts(args) do
{nil, []} ->
Mix.Tasks.Help.run(["still.new"])
{name, opts} ->
Project.new([{:name, name} | opts])
|> Generator.run()
end
end
defp parse_opts(args) do
case OptionParser.parse(args, strict: @arg_types) do
{opts, [name], []} ->
{name, opts}
{_, [], []} ->
{nil, []}
{_, args, []} ->
Mix.raise("Invalid project name: #{Enum.join(args, " ")}")
{_opts, _args, [{arg, nil} | _]} ->
Mix.raise("Invalid argument: #{arg}")
{_opts, _args, [{arg, value} | _]} ->
Mix.raise("Invalid argument: #{arg}=#{value}")
end
end
end
| 20.727273 | 66 | 0.547368 |
f72334e5a71b316871b3e5921a16639f75c757ff | 339 | exs | Elixir | apps/artemis/priv/repo/migrations/20200514130559_add_value_number_and_value_percent_to_event_answers.exs | artemis-platform/artemis_teams | 9930c3d9528e37b76f0525390e32b66eed7eadde | [
"MIT"
] | 2 | 2020-04-23T02:29:18.000Z | 2020-07-07T13:13:17.000Z | apps/artemis/priv/repo/migrations/20200514130559_add_value_number_and_value_percent_to_event_answers.exs | chrislaskey/artemis_teams | 9930c3d9528e37b76f0525390e32b66eed7eadde | [
"MIT"
] | 4 | 2020-04-26T20:35:36.000Z | 2020-11-10T22:13:19.000Z | apps/artemis/priv/repo/migrations/20200514130559_add_value_number_and_value_percent_to_event_answers.exs | chrislaskey/artemis_teams | 9930c3d9528e37b76f0525390e32b66eed7eadde | [
"MIT"
] | null | null | null | defmodule Artemis.Repo.Migrations.AddValueNumberAndValuePercentToEventAnswers do
use Ecto.Migration
def change do
alter table(:event_answers) do
add :value_number, :numeric
add :value_percent, :integer
end
create index(:event_answers, :value_number)
create index(:event_answers, :value_percent)
end
end
| 24.214286 | 80 | 0.749263 |