Class: Sourced::Message::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/sourced/message.rb

Instance Method Summary collapse

Constructor Details

#initialize(message_class) ⇒ Registry

Returns a new instance of Registry.



71
72
73
74
# File 'lib/sourced/message.rb', line 71

def initialize(message_class)
  @message_class = message_class
  @lookup = {}
end

Instance Method Details

#[](key) ⇒ Object



80
81
82
83
84
85
86
87
88
89
# File 'lib/sourced/message.rb', line 80

def [](key)
  klass = lookup[key]
  return klass if klass

  message_class.subclasses.each do |c|
    klass = c.registry[key]
    return klass if klass
  end
  nil
end

#[]=(key, klass) ⇒ Object



76
77
78
# File 'lib/sourced/message.rb', line 76

def []=(key, klass)
  @lookup[key] = klass
end

#inspectObject



91
92
93
# File 'lib/sourced/message.rb', line 91

def inspect
  %(<#{self.class}:#{object_id} #{lookup.size} keys, #{message_class.subclasses.size} child registries>)
end