Class: XMigra::RevertFile

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

Constant Summary collapse

REVERSION_SUBDIR =
'rollback'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(migration) ⇒ RevertFile

Returns a new instance of RevertFile.



7
8
9
10
11
12
13
14
15
# File 'lib/xmigra/revert_file.rb', line 7

def initialize(migration)
  @migration = migration
  mig_path = Pathname(migration.file_path)
  @description = "REVERT #{migration.description} (#{mig_path.basename})"
  @path = migration.schema_dir.join(
    REVERSION_SUBDIR,
    mig_path.basename.to_s.sub(/\..*?$/, '.sql')
  )
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



17
18
19
# File 'lib/xmigra/revert_file.rb', line 17

def description
  @description
end

#pathObject (readonly)

Returns the value of attribute path.



17
18
19
# File 'lib/xmigra/revert_file.rb', line 17

def path
  @path
end

Instance Method Details

#exist?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/xmigra/revert_file.rb', line 38

def exist?
  @path.exist?
end

#inspectObject



31
32
33
34
35
36
# File 'lib/xmigra/revert_file.rb', line 31

def inspect
  "#<#{self.class.name} %s%s>" % [
    @path,
    (" (missing)" unless @path.exist?),
  ]
end

#to_sObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/xmigra/revert_file.rb', line 19

def to_s
  if @path.exist?
    @sql ||= "-- %s:\n\n%s\n%s" % [
      @description,
      @path.read,
      @migration.reversion_tracking_sql
    ]
  else
    "-- #@description: No reversion given\n"
  end
end