Class: Converter
- Inherits:
-
Object
- Object
- Converter
- Defined in:
- backend/app/converters/converter.rb
Direct Known Subclasses
AccessionConverter, DigitalObjectConverter, EACConverter, EADConverter, MarcXMLConverter
Defined Under Namespace
Classes: ConverterMappingError, ConverterNotFound
Class Method Summary (collapse)
-
+ (Object) for(type, input_file)
-
+ (Object) inherited(subclass)
-
+ (Object) list_import_types(show_hidden = false)
List all available import types.
-
+ (Object) register_converter(subclass)
Instance Method Summary (collapse)
-
- (Object) get_output_path
-
- (Converter) initialize(input_file)
constructor
A new instance of Converter.
-
- (Object) remove_files
forcibly remove files in the event of an interruption.
Constructor Details
- (Converter) initialize(input_file)
Returns a new instance of Converter
8 9 10 11 |
# File 'backend/app/converters/converter.rb', line 8 def initialize(input_file) @input_file = input_file @batch = ASpaceImport::RecordBatch.new end |
Class Method Details
+ (Object) for(type, input_file)
74 75 76 77 78 79 80 81 |
# File 'backend/app/converters/converter.rb', line 74 def self.for(type, input_file) Array(@converters).each do |converter| converter = converter.instance_for(type, input_file) return converter if converter end raise ConverterNotFound.new("No suitable converter found for #{type}") end |
+ (Object) inherited(subclass)
[View source]
45 46 47 48 49 |
# File 'backend/app/converters/converter.rb', line 45 def self.inherited(subclass) # We name Converter explicitly so that subclasses of subclasses still get # registered at the top-most level. Converter.register_converter(subclass) end |
+ (Object) list_import_types(show_hidden = false)
List all available import types. Subclasses have the option of hiding certain import types that they actually support (for example, for suppressing imports that exist to support a plugin or user script, but shouldn’t be shown to end users)
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'backend/app/converters/converter.rb', line 56 def self.list_import_types(show_hidden = false) seen_types = {} Array(@converters).map {|converter| converter.import_types(show_hidden).map {|import| # Plugins might define their own converters that replace the standard # ones. Only show one instance of each importer. if seen_types[import[:name]] nil else seen_types[import[:name]] = true import end } }.flatten(1).compact end |
+ (Object) register_converter(subclass)
[View source]
36 37 38 39 40 41 42 |
# File 'backend/app/converters/converter.rb', line 36 def self.register_converter(subclass) @converters ||= [] # Add the most recently created subclass to the beginning of the list so we # give it preference when searching. @converters.unshift(subclass) end |
Instance Method Details
- (Object) get_output_path
[View source]
14 15 16 |
# File 'backend/app/converters/converter.rb', line 14 def get_output_path @batch.get_output_path end |
- (Object) remove_files
forcibly remove files in the event of an interruption
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'backend/app/converters/converter.rb', line 20 def remove_files @batch.each_open_file_path do |path| 3.times do |i| begin File.unlink(path) break rescue Errno::EACCES # sometimes windows does not like this. let's wait and retry. sleep(1) # just in case it's open by something else.. next unless i == 2 $stderr.puts "Cannot remove #{path}...giving up." end end end end |