Class: Bowline::Desktop::Bridge::Message
- Includes:
- Logging
- Defined in:
- lib/bowline/desktop/bridge.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Instance Method Summary collapse
- #callback(result) ⇒ Object
- #callback? ⇒ Boolean
-
#initialize(window, atts) ⇒ Message
constructor
A new instance of Message.
- #invoke ⇒ Object
Methods included from Logging
#debug, debug, #log_error, log_error, trace, #trace
Constructor Details
#initialize(window, atts) ⇒ Message
Returns 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
#args ⇒ Object (readonly)
Returns the value of attribute args.
43 44 45 |
# File 'lib/bowline/desktop/bridge.rb', line 43 def args @args end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
43 44 45 |
# File 'lib/bowline/desktop/bridge.rb', line 43 def id @id end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
43 44 45 |
# File 'lib/bowline/desktop/bridge.rb', line 43 def klass @klass end |
#method_name ⇒ Object (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 |
#window ⇒ Object (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
#callback(result) ⇒ Object
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 |
#callback? ⇒ Boolean
54 55 56 |
# File 'lib/bowline/desktop/bridge.rb', line 54 def callback? @id != -1 end |
#invoke ⇒ Object
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 |