Rails 有给所有 model 自动生成类型标注的插件吗?

gaicitadie · May 11, 2019 · Last by gaicitadie replied at May 13, 2019 · 1781 hits

就是根据 schema.rb,自动在每个 model 上面加上注释,为 model 的每个字段标注上类型,这在 IDE 的自动完成非常重要。

Reply to qichunren

对,就是类似这种,不过它生成的注释貌似 RubyMine 识别不了

# == Schema Info
#
# Table name: line_items
#
#  id                  :integer(11)    not null, primary key
#  quantity            :integer(11)    not null
#  product_id          :integer(11)    not null
#  unit_price          :float
#  order_id            :integer(11)
#

 class LineItem < ActiveRecord::Base
   belongs_to :product
  . . .

其实我要生成注释不是给人读的,是给 IDE 读的,希望能通过注释准确获取 model 对象的属性。

IDE 可以读 schema.rb。

Reply to Rei

无奈 ruby 太魔幻,rubymine 经常读不到,或者张冠李戴,读不准。

这是比较头疼的地方,用 laravel 框架和 phostorm,装上生成 doc type 的插件,基本上自动完成能达到 95% 的准确度,接近静态语言。rails 这方面还是有些欠缺,可能是 rails 社区用 ide 的不多,jetbrains 官方对 rubymine 的 type hint 支持也不如 phpstorm。

Reply to gaicitadie

ruby 啥都好,就是这点特别让人不舒服。前段时间,想看看 ActiveSupport 的一些源码,还特意试了下 RubyMine,两天后果断卸载,ctrl + b 给我查出来一堆无关的东西,太干扰思路了,还是老实 source_location 慢慢来算了。话说,有没有适合的 gem 定位方法源码的😂 😂 😂

头像 oracle 律师函警告。。

Reply to pynix

我这头像是 QAQ 三个字母来的 --_--

怎么看着是 oRACle 被截断了。。。

白底红字,颜色已经侵权 oracle 了😏

You need to Sign in before reply, if you don't have an account, please Sign up first.