在Ecto.Repo.Supervisor
中发现了这一点,我想知道__info__/1
的其他选项记录在哪里:
def compile_config(repo, opts) do
# (...)
behaviours =
for {:behaviour, behaviours} <- adapter.__info__(:attributes),
behaviour <- behaviours,
do: behaviour
# (...)
end
编译模块后,使用此模块中的许多功能 将引发错误,因为检查运行时不在其范围内 数据。大部分运行时数据都可以通过
__info__/1
进行检查 函数附加到每个已编译模块。
答案 0 :(得分:0)
在Module
's source中找到它:
@doc """
Provides runtime information about functions and macros defined by the
module, etc.
Each module gets an `__info__/1` function when it's compiled. The function
takes one of the following atoms:
* `:functions` - keyword list of public functions along with their arities
* `:macros` - keyword list of public macros along with their arities
* `:module` - the module atom name
* `:md5` - the MD5 of the module
* `:compile` - a list with compiler metadata
* `:attributes` - a list with all persisted attributes
"""
def __info__(kind)
:deprecated
-显示模块中以@deprecated
属性(包含在1.7.0-rc.0
中为前缀)中不推荐使用的功能
在Phoenix项目中尝试上面的behaviour =
以上代码段:
$ iex -S mix phx.server
iex(3)> Ecto.Adapters.Postgres.__info__(:attributes)
[
vsn: [168581197275628950002173003256895919063],
behaviour: [Ecto.Adapter],
behaviour: [Ecto.Adapter.Migration],
behaviour: [Ecto.Adapter.Queryable],
behaviour: [Ecto.Adapter.Schema],
behaviour: [Ecto.Adapter.Transaction],
behaviour: [Ecto.Adapter.Storage],
behaviour: [Ecto.Adapter.Structure]
]
iex(4)> for {:behaviour, behaviours} <-
...(4)> Ecto.Adapters.Postgres.__info__(:attributes),
...(4)> behaviour <- behaviours,
...(4)> do: behaviour
[Ecto.Adapter, Ecto.Adapter.Migration, Ecto.Adapter.Queryable,
Ecto.Adapter.Schema, Ecto.Adapter.Transaction, Ecto.Adapter.Storage,
Ecto.Adapter.Structure]