Class: Jumbotron::Services::Adapters::BuildLineAcquisitionScopes

Inherits:
CommandTower::Services::ApplicationService
  • Object
show all
Defined in:
app/services/jumbotron/services/adapters/build_line_acquisition_scopes.rb

Instance Method Summary collapse

Instance Method Details

#callObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/jumbotron/services/adapters/build_line_acquisition_scopes.rb', line 10

def call
  seen = {}
  scopes = []
  incomplete = 0
  games_by_id = Game.where(id: Array(games).map(&:id)).includes(:provider_identities).index_by(&:id)
  Array(games).each do |game|
    scoped_game = games_by_id[game.id] || game
    scope = adapter.line_acquisition_scope_for(scoped_game)
    if scope.nil?
      incomplete += 1
      next
    end

    key = [
      scope.fetch(:endpoint),
      Synchronization::Lease.normalized_acquisition_parts(scope.fetch(:acquisition))
    ]
    next if seen[key]

    seen[key] = true
    scopes << { endpoint: scope.fetch(:endpoint), acquisition: scope.fetch(:acquisition) }
  end

  context.scopes = scopes
  context.skipped_incomplete_scope = incomplete
end