Module: SimpleMigrator::Migratable

Defined in:
lib/simple_migrator/migratable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



31
32
33
# File 'lib/simple_migrator/migratable.rb', line 31

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#migrate!(_migrator = migrator) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/simple_migrator/migratable.rb', line 3

def migrate!(_migrator = migrator)
  self.class.migrations.each do |migration|
    rebound_proc = rebind_proc(migration.proc)
    name = prefixed_migration_name(migration.name)
    _migrator.migrate(name, &rebound_proc)
  end
end

#migration_prefixObject



19
# File 'lib/simple_migrator/migratable.rb', line 19

def migration_prefix; end

#migratorObject

Raises:

  • (NoMigratorError)


21
22
23
# File 'lib/simple_migrator/migratable.rb', line 21

def migrator
  raise NoMigratorError, "`migrate!` called without a migrator.\nEither provide a migrator or define a `migrator` method"
end

#prefixed_migration_name(name) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/simple_migrator/migratable.rb', line 11

def prefixed_migration_name(name)
  if migration_prefix
    [migration_prefix, name].join("_")
  else
    name
  end
end

#rebind_proc(proc) ⇒ Object



25
26
27
28
29
# File 'lib/simple_migrator/migratable.rb', line 25

def rebind_proc(proc)5
  Proc.new do |db|
    instance_exec(db, &proc)
  end
end