Class: FedoraMigrate::MigrationReport

Inherits:
Object
  • Object
show all
Defined in:
lib/fedora_migrate/migration_report.rb

Constant Summary collapse

DEFAULT_PATH =
"migration_report".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ MigrationReport

Returns a new instance of MigrationReport.



7
8
9
10
11
# File 'lib/fedora_migrate/migration_report.rb', line 7

def initialize(path = nil)
  @path = path.nil? ? DEFAULT_PATH : path
  FileUtils.mkdir_p(@path)
  reload
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



3
4
5
# File 'lib/fedora_migrate/migration_report.rb', line 3

def path
  @path
end

#resultsObject

Returns the value of attribute results.



3
4
5
# File 'lib/fedora_migrate/migration_report.rb', line 3

def results
  @results
end

Instance Method Details

#failed_objectsObject



19
20
21
# File 'lib/fedora_migrate/migration_report.rb', line 19

def failed_objects
  results.keys.map { |k| k unless results[k]["status"] }.compact
end

#failuresObject



23
24
25
# File 'lib/fedora_migrate/migration_report.rb', line 23

def failures
  failed_objects.count
end

#reloadObject



13
14
15
# File 'lib/fedora_migrate/migration_report.rb', line 13

def reload
  @results = load_results_from_directory
end

#report_failures(output = '') ⇒ Object



31
32
33
34
35
36
# File 'lib/fedora_migrate/migration_report.rb', line 31

def report_failures(output = '')
  failed_objects.each do |k|
    output << "#{k}:\n\tobject: #{results[k]['object']}\n\trelationships: #{results[k]['relationships']}\n\n"
  end
  output
end

#save(pid, report) ⇒ Object

Receives and individual report and writes it to the MigrationReport directory



39
40
41
42
43
# File 'lib/fedora_migrate/migration_report.rb', line 39

def save(pid, report)
  file = File.join(path, file_from_pid(pid))
  json = JSON.load(report.to_json)
  File.write(file, JSON.pretty_generate(json))
end

#total_objectsObject



27
28
29
# File 'lib/fedora_migrate/migration_report.rb', line 27

def total_objects
  results.keys.count
end