Skip to content

Commit 3abb06f

Browse files
replace Module.eval_quoted/4 with Code.eval_quoted/3
1 parent 9711baa commit 3abb06f

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

lib/exprotobuf/builder.ex

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
defmodule Protobuf.Builder do
22
@moduledoc false
33

4-
alias Protobuf.Config
5-
64
import Protobuf.DefineEnum, only: [def_enum: 3]
75
import Protobuf.DefineMessage, only: [def_message: 3]
86

7+
alias Protobuf.Config
8+
99
def define(msgs, %Config{inject: inject} = config) do
1010
# When injecting, use_in is not available, so we don't need to use @before_compile
1111
if inject do
1212
quote location: :keep do
13-
Module.register_attribute(__MODULE__, :use_in, accumulate: true)
1413
import unquote(__MODULE__), only: [use_in: 2]
1514

15+
Module.register_attribute(__MODULE__, :use_in, accumulate: true)
16+
1617
unless is_nil(unquote(config.from_file)) do
1718
case unquote(config.from_file) do
1819
file when is_binary(file) ->
@@ -28,13 +29,14 @@ defmodule Protobuf.Builder do
2829
@config unquote(Macro.escape(Map.to_list(%{config | :schema => nil})))
2930
@msgs unquote(Macro.escape(msgs))
3031
contents = unquote(__MODULE__).generate(@msgs, @config)
31-
Module.eval_quoted(__MODULE__, contents, [], __ENV__)
32+
Code.eval_quoted(contents, [], __ENV__)
3233
end
3334
else
3435
quote do
35-
Module.register_attribute(__MODULE__, :use_in, accumulate: true)
3636
import unquote(__MODULE__), only: [use_in: 2]
3737

38+
Module.register_attribute(__MODULE__, :use_in, accumulate: true)
39+
3840
unless is_nil(unquote(config.from_file)) do
3941
case unquote(config.from_file) do
4042
file when is_binary(file) ->
@@ -57,7 +59,7 @@ defmodule Protobuf.Builder do
5759
defmacro __before_compile__(_env) do
5860
quote location: :keep do
5961
contents = unquote(__MODULE__).generate(@msgs, @config)
60-
Module.eval_quoted(__MODULE__, contents, [], __ENV__)
62+
Code.eval_quoted(contents, [], __ENV__)
6163
end
6264
end
6365

@@ -83,12 +85,13 @@ defmodule Protobuf.Builder do
8385
item_type in [:msg, :proto3_msg, :enum],
8486
into: [] do
8587
if only != [] do
86-
is_child? =
87-
Enum.any?(only, fn o ->
88+
is_child? =
89+
Enum.any?(only, fn o ->
8890
o != item_name and is_child_type?(item_name, o)
8991
end)
90-
92+
9193
last_mod = last_module(item_name)
94+
9295
if last_mod in only or is_child? do
9396
case item_type do
9497
:msg when is_child? ->

lib/exprotobuf/decoder.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
defmodule Protobuf.Decoder do
22
@moduledoc false
3-
use Bitwise, only_operators: true
3+
import Bitwise
44

55
alias Protobuf.Field
66
alias Protobuf.OneOfField

lib/exprotobuf/define_message.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ defmodule Protobuf.DefineMessage do
22
@moduledoc false
33

44
alias Protobuf.Decoder
5+
alias Protobuf.Delimited
56
alias Protobuf.Encoder
67
alias Protobuf.Field
78
alias Protobuf.OneOfField
8-
alias Protobuf.Delimited
99
alias Protobuf.Utils
1010

1111
def def_message(name, fields, inject: inject, doc: doc, syntax: syntax) when is_list(fields) do
@@ -61,7 +61,7 @@ defmodule Protobuf.DefineMessage do
6161
unquote(constructors(name))
6262

6363
if use_in != nil do
64-
Module.eval_quoted(__MODULE__, use_in, [], __ENV__)
64+
Code.eval_quoted(use_in, [], __ENV__)
6565
end
6666

6767
defimpl Protobuf.Serializable do
@@ -76,7 +76,7 @@ defmodule Protobuf.DefineMessage do
7676

7777
defp constructors(name) do
7878
quote location: :keep do
79-
def new(), do: new([])
79+
def new, do: new([])
8080

8181
def new(values) do
8282
struct(unquote(name), values)

0 commit comments

Comments
 (0)