Class: Monark::Migration

Inherits:
Object
  • Object
show all
Defined in:
lib/monark/migration.rb

Overview

A Monark migration. Acceptable formats are ‘.sql`, `.sql.erb` and `.rb`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, path, proc = nil) ⇒ Migration

Returns a new instance of Migration.



9
10
11
12
13
# File 'lib/monark/migration.rb', line 9

def initialize(root, path, proc = nil)
  self.root = Pathname(root.to_s)
  self.path = path
  @code = proc
end

Instance Attribute Details

#kindObject

Returns the value of attribute kind.



6
7
8
# File 'lib/monark/migration.rb', line 6

def kind
  @kind
end

#pathObject

Returns the value of attribute path.



6
7
8
# File 'lib/monark/migration.rb', line 6

def path
  @path
end

#reloadableObject Also known as: reloadable?

Returns the value of attribute reloadable.



6
7
8
# File 'lib/monark/migration.rb', line 6

def reloadable
  @reloadable
end

#rootObject

Returns the value of attribute root.



6
7
8
# File 'lib/monark/migration.rb', line 6

def root
  @root
end

Instance Method Details

#codeObject



15
16
17
# File 'lib/monark/migration.rb', line 15

def code
  @code ||= load_file("sql", "sql.erb", "rb")
end

#performObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/monark/migration.rb', line 19

def perform
  code
  if !kind
    puts "-> calling '#{@path}'"
    @code.call
  elsif @kind == "rb"
    puts "-> evaluating '#{@path}'"
    binding.eval(@code, path, 0)
  else
    puts "-> executing '#{@path}'"
    ActiveRecord::Base.connection.execute @code
  end
end