Class: Rooibos::Message::Routed

Inherits:
Data
  • Object
show all
Includes:
Predicates
Defined in:
lib/rooibos/message/routed.rb

Overview

Message synthesized by Router when keymap uses symbol + route.

When a keymap entry uses a symbol instead of a handler, and specifies a route, the Router creates this message and dispatches it to the child fragment’s UPDATE.

Example

# In parent keymap:
key :down, :move_down, route: :file_list

# Router synthesizes:
Routed.new(envelope: :move_down, event: key_event)

# Child UPDATE matches:
in { type: :routed, envelope: :move_down }
  handle_move_down(model)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Predicates

#==, #to_sym

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/rooibos/message/routed.rb', line 42

def method_missing(method_name, *args, &block)
  if method_name.end_with?("?")
    method_name.to_s.chomp("?") == envelope.to_s
  else
    super
  end
end

Instance Attribute Details

#envelopeObject (readonly)

Returns the value of attribute envelope

Returns:

  • (Object)

    the current value of envelope



27
28
29
# File 'lib/rooibos/message/routed.rb', line 27

def envelope
  @envelope
end

#eventObject (readonly)

Returns the value of attribute event

Returns:

  • (Object)

    the current value of event



27
28
29
# File 'lib/rooibos/message/routed.rb', line 27

def event
  @event
end

Instance Method Details

#deconstruct_keys(_keys) ⇒ Object



30
31
32
# File 'lib/rooibos/message/routed.rb', line 30

def deconstruct_keys(_keys)
  { type: :routed, envelope:, event: }
end

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/rooibos/message/routed.rb', line 38

def respond_to_missing?(method_name, include_private = false)
  method_name.end_with?("?") || super
end

#routed?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/rooibos/message/routed.rb', line 34

def routed?
  true
end