Class: Gienah::Testing::FakePlugin
- Inherits:
-
Object
- Object
- Gienah::Testing::FakePlugin
- Defined in:
- lib/gienah/testing/fake_plugin.rb,
sig/gienah.rbs
Instance Attribute Summary collapse
-
#capabilities ⇒ Array[String]
readonly
Returns the value of attribute capabilities.
Instance Method Summary collapse
- #dispatch(message) ⇒ Object
- #export(method) {|arg0| ... } ⇒ FakePlugin
-
#initialize(capabilities: []) ⇒ FakePlugin
constructor
A new instance of FakePlugin.
- #notify(method, params = {}) ⇒ Object
- #on_notification {|arg0, arg1| ... } ⇒ FakePlugin
- #transport(manifest) {|arg0, arg1| ... } ⇒ Transport
Constructor Details
#initialize(capabilities: []) ⇒ FakePlugin
Returns a new instance of FakePlugin.
8 9 10 11 12 |
# File 'lib/gienah/testing/fake_plugin.rb', line 8 def initialize(capabilities: []) @exports = {} @notifications = [] @capabilities = capabilities.map(&:to_s) end |
Instance Attribute Details
#capabilities ⇒ Array[String] (readonly)
Returns the value of attribute capabilities.
6 7 8 |
# File 'lib/gienah/testing/fake_plugin.rb', line 6 def capabilities @capabilities end |
Instance Method Details
#dispatch(message) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gienah/testing/fake_plugin.rb', line 28 def dispatch() method = ["method"] params = .fetch("params", {}) case method when "initialize" @capabilities = Array(params["capabilities"]).map(&:to_s) Protocol.response(["id"], result: {"api_version" => params["api_version"]}) when "shutdown" Protocol.response(["id"], result: nil) else handler = @exports[method] return Protocol.response(["id"], error: {"code" => -32601, "message" => "method not found: #{method}"}) unless handler result = handler.arity == 1 ? handler.call(params) : handler.call(self, params) Protocol.response(["id"], result: result) end rescue StandardError => error Protocol.response(["id"], error: {"code" => -32000, "message" => "#{error.class}: #{error.}"}) end |
#export(method) {|arg0| ... } ⇒ FakePlugin
14 15 16 17 |
# File 'lib/gienah/testing/fake_plugin.rb', line 14 def export(method, &handler) @exports[method] = handler self end |
#notify(method, params = {}) ⇒ Object
47 48 49 |
# File 'lib/gienah/testing/fake_plugin.rb', line 47 def notify(method, params = {}) @notifications.each { |handler| handler.call(method, params) } end |
#on_notification {|arg0, arg1| ... } ⇒ FakePlugin
19 20 21 22 |
# File 'lib/gienah/testing/fake_plugin.rb', line 19 def on_notification(&handler) @notifications << handler self end |
#transport(manifest) {|arg0, arg1| ... } ⇒ Transport
24 25 26 |
# File 'lib/gienah/testing/fake_plugin.rb', line 24 def transport(manifest, &receive) FakeTransport.new(self, manifest, receive) end |