Sha256: ab9835a327db9dbeb88835fb0f3970b13044bf49afb4083f4e47aec759038406

Contents?: true

Size: 576 Bytes

Versions: 13

Compression:

Stored size: 576 Bytes

Contents

module Arrthorizer
  class Registry
    include Enumerable

    NotFound = Class.new(ArrthorizerException)

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

    def initialize
      self.storage = Hash.new
    end

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

    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

    private
    attr_accessor :storage
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
arrthorizer-0.4.2 lib/arrthorizer/registry.rb
arrthorizer-0.4.1 lib/arrthorizer/registry.rb
arrthorizer-0.3.2 lib/arrthorizer/registry.rb
arrthorizer-0.3.1 lib/arrthorizer/registry.rb
arrthorizer-0.3.0 lib/arrthorizer/registry.rb
arrthorizer-0.2.1 lib/arrthorizer/registry.rb
arrthorizer-0.2.0 lib/arrthorizer/registry.rb
arrthorizer-0.1.3 lib/arrthorizer/registry.rb
arrthorizer-0.1.2 lib/arrthorizer/registry.rb
arrthorizer-0.1.1 lib/arrthorizer/registry.rb
arrthorizer-0.1.0 lib/arrthorizer/registry.rb
arrthorizer-0.1.0.pre2 lib/arrthorizer/registry.rb
arrthorizer-0.1.0.pre lib/arrthorizer/registry.rb