2012-04-12 4 views
0

私は、mySQLデータベースのテーブルの定義を読んだ後に、Ramazeの続編モデルファイルを生成できるrubyクラスを探しています。 例えば、私が入力したいと思います: ruby mySuperGenerator.rb "mytable" 続行モデルジェネレータは存在しますか?

をし、その結果を含む、「モデル」ディレクトリ内のファイル「mytable.rb」ことSHOLD:

 

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 
 

は、このような発電機ならば、誰かが知ってい存在するか?

答えて