Class: Bowline::Desktop::JS::Script

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/bowline/desktop/js.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

debug, #debug, #log_error, log_error, trace, #trace

Constructor Details

#initialize(window, script, prok = nil) ⇒ Script



8
9
10
11
12
# File 'lib/bowline/desktop/js.rb', line 8

def initialize(window, script, prok = nil)
  @window = window
  @script = script
  @prok   = prok
end

Instance Attribute Details

#prokObject (readonly)

Returns the value of attribute prok



7
8
9
# File 'lib/bowline/desktop/js.rb', line 7

def prok
  @prok
end

#scriptObject (readonly)

Returns the value of attribute script



7
8
9
# File 'lib/bowline/desktop/js.rb', line 7

def script
  @script
end

#windowObject (readonly) Also known as: windows

Returns the value of attribute window



7
8
9
# File 'lib/bowline/desktop/js.rb', line 7

def window
  @window
end

Instance Method Details

#callObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bowline/desktop/js.rb', line 21

def call
  if Desktop.enabled?
    debug "JS eval on #{window}: #{script}"
    if multiple_windows?
      windows.each {|w| w.run_script(script) }
      raise "Can't return from multiple windows" if prok
    else
      result = parse(window.run_script(script))
      Thread.new { prok.call(result) } if prok
    end
    result
  else
    debug "Pseudo JS eval on #{window}: #{script}"
    prok.call(nil) if prok
  end
end

#ready?Boolean



15
16
17
18
19
# File 'lib/bowline/desktop/js.rb', line 15

def ready?
  multiple_windows? ? 
    windows.all?(&:loaded?) : 
      window.loaded?
end