class MinceMigrator::Migrations::Loader

Public Class Methods

new(options) click to toggle source
# File lib/mince_migrator/migrations/loader.rb, line 4
def initialize(options)
  @klass_name = options[:klass_name]
  @full_path = options[:full_path]
end

Public Instance Methods

call() click to toggle source
# File lib/mince_migrator/migrations/loader.rb, line 13
def call
  if valid?
    require @full_path
    perform_post_load_validations
  end
end
klass() click to toggle source
# File lib/mince_migrator/migrations/loader.rb, line 9
def klass
  eval "::MinceMigrator::Migrations::#{@klass_name}"
end
valid?() click to toggle source
# File lib/mince_migrator/migrations/loader.rb, line 20
def valid?
  file_exists?
end

Private Instance Methods

file_exists?() click to toggle source
# File lib/mince_migrator/migrations/loader.rb, line 46
def file_exists?
  raise 'migration does not exist' unless ::File.exists?(@full_path)
  true
end
has_all_interfaces?() click to toggle source
# File lib/mince_migrator/migrations/loader.rb, line 42
def has_all_interfaces?
  %w(run revert time_created).all?{|a| klass.respond_to?(a) }
end
has_valid_interface?() click to toggle source
# File lib/mince_migrator/migrations/loader.rb, line 36
def has_valid_interface?
  if !has_all_interfaces?
    raise "migration does not have all required methods (:run, :revert, and :time_created)"
  end
end
mince_migration?() click to toggle source
# File lib/mince_migrator/migrations/loader.rb, line 30
def mince_migration?
  klass # Check that constant is valid and loaded
rescue NameError
  raise 'invalid migration'
end
perform_post_load_validations() click to toggle source
# File lib/mince_migrator/migrations/loader.rb, line 26
def perform_post_load_validations
  mince_migration? && has_valid_interface?
end