Sha256: 3c81b2a99e381d8060f8c87ce34d87f17c24e4e84a6740dcbf46e394b7123ce4

Contents?: true

Size: 659 Bytes

Versions: 7

Compression:

Stored size: 659 Bytes

Contents

# frozen_string_literal: true

module Noticent
  class ProcMap
    def initialize(config)
      @map = {}
      @config = config
    end

    def use(symbol, proc)
      raise Noticent::BadConfiguration, 'should provide a proc' unless proc.is_a?(Proc)
      raise Noticent::BadConfiguration, "invalid number of parameters for 'use' in '#{symbol}'" if proc.arity != 1

      @map[symbol] = proc
    end

    def fetch(symbol)
      raise Noticent::Error, "no map found for '#{symbol}'" if @map[symbol].nil?

      @map[symbol]
    end

    def count
      @map.count
    end

    def values
      @map
    end

    protected

    attr_reader :config
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
noticent-0.0.6 lib/noticent/proc_map.rb
noticent-0.0.5 lib/noticent/proc_map.rb
noticent-0.0.4 lib/noticent/proc_map.rb
noticent-0.0.3 lib/noticent/proc_map.rb
noticent-0.0.2 lib/noticent/proc_map.rb
noticent-0.0.1 lib/noticent/proc_map.rb
noticent-0.0.1.pre.pre lib/noticent/proc_map.rb