うまくいった

ライブラリを呼び出すための$LOAD_PATHに対してクラス名+migrationのディレクトリがあるかどうかを調べていくことで問題解決(多分)。コードはこんな感じ。

  def schema_version
    match = Regexp.new('^(\d{3,})_(.*)\.rb$')
    max = 0
    $LOAD_PATH.each do |load_path|
      path = load_path + '/' + name.underscore + '/migration'
      begin
        Dir.foreach(path) do |fname|
          if fname =~ match
            version = $1.to_i
            max = version if version > max
          end
        end
        return max
      rescue
        
      end
    end
    return 0
  end




« Prev item - Next Item »
---------------------------------------------

Comments


No comments yet. You can be the first!


Leave comment

© 2007 yoursite.com | Designed by DesignsByDarren
Ported to Nucleus CMS: Suvoroff