Sha256: 3880f93018e8eb069078a9c79b661d87f66668956b2e8895843f5d13d264655c

Contents?: true

Size: 1.06 KB

Versions: 163

Compression:

Stored size: 1.06 KB

Contents

module Caboose

  class Version
    include Comparable
    attr_accessor :str, :migrations

    def initialize(str, migration_range)
      @str = str
      @migrations = []

      if !migration_range.nil?

        directory = File.join(File.expand_path('../../..', __FILE__), 'db/migrate')
        files = Dir.entries(directory).select{ |f| !File.directory?(f) && /[0-9]{3}_[^\n\r\.]+\.rb$/ =~ f && migration_range.include?(f[0..2].to_i) }
        files.sort.each do |f|
          require File.join(directory, f)
          /[0-9]{3}_(?<clazz_name>[^\n\r\.]+)\.rb$/ =~ f
          @migrations += [clazz_name.classify.constantize.new]
        end
      end

    end

    def to_s
      return @str
    end

    def self.compare_version_strings(a, b)
      a = a.split('.').map{|s| s.to_i}
      b = b.split('.').map{|s| s.to_i}
      return a <=> b
    end

    def <=>(other)
      return Version.compare_version_strings(@str, other.to_s)
    end

    def up(c)
      @migrations.each{|m| m.up(c)}
    end

    def down(c)
      @migrations.reverse_each{|m| m.down(c)}
    end
  end

end

Version data entries

163 entries across 163 versions & 1 rubygems

Version Path
caboose-cms-0.3.42 lib/caboose/migration_version.rb
caboose-cms-0.3.41 lib/caboose/migration_version.rb
caboose-cms-0.3.40 lib/caboose/migration_version.rb
caboose-cms-0.3.39 lib/caboose/migration_version.rb
caboose-cms-0.3.38 lib/caboose/migration_version.rb
caboose-cms-0.3.37 lib/caboose/migration_version.rb
caboose-cms-0.3.36 lib/caboose/migration_version.rb
caboose-cms-0.3.35 lib/caboose/migration_version.rb
caboose-cms-0.3.34 lib/caboose/migration_version.rb
caboose-cms-0.3.33 lib/caboose/migration_version.rb
caboose-cms-0.3.32 lib/caboose/migration_version.rb
caboose-cms-0.3.31 lib/caboose/migration_version.rb
caboose-cms-0.3.30 lib/caboose/migration_version.rb
caboose-cms-0.3.29 lib/caboose/migration_version.rb
caboose-cms-0.3.28 lib/caboose/migration_version.rb
caboose-cms-0.3.27 lib/caboose/migration_version.rb
caboose-cms-0.3.26 lib/caboose/migration_version.rb
caboose-cms-0.3.25 lib/caboose/migration_version.rb
caboose-cms-0.3.24 lib/caboose/migration_version.rb
caboose-cms-0.3.23 lib/caboose/migration_version.rb