Class: Bowline::Desktop::Bridge::Message

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

Overview

:nodoc:

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from Logging

#debug, #log_error, #trace

Constructor Details

- (Message) initialize(window, atts)

A new instance of Message



45
46
47
48
49
50
51
52
# File 'lib/bowline/desktop/bridge.rb', line 45

def initialize(window, atts)
  @window       = window
  atts          = atts.with_indifferent_access
  @id           = atts[:id]
  @klass        = atts[:klass]
  @method_name  = atts[:method].to_sym
  @args         = atts[:args] || []
end

Instance Attribute Details

- (Object) args (readonly)

Returns the value of attribute args



43
44
45
# File 'lib/bowline/desktop/bridge.rb', line 43

def args
  @args
end

- (Object) id (readonly)

Returns the value of attribute id



43
44
45
# File 'lib/bowline/desktop/bridge.rb', line 43

def id
  @id
end

- (Object) klass (readonly)

Returns the value of attribute klass



43
44
45
# File 'lib/bowline/desktop/bridge.rb', line 43

def klass
  @klass
end

- (Object) method_name (readonly)

Returns the value of attribute method_name



43
44
45
# File 'lib/bowline/desktop/bridge.rb', line 43

def method_name
  @method_name
end

- (Object) window (readonly)

Returns the value of attribute window



43
44
45
# File 'lib/bowline/desktop/bridge.rb', line 43

def window
  @window
end

Instance Method Details

- (Object) callback(result)



58
59
60
61
62
63
64
65
66
67
# File 'lib/bowline/desktop/bridge.rb', line 58

def callback(result)
  return unless callback?
  proxy = Proxy.new(window)
  proxy = proxy.Bowline.invokeCallback(
    id, result.to_js.to_json
  )
  Runtime.main { 
    window.run_script(proxy.to_s)
  }
end

- (Boolean) callback?

Returns:

  • (Boolean)


54
55
56
# File 'lib/bowline/desktop/bridge.rb', line 54

def callback?
  @id != -1
end

- (Object) invoke



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/bowline/desktop/bridge.rb', line 69

def invoke
  debug "JS invoking: #{klass}.#{method_name}(#{args.join(',')})"

  if klass == "_window"
    object = window
  else
    # TODO - security concerns with constantize
    object = klass.constantize
  end

  if object.respond_to?(:js_exposed?) && 
      object.js_exposed?(method_name)
    
    object.js_invoke(
      window, 
      method(:callback), 
      method_name, 
      *args
    )

  else
    raise "Method not allowed"
  end
rescue => e
  log_error e
end