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.22 lib/caboose/migration_version.rb
caboose-cms-0.3.20 lib/caboose/migration_version.rb
caboose-cms-0.3.19 lib/caboose/migration_version.rb
caboose-cms-0.3.17 lib/caboose/migration_version.rb
caboose-cms-0.3.16 lib/caboose/migration_version.rb
caboose-cms-0.3.15 lib/caboose/migration_version.rb
caboose-cms-0.3.14 lib/caboose/migration_version.rb
caboose-cms-0.3.13 lib/caboose/migration_version.rb
caboose-cms-0.3.12 lib/caboose/migration_version.rb
caboose-cms-0.3.11 lib/caboose/migration_version.rb
caboose-cms-0.3.9 lib/caboose/migration_version.rb
caboose-cms-0.3.8 lib/caboose/migration_version.rb
caboose-cms-0.3.7 lib/caboose/migration_version.rb
caboose-cms-0.3.6 lib/caboose/migration_version.rb
caboose-cms-0.3.5 lib/caboose/migration_version.rb
caboose-cms-0.3.4 lib/caboose/migration_version.rb
caboose-cms-0.3.3 lib/caboose/migration_version.rb
caboose-cms-0.3.2 lib/caboose/migration_version.rb
caboose-cms-0.3.1 lib/caboose/migration_version.rb
caboose-cms-0.2.104 lib/caboose/migration_version.rb