【发布时间】:2015-07-29 02:05:40
【问题描述】:
annotate gem 的自述文件提到了由特定 gem 生成的模型、固定装置、规格和文件,但没有提到演示者。
有没有办法让annotate给presenters添加注解?
【问题讨论】:
annotate gem 的自述文件提到了由特定 gem 生成的模型、固定装置、规格和文件,但没有提到演示者。
有没有办法让annotate给presenters添加注解?
【问题讨论】:
似乎没有一种 gem 支持的方法可以将模型注释添加到其他类型的环绕模型的类,如演示者、装饰者和展示者。但是,由于 gem 中几乎所有的主要代码都在一个文件中(lib/annotate/annotate_models.rb),你可以bundle open annotate 并在它上面修改以获得你想要的东西,假设你不介意一点猴子补丁.例如,假设您的演示者在app/presenters,您可以直接对文件进行以下类型的编辑:
module AnnotateModels
# Towards the top of the file where all the directory
# declarations are...
PRESENTER_DIR = File.join("app", "presenters")
PRESENTER_TEST_DIR = File.join("test", "presenters")
PRESENTER_SPEC_DIR = File.join("spec", "presenters")
PRESENTER_PATTERNS = [
File.join(PRESENTER_DIR, "%MODEL_NAME%_presenter.rb"),
File.join(PRESENTER_TEST_DIR, "%MODEL_NAME%_presenter_test.rb"),
File.join(PRESENTER_SPEC_DIR, "%MODEL_NAME%_presenter_spec.rb"),
]
# ...
def annotate
# ...
# add in presenters to the list of file types that require annotations
%w(test fixture factory serializer presenter).each do |key|
# ...
end
end
def remove_annotations
# ...
# add presenter files to list needing annotation removal
(TEST_PATTERNS + FIXTURE_PATTERNS + FACTORY_PATTERNS + SERIALIZER_PATTERNS + PRESENTER_PATTERNS).map { ... }
end
# ...
end
当然不是一个优雅的解决方案,但如果这种更改适合您,您可以考虑分叉 gem 并将任何更改移到那里,或者甚至可以将拉取请求提交回 gem。查看 annotate gem 问题跟踪器,似乎没有任何关于向可以注释的文件类型添加演示者或装饰器的功能请求或讨论。
【讨论】: