Class: HubLink::Importer

Inherits:
Object
  • Object
show all
Defined in:
lib/hub_link/importer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo:, start_date:, resources:, &block) ⇒ Importer

Returns a new instance of Importer.



13
14
15
16
17
18
# File 'lib/hub_link/importer.rb', line 13

def initialize(repo:, start_date:, resources:, &block)
  @repo = repo.to_s
  @start_date = start_date
  @resources = resources
  @callbacks = Callbacks.new(block)
end

Class Method Details

.run(*args, &block) ⇒ Object



9
10
11
# File 'lib/hub_link/importer.rb', line 9

def self.run(*args, &block)
  new(*args, &block).run
end

Instance Method Details

#runObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/hub_link/importer.rb', line 20

def run
  stream.in_batches do |batch|
    callback(:init, batch.query)

    resources.each do |source, target|
      callback(:start, source)
      import batch.fetch(source), to: target
      callback(:finish, target.count)
    end
  end
end