class Cassie::Schema::VersionFileLoader

Public Class Methods

new(filename) click to toggle source
# File lib/cassie/schema/version_file_loader.rb, line 6
def initialize(filename)
  @filename = filename
  @version = build_version
end

Protected Instance Methods

build_unapplied_version() click to toggle source
# File lib/cassie/schema/version_file_loader.rb, line 25
def build_unapplied_version
  matches = File.basename(filename).match(/([0-9_]+)_?(.*).rb$/).captures

  number = matches.first.tr('_','.')
  description = matches.last.try(:humanize)

  Version.new(number, description)
end
build_version() click to toggle source
# File lib/cassie/schema/version_file_loader.rb, line 13
def build_version
  unapplied_version = build_unapplied_version

  # return the applied version if it exists, since it will
  # have the full and current information about the version
  # fall back to this unapplied_version if version is not applied
  Cassie::Schema.applied_versions.find{ |v| v == unapplied_version } || unapplied_version
rescue Cassie::Schema::UninitializedError => e
  # version cannot be applied if cassie schema meta is not initialized
  unapplied_version
end