Class: RailsSpotlight::Channels::Handlers::LogsHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_spotlight/channels/handlers/logs_handler.rb

Constant Summary collapse

TYPE =
'logs'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ LogsHandler

Returns a new instance of LogsHandler.



9
10
11
# File 'lib/rails_spotlight/channels/handlers/logs_handler.rb', line 9

def initialize(data)
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



13
14
15
# File 'lib/rails_spotlight/channels/handlers/logs_handler.rb', line 13

def data
  @data
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
# File 'lib/rails_spotlight/channels/handlers/logs_handler.rb', line 15

def call
  return unless ::RailsSpotlight.config.live_logs_enabled?
  return unless data['type'] == TYPE

  for_project = Array(data['project'])
  raise_project_mismatch_error!(for_project) if for_project.present? && !for_project.include?(project)

  { payload: data[:payload] }
end

#projectObject



32
33
34
# File 'lib/rails_spotlight/channels/handlers/logs_handler.rb', line 32

def project
  ::RailsSpotlight.config.project_name
end

#raise_project_mismatch_error!(for_project) ⇒ Object



25
26
27
28
29
30
# File 'lib/rails_spotlight/channels/handlers/logs_handler.rb', line 25

def raise_project_mismatch_error!(for_project)
  raise ::RailsSpotlight::Channels::Handlers::ResponseError.new(
    "Project mismatch, Logs from #{for_project} project cannot be forwarded in #{project} project",
    code: :project_mismatch
  )
end