是否存在续集模型生成器



我正在寻找一个可以在读取 mySQL 数据库中表的定义后为 Ramaze 生成续集模型文件的 ruby 类。例如,我想输入: ruby mySuperGenerator.rb "mytable"

结果应该是"model"目录中的文件"mytable.rb",包含:


class Mytable < Sequel::Model(:mytable)
  # All plugins I've defined somewhere before lauching the generator
  plugin :validation_helpers
  plugin :json_serializer
  one_to_many :othertable
  many_to_one :othertable2
  def validate
        # Generating this if there are some not null attributes in this table
    validates_presence [:fieldthatshoulnotbenull1, :fieldthatshoulnotbenull2]
    errors.add(:fieldthatshoulnotbenull1, 'The field fieldthatshoulnotbenull1 should not be null.') if self.fieldthatshoulnotbenull1.nil?
  end
  def before_create
    # All the default values found for each table attributes
    self.creation_time ||= Time.now
  end
  def before_destroy
    # referential integrity
    self.othertable_dataset.destroy unless self.othertable.nil?
  end
end

有人知道这样的生成器是否存在吗?

嗯...我终于写好了剧本。看到 https://github.com/Pilooz/sequel_model_generator 有外观和分叉!

最新更新