Module: Plushie::Event::Effect::Result

Defined in:
lib/plushie/event.rb

Overview

Typed per-kind outcomes nested under Event::Effect.

Matches the Rust SDK's EffectResult enum. Host SDKs share the concept across language-idiomatic shapes; Ruby uses Data.define classes so apps can pattern-match on the class with Ruby's native case/in syntax.

Defined Under Namespace

Classes: Cancelled, ClipboardCleared, ClipboardHtml, ClipboardText, ClipboardWritten, DirectoriesSelected, DirectorySelected, Error, FileOpened, FileSaved, FilesOpened, NotificationShown, RendererRestarted, Timeout, Unsupported

Class Method Summary collapse

Class Method Details

.decode(kind, status, payload) ⇒ Object

Decode a renderer-supplied (kind, status, payload) triple into the appropriate Data.define instance.

Parameters:

  • kind (String)

    effect kind, e.g. "file_open"

  • status (String)

    wire status: "ok", "cancelled", "error", "unsupported"

  • payload (Object, nil)

    result payload on "ok" or the error reason on "error"

Returns:

  • (Object)

    typed result instance



239
240
241
242
243
244
245
246
247
# File 'lib/plushie/event.rb', line 239

def self.decode(kind, status, payload)
  case status
  when "cancelled" then Cancelled.new
  when "unsupported" then Unsupported.new
  when "error" then Error.new(message: payload.to_s)
  when "ok" then decode_ok(kind, payload.is_a?(Hash) ? payload : {})
  else Error.new(message: "unknown effect status: #{status}")
  end
end