代码之家  ›  专栏  ›  技术社区  ›  toraritte

“信息/1”记录在哪里?

  •  1
  • toraritte  · 技术社区  · 6 年前

    找到这个了吗 Ecto.Repo.Supervisor 我想知道其他的选择 __info__/1 记录如下:

      def compile_config(repo, opts) do
      # (...)
        behaviours =
          for {:behaviour, behaviours} <- adapter.__info__(:attributes),
              behaviour <- behaviours,
              do: behaviour
    
      # (...)
      end
    

    The Module documentation 只是提到了这一点

    将引发错误,因为它超出了检查运行时的范围 数据。大多数运行时数据都可以通过 附加到每个编译模块的函数。

    1 回复  |  直到 6 年前
        1
  •  0
  •   toraritte    6 年前

    我在里面找到的 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 )


    尝试上述方法 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]