Class: RailsSpotlight::Channels::Handlers::LiveConsoleHandler
- Inherits:
-
Object
- Object
- RailsSpotlight::Channels::Handlers::LiveConsoleHandler
- Defined in:
- lib/rails_spotlight/channels/handlers/live_console_handler.rb
Constant Summary collapse
- TYPE =
'console'
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #call ⇒ Object
- #execute_command(command, inspect_types) ⇒ Object
- #executor ⇒ Object
-
#initialize(data) ⇒ LiveConsoleHandler
constructor
A new instance of LiveConsoleHandler.
- #project ⇒ Object
- #raise_project_mismatch_error!(for_project) ⇒ Object
Constructor Details
#initialize(data) ⇒ LiveConsoleHandler
Returns a new instance of LiveConsoleHandler.
11 12 13 |
# File 'lib/rails_spotlight/channels/handlers/live_console_handler.rb', line 11 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
15 16 17 |
# File 'lib/rails_spotlight/channels/handlers/live_console_handler.rb', line 15 def data @data end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rails_spotlight/channels/handlers/live_console_handler.rb', line 17 def call return unless ::RailsSpotlight.config.live_logs_enabled? return unless data['type'] == TYPE command = data['command'] inspect_types = data['inspect_types'] for_project = Array(data['project']) raise_project_mismatch_error!(for_project) if for_project.present? && !for_project.include?(project) execute_command(command, inspect_types) end |
#execute_command(command, inspect_types) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rails_spotlight/channels/handlers/live_console_handler.rb', line 41 def execute_command(command, inspect_types) RailsSpotlight.config.logger && RailsSpotlight.config.logger.info("Executing command: #{command}") # rubocop:disable Style/SafeNavigation executor.execute(command) if executor.execution_successful? { payload: { result: executor.result_as_json(inspect_types: inspect_types) } } else { payload: { failed: executor.result_as_json } } end rescue => e # rubocop:disable Style/RescueStandardError { error: e. } end |
#executor ⇒ Object
30 31 32 |
# File 'lib/rails_spotlight/channels/handlers/live_console_handler.rb', line 30 def executor @executor ||= ::RailsSpotlight::RailsCommandExecutor.new end |
#project ⇒ Object
58 59 60 |
# File 'lib/rails_spotlight/channels/handlers/live_console_handler.rb', line 58 def project ::RailsSpotlight.config.project_name end |
#raise_project_mismatch_error!(for_project) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/rails_spotlight/channels/handlers/live_console_handler.rb', line 34 def raise_project_mismatch_error!(for_project) raise ::RailsSpotlight::Channels::Handlers::ResponseError.new( "Project mismatch, The command was intended for the #{for_project} project. This is #{project} project", code: :project_mismatch ) end |