Module: ActiveCypher::Bolt::Messaging

Defined in:
lib/active_cypher/bolt/messaging.rb

Defined Under Namespace

Classes: Begin, Commit, Discard, Failure, Goodbye, Hello, Ignored, Logoff, Logon, Message, Pull, Record, Reset, Rollback, Route, Run, Success, Telemetry

Class Method Summary collapse

Class Method Details

.for_signature(signature, *fields) ⇒ Message

Lookup-and-instantiate based on signature + raw fields

Parameters:

  • signature (Integer)

    the Bolt message signature

  • fields (Array)

    the decoded fields for this message

Returns:

  • (Message)

    instance of the right subclass, or generic Message



25
26
27
28
29
30
31
# File 'lib/active_cypher/bolt/messaging.rb', line 25

def for_signature(signature, *fields)
  if (klass = @registry[signature])
    klass.new(*fields)
  else
    Message.new(signature, fields)
  end
end

.normalize_map(map) ⇒ Object

Normalize any metadata or parameters map



42
43
44
# File 'lib/active_cypher/bolt/messaging.rb', line 42

def normalize_map(map)
  (map || {}).with_indifferent_access
end

.register(subclass) ⇒ Object

Register a subclass if it defines SIGNATURE



34
35
36
37
38
39
# File 'lib/active_cypher/bolt/messaging.rb', line 34

def register(subclass)
  return unless subclass.const_defined?(:SIGNATURE)

  sig = subclass.const_get(:SIGNATURE)
  @registry[sig] = subclass
end

.registryObject

For introspection



16
17
18
# File 'lib/active_cypher/bolt/messaging.rb', line 16

def registry
  @registry.dup
end