Class: Threatinator::Registry

Inherits:
Object
  • Object
show all
Includes:
Exceptions
Defined in:
lib/threatinator/registry.rb

Overview

Just a simple class that holds stuff. Yup, a glorified hash.

Direct Known Subclasses

FeedRegistry

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



8
9
10
# File 'lib/threatinator/registry.rb', line 8

def initialize()
  @data= Hash.new
end

Instance Method Details

#clearObject

Removes all objects from the registry



48
49
50
# File 'lib/threatinator/registry.rb', line 48

def clear
  @data.clear
end

#countInteger

Returns the number of objects in the registry.

Returns:

  • (Integer)

    the number of objects in the registry



35
36
37
# File 'lib/threatinator/registry.rb', line 35

def count
  @data.count
end

#each {|object| ... } ⇒ Object

Enumerates through each object in our registry

Yields:

  • (object)

Yield Parameters:

  • object (Object)

    An object within the registry



42
43
44
45
# File 'lib/threatinator/registry.rb', line 42

def each(&block)
  return enum_for(:each) unless block_given?
  @data.each_pair(&block)
end

#get(key) ⇒ Object

Parameters:

  • key (Object)

Returns:

  • (Object)


25
26
27
# File 'lib/threatinator/registry.rb', line 25

def get(key)
  @data[key]
end

#keysArray<Object>

Returns an array of keys.

Returns:

  • (Array<Object>)

    an array of keys



30
31
32
# File 'lib/threatinator/registry.rb', line 30

def keys
  @data.keys
end

#register(key, object) ⇒ Object

Parameters:

  • key (Object)

    The object to use as the key for storing the object

  • object (Object)

    The object to be stored

Raises:

  • (Threatinator::Exceptions::dAlreadyRegisteredError)

    if an object with the same key is already registered.



16
17
18
19
20
21
# File 'lib/threatinator/registry.rb', line 16

def register(key, object)
  if @data.has_key?(key)
    raise AlreadyRegisteredError.new(key)
  end
  @data[key] = object
end