Class: XMigra::BranchUpgrade

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

Constant Summary collapse

TARGET_BRANCH =
"resulting branch"
MIGRATION_COMPLETED =
"completes migration to"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ BranchUpgrade

Returns a new instance of BranchUpgrade.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/xmigra/branch_upgrade.rb', line 10

def initialize(path)
  @file_path = path
  @warnings = []
  
  verinc_info = {}
  if path.exist?
    @found = true
    begin
      verinc_info = YAML.load_file(path)
    rescue Error => e
      XMigra.log_error(e)
      warning "Failed to load branch upgrade migration (#{e.class}).\n  #{e}"
      verinc_info = {}
    end
  end
  
  @base_migration = verinc_info[Migration::FOLLOWS]
  @target_branch = (XMigra.secure_digest(verinc_info[TARGET_BRANCH]) if verinc_info.has_key? TARGET_BRANCH)
  @migration_completed = verinc_info[MIGRATION_COMPLETED]
  @sql = verinc_info['sql']
end

Instance Attribute Details

#base_migrationObject (readonly)

Returns the value of attribute base_migration.



32
33
34
# File 'lib/xmigra/branch_upgrade.rb', line 32

def base_migration
  @base_migration
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



32
33
34
# File 'lib/xmigra/branch_upgrade.rb', line 32

def file_path
  @file_path
end

#migration_completedObject (readonly)

Returns the value of attribute migration_completed.



32
33
34
# File 'lib/xmigra/branch_upgrade.rb', line 32

def migration_completed
  @migration_completed
end

#target_branchObject (readonly)

Returns the value of attribute target_branch.



32
33
34
# File 'lib/xmigra/branch_upgrade.rb', line 32

def target_branch
  @target_branch
end

Instance Method Details

#applicable?(mig_chain) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'lib/xmigra/branch_upgrade.rb', line 38

def applicable?(mig_chain)
  return false if mig_chain.length < 1
  return false unless (@base_migration && @target_branch)
  
  return File.basename(mig_chain[-1].file_path) == XMigra.yaml_path(@base_migration)
end

#found?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/xmigra/branch_upgrade.rb', line 34

def found?
  @found
end

#has_warnings?Boolean

Returns:

  • (Boolean)


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

def has_warnings?
  not @warnings.empty?
end

#migration_completed_idObject



63
64
65
# File 'lib/xmigra/branch_upgrade.rb', line 63

def migration_completed_id
  Migration.id_from_filename(XMigra.yaml_path(migration_completed))
end

#sqlObject



53
54
55
56
57
58
59
60
61
# File 'lib/xmigra/branch_upgrade.rb', line 53

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

#warningsObject



49
50
51
# File 'lib/xmigra/branch_upgrade.rb', line 49

def warnings
  @warnings.dup
end