Class: Racket::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/racket/registry.rb

Overview

Racket Registry namespace

Defined Under Namespace

Classes: InvalidCallbackError, InvalidKeyError, KeyAlreadyRegisteredError, KeyNotRegisteredError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.with_map(map) ⇒ Racket::Registry

Returns a new registry with all items in the map registered as non-singleton procs.

Parameters:

  • map (Hash)

Returns:



29
30
31
32
33
# File 'lib/racket/registry.rb', line 29

def with_map(map)
  registry = new
  map.each_pair { |key, value| registry.register(key, value) }
  registry
end

.with_singleton_map(map) ⇒ Racket::Registry Also known as: singleton_map

Returns a new registry with all items in the map registered as singleton procs.

Parameters:

  • map (Hash)

Returns:



40
41
42
43
44
# File 'lib/racket/registry.rb', line 40

def with_singleton_map(map)
  registry = new
  map.each_pair { |key, value| registry.register_singleton(key, value) }
  registry
end

Instance Method Details

#forget(key) ⇒ nil

Removes the callback specified by key from the registry.

Parameters:

  • key (String|Symbol)

Returns:

  • (nil)


53
54
55
# File 'lib/racket/registry.rb', line 53

def forget(key)
  Helper.forget(obj: self, key: key)
end

#forget_allObject

Removes all callbacks from the registry.



58
59
60
# File 'lib/racket/registry.rb', line 58

def forget_all
  Helper.forget_all(obj: self)
end

#register(key, proc = nil, &block) ⇒ nil

Registers a new callback in the registry. This will add a new method matching key to the registry that can be used both outside the registry and when registering other callbacks dependant of the current entry. Results from the callback will not be cached, meaning that the callback may return a different object every time.

Parameters:

  • key (String|Symbol)
  • proc (Proc|nil) (defaults to: nil)

Returns:

  • (nil)


71
72
73
# File 'lib/racket/registry.rb', line 71

def register(key, proc = nil, &block)
  Helper.register(obj: self, key: key, proc: proc, block: block)
end

#register_singleton(key, proc = nil, &block) ⇒ nil Also known as: singleton

Registers a new callback in the registry. This will add a new method matching key to the registry that can be used both outside the registry and when registering other callbacks dependant of the current entry. Results from the callnack will be cached, meaning that the callback will return the same object every time.

Parameters:

  • key (String|Symbol)
  • proc (Proc|nil) (defaults to: nil)

Returns:

  • (nil)


84
85
86
# File 'lib/racket/registry.rb', line 84

def register_singleton(key, proc = nil, &block)
  Helper.register_singleton(obj: self, key: key, proc: proc, block: block)
end