Ruby DSLs和动态文档? [英] Ruby DSLs and Dynamic Documentation?

查看:173
本文介绍了Ruby DSLs和动态文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用动态数量的参数来定义DSL,方法如下例所示:

How do you approach defining a DSL with a dynamic number of arguments being created for the method such as in the following example:

module my_module
  class Resource
    # @macro dsl_method
    # @method $1(${2--2})
    # @return [${2}] the return value of $0
    def self.property(name, type, args*) end
  end

  class Post < Resource
    property :title, String, arg1, arg2, arg3
    property :view_cout, Integer
  end
end

最终我想以语句 def self.property(name,type,(arg_name,default,type,所需的)*)。来自一个沉重的C背景我想我最好的方式,我可以描述的问题是我想输入一个动态数量的东西相当于一个结构体,并将每个动态文档记录为一个 @param 相应地包含在结构体中的值。

Ultimately I would like to define the DSL in the spirit of the statement def self.property( name, type, (arg_name, default, type, required)*). Coming from a heavy C background I guess the best way I am able describe the question is I would like to input a dynamic number of something equivalent to a struct and have each dynamically documented documented as an @param accordingly to values contained within the struct.

参考结帐 Yard宏扩展变量,并查看我的其他相关问题:

For reference checkout Yard Macro Expansion Variables and see my other related questions:

  • Iterating over the registers of a Yardoc @macro
  • How to make Yard @macros apply to multiple files
  • Dynamic documentation, using the return of method in the description of another YARD?
  • How to automatically document Metaprogrammed attr_accessors using RDoc?

推荐答案

我想在这种情况下,您需要实际生成方法代码作为字符串,将其保存在YARD的文件中阅读,您可以随后要求/加载,如果你想。

I guess that in this case, you will need to actually generate the method code as a string, save it in a file for YARD to read, which you can subsequently require/load, if you want to.

这篇关于Ruby DSLs和动态文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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