Class: PgMigrate::ManifestReader

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_migrate/manifest_reader.rb

Instance Method Summary collapse

Constructor Details

#initializeManifestReader

Returns a new instance of ManifestReader.



6
7
8
# File 'lib/pg_migrate/manifest_reader.rb', line 6

def initialize
  @log = Logging.logger[self]
end

Instance Method Details

#build_migration_path(manifest_path, migration_name) ⇒ Object

construct a migration file path location based on the manifest basedir and the name of the migration



34
35
36
# File 'lib/pg_migrate/manifest_reader.rb', line 34

def build_migration_path(manifest_path, migration_name)
  File.join(manifest_path, UP_DIRNAME, "#{migration_name}")
end

#hash_loaded_manifest(loaded_manifest) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/pg_migrate/manifest_reader.rb', line 38

def hash_loaded_manifest(loaded_manifest)
  hash = {}
  loaded_manifest.each do |manifest|
    hash[manifest.name] = manifest
  end
  return hash
end

#load_input_manifest(manifest_path) ⇒ Object

returns array of migration paths



11
12
13
14
# File 'lib/pg_migrate/manifest_reader.rb', line 11

def load_input_manifest(manifest_path)
  manifest, version = load_manifest(manifest_path, false)
  return manifest
end

#load_output_manifest(manifest_path) ⇒ Object

returns [array of migration paths, version]



17
18
19
# File 'lib/pg_migrate/manifest_reader.rb', line 17

def load_output_manifest(manifest_path)
  return load_manifest(manifest_path, true)
end

#validate_migration_paths(manifest_path, manifest) ⇒ Object

verify that the migration files exist



23
24
25
26
27
28
29
30
31
# File 'lib/pg_migrate/manifest_reader.rb', line 23

def validate_migration_paths(manifest_path, manifest)
  # each item in the manifest should be a valid file
  manifest.each do |item|
    item_path = build_migration_path(manifest_path, item.name)
    if !Pathname.new(item_path).exist?
      raise "manifest reference #{item.name} does not exist at path #{item_path}"
    end
  end
end