Module: Stockboy::Registry

Included in:
Filters, Providers, Readers, Translations
Defined in:
lib/stockboy/registry.rb

Overview

Holds a collection of registered classes for convenient reference by symbolic name

Instance Method Summary collapse

Instance Method Details

#allHash

List all named classes in the registry

Returns:

  • (Hash)


37
38
39
# File 'lib/stockboy/registry.rb', line 37

def all
  @registry
end

#build(key, options, block) ⇒ Object



41
42
43
44
45
46
# File 'lib/stockboy/registry.rb', line 41

def build(key, options, block)
  options = [options] unless options.is_a? Array
  key = find(key) if key.is_a? Symbol
  key = key.new(*options, &block) if key.is_a? Class
  key
end

#find(key) ⇒ Class Also known as: []

Look up a class and return it by symbolic name

Parameters:

  • key (Symbol)

Returns:

  • (Class)


28
29
30
# File 'lib/stockboy/registry.rb', line 28

def find(key)
  @registry[key]
end

#register(key, provider) ⇒ Object

Register a class under a convenient symbolic name

Parameters:

  • key (Symbol)

    Symbolic name of the class

  • provider (Class)

    Class to be returned when requested



19
20
21
# File 'lib/stockboy/registry.rb', line 19

def register(key, provider)
  @registry[key] = provider
end