Class: DebugConsole

Inherits:
Hyperloop::Component show all
Defined in:
lib/hyperloop/console/client_components.rb

Constant Summary

Constants inherited from Hyperloop::Component

Hyperloop::Component::VERSION

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.application_window_idObject

Returns the value of attribute application_window_id.



10
11
12
# File 'lib/hyperloop/console/client_components.rb', line 10

def application_window_id
  @application_window_id
end

.contextObject

Returns the value of attribute context.



11
12
13
# File 'lib/hyperloop/console/client_components.rb', line 11

def context
  @context
end

Class Method Details

.console_idObject



13
14
15
16
17
18
19
# File 'lib/hyperloop/console/client_components.rb', line 13

def console_id
  @console_id ||=
    (
      `sessionStorage.getItem('Hyperloop::Console::ConsoleId')` ||
      SecureRandom.uuid.tap { |id| `sessionStorage.setItem('Hyperloop::Console::ConsoleId', #{id})` }
    )
end

.evaluate(compiled_code) ⇒ Object



27
28
29
30
31
32
# File 'lib/hyperloop/console/client_components.rb', line 27

def evaluate(compiled_code)
  @code_to_send = @code_to_send[0..-2]
  mutate.history << {eval: @code_to_send}
  mutate.console_state :sending
  Evaluate.run target_id: application_window_id, sender_id: console_id, context: context, string: compiled_code
end

.ready!(code, compiled_code) ⇒ Object



21
22
23
24
25
# File 'lib/hyperloop/console/client_components.rb', line 21

def ready!(code, compiled_code)
  @code_to_send = code
  mutate.error_message nil
  evaluate compiled_code if @code_to_send =~ /.\n$/
end