Class: XMigra::Migration

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

Constant Summary collapse

EMPTY_DB =
'empty database'
FOLLOWS =
'starting from'
CHANGES =
'changes'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(info) ⇒ Migration

Returns a new instance of Migration.



11
12
13
14
15
16
17
18
19
20
# File 'lib/xmigra/migration.rb', line 11

def initialize(info)
  @id = info['id'].dup.freeze
  _follows = info[FOLLOWS]
  @follows = (_follows.dup.freeze unless _follows == EMPTY_DB)
  @sql = info.has_key?('sql') ? info["sql"].dup.freeze : nil
  @description = info["description"].dup.freeze
  @changes = (info[CHANGES] || []).dup.freeze
  @changes.each {|c| c.freeze}
  @all_info = Marshal.load(Marshal.dump(info))
end

Instance Attribute Details

#changesObject (readonly)

Returns the value of attribute changes.



22
23
24
# File 'lib/xmigra/migration.rb', line 22

def changes
  @changes
end

#descriptionObject (readonly)

Returns the value of attribute description.



22
23
24
# File 'lib/xmigra/migration.rb', line 22

def description
  @description
end

#file_pathObject

Returns the value of attribute file_path.



23
24
25
# File 'lib/xmigra/migration.rb', line 23

def file_path
  @file_path
end

#followsObject (readonly)

Returns the value of attribute follows.



22
23
24
# File 'lib/xmigra/migration.rb', line 22

def follows
  @follows
end

#idObject (readonly)

Returns the value of attribute id.



22
23
24
# File 'lib/xmigra/migration.rb', line 22

def id
  @id
end

Class Method Details

.id_from_filename(fname) ⇒ Object



51
52
53
# File 'lib/xmigra/migration.rb', line 51

def id_from_filename(fname)
  XMigra.secure_digest(fname.upcase) # Base64 encoded digest
end

Instance Method Details

#reversionObject



45
46
47
48
# File 'lib/xmigra/migration.rb', line 45

def reversion
  result = RevertFile.new(self)
  return result if result.exist?
end

#schema_dirObject



25
26
27
28
29
30
31
32
33
# File 'lib/xmigra/migration.rb', line 25

def schema_dir
  @schema_dir ||= begin
    result = Pathname(file_path).dirname
    while result.basename.to_s != SchemaManipulator::STRUCTURE_SUBDIR
      result = result.dirname
    end
    result.join('..')
  end
end

#sqlObject



35
36
37
38
39
40
41
42
43
# File 'lib/xmigra/migration.rb', line 35

def sql
  if Plugin.active
    (@sql || "").dup.tap do |result|
      Plugin.active.amend_source_sql(result)
    end
  else
    @sql
  end
end