Skip to content

Commit 98ade3b

Browse files
committed
Convert project stack to records
1 parent dc5fe48 commit 98ade3b

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

lib/mix/lib/mix/project.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ defmodule Mix.Project do
3131
defined.
3232
"""
3333

34+
alias Mix.Server.Project
35+
3436
@doc false
3537
defmacro __using__(_) do
3638
quote do
@@ -85,7 +87,7 @@ defmodule Mix.Project do
8587
"""
8688
def get do
8789
case Mix.Server.call(:projects) do
88-
[{ h, _ }|_] -> h
90+
[Project[name: project]|_] -> project
8991
_ -> nil
9092
end
9193
end
@@ -103,7 +105,7 @@ defmodule Mix.Project do
103105
"""
104106
def config do
105107
case Mix.Server.call(:projects) do
106-
[{ h, config }|_] when h != nil -> config
108+
[Project[name: name, config: config]|_] when name != nil -> config
107109
_ -> default_config
108110
end
109111
end

lib/mix/lib/mix/server.ex

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ defmodule Mix.Server do
88
shell: Mix.Shell.IO, scm: Ordset.new, env: nil, post_config: [],
99
io_done: false
1010

11+
defrecord Project, name: nil, config: nil
12+
1113
def start_link(env) do
1214
:gen_server.start_link({ :local, __MODULE__ }, __MODULE__, env, [])
1315
end
@@ -56,7 +58,7 @@ defmodule Mix.Server do
5658

5759
def handle_call(:pop_project, _from, config) do
5860
case config.projects do
59-
[{ project, _ }|tail] ->
61+
[ Project[name: project] | tail ] ->
6062
{ :reply, project, config.projects(tail).io_done(false) }
6163
_ ->
6264
{ :reply, nil, config }
@@ -106,10 +108,11 @@ defmodule Mix.Server do
106108
{ :noreply, config.update_tasks Ordset.filter(fn {t, _} -> t != task end, &1) }
107109
end
108110

109-
def handle_cast({ :push_project, name, project }, config) do
110-
project = Keyword.merge(project, config.post_config)
111+
def handle_cast({ :push_project, name, conf }, config) do
112+
conf = Keyword.merge(conf, config.post_config)
113+
project = Project[name: name, config: conf]
111114
config = config.post_config([])
112-
.update_projects([{ name, project }|&1])
115+
.update_projects([project|&1])
113116
.io_done(false)
114117
{ :noreply, config }
115118
end
@@ -136,13 +139,16 @@ defmodule Mix.Server do
136139

137140
# Returns if project is part of an umbrella project
138141
defp in_umbrella?(config) do
139-
Enum.any? config.projects, fn { _, conf } -> conf[:apps_path] != nil end
142+
Enum.any?(config.projects, fn(Project[config: conf]) ->
143+
conf[:apps_path] != nil
144+
end)
140145
end
141146

142147
# Returns if project is an umbrella project
143148
defp umbrella?(config) do
144149
case config.projects do
145-
[ { h, conf } | _ ] when h != nil -> conf[:apps_path] != nil
150+
[ Project[name: name, config: config] | _ ] when name != nil ->
151+
config[:apps_path] != nil
146152
_ -> false
147153
end
148154
end

0 commit comments

Comments
 (0)