__info __ / 1记录在哪里? [英] Where is `__info__/1` documented?

查看:78
本文介绍了__info __ / 1记录在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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
函数检查大多数运行时数据。

After a module is compiled, using many of the functions in this module will raise errors, since it is out of their scope to inspect runtime data. Most of the runtime data can be inspected via the __info__/1 function attached to each compiled module.


推荐答案

模块的源

 @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 属性为前缀的已弃用函数(包含在<$ c $中) c> 1.7.0-rc.0 )

Undocumented atoms

:deprecated - shows deprecated functions in a module that are prefixed with the @deprecated attribute (included in 1.7.0-rc.0)

在Phoenix项目中尝试上述行为= 以上代码段:

Trying out the above behaviour = snippet above in a Phoenix project:

$ 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]

这篇关于__info __ / 1记录在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆