Class: Arrthorizer::Registry

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/arrthorizer/registry.rb

Constant Summary collapse

NotFound =
Class.new(ArrthorizerException)

Instance Method Summary collapse

Constructor Details

#initializeRegistry

Returns a new instance of Registry.



11
12
13
# File 'lib/arrthorizer/registry.rb', line 11

def initialize
  self.storage = Hash.new
end

Instance Method Details

#add(object) ⇒ Object



15
16
17
# File 'lib/arrthorizer/registry.rb', line 15

def add(object)
  storage[object.to_key] = object
end

#each(&block) ⇒ Object



7
8
9
# File 'lib/arrthorizer/registry.rb', line 7

def each(&block)
  storage.values.each(&block)
end

#fetch(key, &block) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/arrthorizer/registry.rb', line 19

def fetch(key, &block)
  block ||= proc { raise NotFound, "Could not find value for #{key.inspect}" }

  formatted_key = key.respond_to?(:to_key) ? key.to_key : key

  storage.fetch(formatted_key, &block)
end