Skip to content

Commit

Permalink
Fix warnings for Elixir 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Jun 1, 2016
1 parent c43ccec commit 517ce30
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 65 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.1.5 (2016-6-01)

* Enhancements
* Fix warnings for Elixir 1.3

## 1.1.4 (2016-1-25)

* Enhancements
Expand Down
2 changes: 1 addition & 1 deletion installer/lib/phoenix_new.ex
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ defmodule Mix.Tasks.Phoenix.New do
:crypto.strong_rand_bytes(length) |> Base.encode64 |> binary_part(0, length)
end

defp phoenix_dep("deps/phoenix"), do: ~s[{:phoenix, "~> 1.1.4"}]
defp phoenix_dep("deps/phoenix"), do: ~s[{:phoenix, "~> 1.1.5"}]
# defp phoenix_dep("deps/phoenix"), do: ~s[{:phoenix, github: "phoenixframework/phoenix", override: true}]
defp phoenix_dep(path), do: ~s[{:phoenix, path: #{inspect path}, override: true}]

Expand Down
2 changes: 1 addition & 1 deletion installer/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Phoenix.New.Mixfile do

def project do
[app: :phoenix_new,
version: "1.1.4",
version: "1.1.5",
elixir: "~> 1.0-dev"]
end

Expand Down
13 changes: 9 additions & 4 deletions lib/mix/tasks/phoenix.gen.json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,8 @@ defmodule Mix.Tasks.Phoenix.Gen.Json do
{:eex, "controller.ex", "web/controllers/#{path}_controller.ex"},
{:eex, "view.ex", "web/views/#{path}_view.ex"},
{:eex, "controller_test.exs", "test/controllers/#{path}_controller_test.exs"},
]
] ++ changeset_view()

unless File.exists?("web/views/changeset_view.ex") do
files = files ++ [{:eex, "changeset_view.ex", "web/views/changeset_view.ex"}]
end

Mix.Phoenix.copy_from paths(), "priv/templates/phoenix.gen.json", "", binding, files

Expand All @@ -69,6 +66,14 @@ defmodule Mix.Tasks.Phoenix.Gen.Json do
end
end

defp changeset_view do
if File.exists?("web/views/changeset_view.ex") do
[]
else
[{:eex, "changeset_view.ex", "web/views/changeset_view.ex"}]
end
end

defp validate_args!([_, plural | _] = args) do
cond do
String.contains?(plural, ":") ->
Expand Down
14 changes: 7 additions & 7 deletions lib/mix/tasks/phoenix.gen.model.ex
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ defmodule Mix.Tasks.Phoenix.Gen.Model do
binding = Mix.Phoenix.inflect(singular)
params = Mix.Phoenix.params(attrs)
path = binding[:path]
migration = String.replace(path, "/", "_")

Mix.Phoenix.check_module_name_availability!(binding[:module])
{assocs, attrs} = partition_attrs_and_assocs(attrs)
Expand All @@ -104,12 +103,7 @@ defmodule Mix.Tasks.Phoenix.Gen.Model do
files = [
{:eex, "model.ex", "web/models/#{path}.ex"},
{:eex, "model_test.exs", "test/models/#{path}_test.exs"},
]

if opts[:migration] != false do
files =
[{:eex, "migration.exs", "priv/repo/migrations/#{timestamp()}_create_#{migration}.exs"}|files]
end
] ++ migration(opts[:migration], path)

Mix.Phoenix.copy_from paths(), "priv/templates/phoenix.gen.model", "", binding, files

Expand All @@ -125,6 +119,12 @@ defmodule Mix.Tasks.Phoenix.Gen.Model do
end
end

defp migration(false, _path), do: []
defp migration(_, path) do
[{:eex, "migration.exs",
"priv/repo/migrations/#{timestamp()}_create_#{String.replace(path, "/", "_")}.exs"}]
end

defp validate_args!([_, plural | _] = args) do
cond do
String.contains?(plural, ":") ->
Expand Down
2 changes: 1 addition & 1 deletion lib/phoenix/controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ defmodule Phoenix.Controller do
exts = parse_exts(type <> "/" <> subtype)
q = parse_q(args)

if q === 1.0 && (format = find_format(exts, accepted)) do
if format = (q === 1.0 && find_format(exts, accepted)) do
put_format(conn, format)
else
parse_header_accept(conn, t, [{-q, exts}|acc], accepted)
Expand Down
6 changes: 3 additions & 3 deletions lib/phoenix/endpoint/instrument.ex
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ defmodule Phoenix.Endpoint.Instrument do
caller = %{module: mod, function: form_fa(fun), file: file, line: line}

if app = Application.get_env(:logger, :compile_time_application) do
caller = Map.put(caller, :application, app)
Map.put(caller, :application, app)
else
caller
end

caller
end

defp form_fa({name, arity}), do: Atom.to_string(name) <> "/" <> Integer.to_string(arity)
Expand Down
14 changes: 4 additions & 10 deletions lib/phoenix/endpoint/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ defmodule Phoenix.Endpoint.Server do
end

def init({otp_app, endpoint}) do
children = []
handler = endpoint.config(:handler)

if config = endpoint.config(:http) do
config = default(config, otp_app, 4000)
children = [handler.child_spec(:http, endpoint, config)|children]
end

if config = endpoint.config(:https) do
{:ok, _} = Application.ensure_all_started(:ssl)
config = default(config, otp_app, 4040)
children = [handler.child_spec(:https, endpoint, config)|children]
children =
for {scheme, port} <- [http: 4000, https: 4040],
config = endpoint.config(scheme) do
handler.child_spec(scheme, endpoint, default(config, otp_app, port))
end

supervise(children, strategy: :one_for_one)
Expand Down
42 changes: 22 additions & 20 deletions lib/phoenix/router/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,33 @@ defmodule Phoenix.Router.Helpers do

## Helpers

defp uri_to_string(uri) do
scheme = uri.scheme

if scheme && (port = URI.default_port(scheme)) do
if uri.port == port, do: uri = %{uri | port: nil}
defp uri_to_string(%{scheme: scheme} = uri) do
if scheme do
scheme <> ":" <> authority(uri)
else
authority(uri)
end

authority = extract_authority(uri)

result = ""
if uri.scheme, do: result = result <> uri.scheme <> ":"
if authority, do: result = result <> "//" <> authority
result
end

defp extract_authority(%{host: nil, authority: authority}) do
authority
defp authority(%{host: nil, authority: nil}), do: ""
defp authority(%{host: nil, authority: authority}), do: "//" <> authority
defp authority(%{host: host, userinfo: userinfo, scheme: scheme, port: port}) do
host
|> if_value(userinfo, fn acc ->
userinfo <> "@" <> acc
end)
|> if_value(port, fn acc ->
case scheme && URI.default_port(scheme) do
^port -> acc
_ -> acc <> ":" <> Integer.to_string(port)
end
end)
|> prepend("//")
end

defp extract_authority(%{host: host, userinfo: userinfo, port: port}) do
authority = host
if userinfo, do: authority = userinfo <> "@" <> authority
if port, do: authority = authority <> ":" <> Integer.to_string(port)
authority
end
defp prepend(acc, prefix), do: prefix <> acc
defp if_value(result, nil, _fun), do: result
defp if_value(result, _value, fun), do: fun.(result)

defp build_own_forward_path(conn, router, path) do
case Map.fetch(conn.private, router) do
Expand Down
6 changes: 3 additions & 3 deletions lib/phoenix/router/scope.ex
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ defmodule Phoenix.Router.Scope do
end

def push(module, opts) when is_list(opts) do
path = Keyword.get(opts, :path)
if path, do: path = Plug.Router.Utils.split(path)
path = Keyword.get(opts, :path)
path = path && Plug.Router.Utils.split(path)

alias = Keyword.get(opts, :alias)
if alias, do: alias = Atom.to_string(alias)
alias = alias && Atom.to_string(alias)

scope = %Scope{path: path,
alias: alias,
Expand Down
2 changes: 1 addition & 1 deletion lib/phoenix/transports/websocket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ defmodule Phoenix.Transports.WebSocket do
conn =
conn
|> code_reload(opts, endpoint)
|> Plug.Conn.fetch_query_params
|> fetch_query_params()
|> Transport.transport_log(opts[:transport_log])
|> Transport.force_ssl(handler, endpoint, opts)
|> Transport.check_origin(handler, endpoint, opts)
Expand Down
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Phoenix.Mixfile do
use Mix.Project

@version "1.1.4"
@version "1.1.5"

def project do
[app: :phoenix,
Expand All @@ -14,6 +14,7 @@ defmodule Phoenix.Mixfile do
# Phoenix.Param, we need to disable consolidation
# for the test environment for Elixir v1.2 onward.
consolidate_protocols: Mix.env != :test,
xref: [exclude: [Ecto.Type]],

name: "Phoenix",
docs: [source_ref: "v#{@version}", main: "Phoenix", logo: "logo.png"],
Expand Down
20 changes: 10 additions & 10 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
%{"cowboy": {:hex, :cowboy, "1.0.4"},
"cowlib": {:hex, :cowlib, "1.0.2"},
"earmark": {:hex, :earmark, "0.1.19"},
"ex_doc": {:hex, :ex_doc, "0.11.2"},
"gettext": {:hex, :gettext, "0.8.0"},
"inch_ex": {:hex, :inch_ex, "0.2.3"},
"phoenix_html": {:hex, :phoenix_html, "1.2.0"},
"plug": {:hex, :plug, "1.0.3"},
"poison": {:hex, :poison, "1.5.0"},
"ranch": {:hex, :ranch, "1.2.0"},
%{"cowboy": {:hex, :cowboy, "1.0.4", "a324a8df9f2316c833a470d918aaf73ae894278b8aa6226ce7a9bf699388f878", [:rebar, :make], [{:cowlib, "~> 1.0.0", [hex: :cowlib, optional: false]}, {:ranch, "~> 1.0", [hex: :ranch, optional: false]}]},
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], []},
"earmark": {:hex, :earmark, "0.1.19", "ffec54f520a11b711532c23d8a52b75a74c09697062d10613fa2dbdf8a9db36e", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.11.2", "8ac82c6144a27faca6a623eeebfbf5a791bc20a54ce29a9c02e499536d253d9b", [:mix], [{:earmark, "~> 0.1.17 or ~> 0.2", [hex: :earmark, optional: true]}]},
"gettext": {:hex, :gettext, "0.8.0", "61a0fbc59d7cc4aa284e8ddd91ba96fe3f45c66a10cadc22fc0d2b2c4f0af3b2", [:mix], []},
"inch_ex": {:hex, :inch_ex, "0.2.3", "4e5050e973fd83afd69424f43d88dc833829d8910f4a7a2db3b2ed6f5c394a24", [:mix], [{:poison, "~> 1.2", [hex: :poison, optional: false]}]},
"phoenix_html": {:hex, :phoenix_html, "1.2.0", "41daafee9a5e19cbb8a74c5eae3973679d53a858aa391cf0bd48bcabab588786", [:mix], [{:plug, ">= 0.12.2 and < 2.0.0", [hex: :plug, optional: false]}]},
"plug": {:hex, :plug, "1.0.3", "8bbcbdaa4cb15170b9a15cb12153e8a6d9e176ce78e4c1990ea0b505b0ca24a0", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, optional: true]}]},
"poison": {:hex, :poison, "1.5.0", "f2f4f460623a6f154683abae34352525e1d918380267cdbd949a07ba57503248", [:mix], []},
"ranch": {:hex, :ranch, "1.2.0", "b286a948a0706a700a9f577e5cecbb2dc66097ea79f3ddb20ba5536069bdb7aa", [:make], []},
"websocket_client": {:git, "https://github.com/jeremyong/websocket_client.git", "f6892c8b55004008ce2d52be7d98b156f3e34569", []}}
5 changes: 2 additions & 3 deletions test/mix/tasks/phoenix.new_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ defmodule Mix.Tasks.Phoenix.NewTest do
in_project :photo_blog, Path.join(tmp_path, "bootstrap/photo_blog"), fn _ ->
Mix.Task.clear
Mix.Task.run "compile", ["--no-deps-check"]
assert_received {:mix_shell, :info, ["Compiled lib/photo_blog.ex"]}
assert_received {:mix_shell, :info, ["Compiled web/router.ex"]}
refute_received {:mix_shell, :info, ["Compiled lib/phoenix.ex"]}
assert_received {:mix_shell, :info, ["Generated photo_blog app"]}
refute_received {:mix_shell, :info, ["Generated phoenix app"]}
Mix.shell.flush

# Adding a new template touches file (through mix)
Expand Down

0 comments on commit 517ce30

Please sign in to comment.