Class: ASpaceImport::RecordBatch

Inherits:
Object
  • Object
show all
Defined in:
backend/app/converters/lib/parse_queue.rb

Overview

Manages the JSON object batch set

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (RecordBatch) initialize(opts = {})

Returns a new instance of RecordBatch



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'backend/app/converters/lib/parse_queue.rb', line 11

def initialize(opts = {})
  opts.each do |k,v|
    instance_variable_set("@#{k}", v)
  end

  @must_be_unique = ['subject']

  @record_filter = ->(record) { true }

  @uri_remapping = {}
  @seen_records = {}

  @working_file = opts[:working_file] || ASUtils.tempfile("import_batch_working_file")
  @working_area = []
end

Class Method Details

+ (Object) dedupe_subrecords(obj)



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'backend/app/converters/lib/parse_queue.rb', line 28

def self.dedupe_subrecords(obj)
  ASpaceImport::FIELDS_TO_DEDUPE.each do |subrecord|

    if obj.respond_to?(subrecord) && obj.send(subrecord).is_a?(Array)
      hashes = []
      obj.send(subrecord).map! { |json|
        hash = json.to_hash.hash
        if hashes.include?(hash)
          nil
        else
          hashes << hash
          json
        end
      }

      obj.send(subrecord).compact!
    end
  end
end

Instance Method Details

- (Object) <<(obj)



54
55
56
57
# File 'backend/app/converters/lib/parse_queue.rb', line 54

def <<(obj)
  self.class.dedupe_subrecords(obj)
  @working_area.push(obj)
end

- (Object) each_open_file_path {|@working_file.path| ... }

Yields:

  • (@working_file.path)


84
85
86
87
# File 'backend/app/converters/lib/parse_queue.rb', line 84

def each_open_file_path
  yield @working_file.path if @working_file && @working_file.path
  yield @batch_file.path if @batch_file && @batch_file.path
end

- (Object) flush



60
61
62
63
64
# File 'backend/app/converters/lib/parse_queue.rb', line 60

def flush
  while !@working_area.empty?
    flush_last
  end
end

- (Object) flush_last

This URI check stops regular JSONModels from going through. JSONModelWrap is what puts that here…



69
70
71
72
73
74
75
# File 'backend/app/converters/lib/parse_queue.rb', line 69

def flush_last
  last = @working_area.pop

  if last.class.method_defined? :uri and !last.uri.nil?
    _push(last)
  end
end

- (Object) get_output_path



78
79
80
81
# File 'backend/app/converters/lib/parse_queue.rb', line 78

def get_output_path
  close
  @batch_file.path
end

- (Object) record_filter=(predicate)



90
91
92
# File 'backend/app/converters/lib/parse_queue.rb', line 90

def record_filter=(predicate)
  @record_filter = predicate
end

- (Object) working_area



49
50
51
# File 'backend/app/converters/lib/parse_queue.rb', line 49

def working_area
  @working_area
end