Class: ActionTrace::FetchSessionStarts

Inherits:
Object
  • Object
show all
Includes:
ActivityLogFetchable, Interactor
Defined in:
app/interactors/action_trace/fetch_session_starts.rb

Instance Method Summary collapse

Methods included from ActivityLogFetchable

#base_scope, #should_fetch?

Instance Method Details

#callObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/interactors/action_trace/fetch_session_starts.rb', line 8

def call
  return unless should_fetch?('session_start')

  scope = base_scope(Ahoy::Visit)
  context.total_count += scope.count

  entries = scope.includes(:user)
                 .order(started_at: :desc)
                 .offset(context.range).limit(context.per_page)
                 .map do |visit|
    {
      id: "visit_#{visit.id}",
      source: 'session_start',
      occurred_at: visit.started_at,
      user: visit.user,
      subject: "#{visit.browser} on #{visit.os} (#{visit.ip})",
      details: visit.attributes.slice('ip', 'browser', 'os', 'device_type', 'country', 'landing_page', 'user_agent')
    }
  end

  context.raw_collection += entries
end