【发布时间】:2016-09-14 20:56:44
【问题描述】:
我正在创建一个类似于 Rails 脚手架生成器的生成器。我想接受一组key:value 参数。像这样:
mycli generate model BlogPost title:string body:text published:datetime
目前我的命令类看起来像这样:
require "thor"
module Mycli
module Generators
class Model < Thor::Group
include Thor::Actions
argument :model_name
# argument :model_attributes # TODO: figure out how to get array of attributes
def self.source_root
File.dirname(__FILE__)
end
def generate_model
template('templates/model.tt', "app/models/#{model_name}.rb")
end
def generate_migration
template('templates/migration.tt', "migrations/#{model_name}.rb")
end
end
end
end
我需要做什么才能访问该属性列表?
【问题讨论】: