Sha256: a89f66d2471d0996b300739fd92b303d83e218259511dba79f45e83410feaf75

Contents?: true

Size: 975 Bytes

Versions: 95

Compression:

Stored size: 975 Bytes

Contents

class KuberKit::Core::Store
  NotFoundError = Class.new(KuberKit::NotFoundError)
  AlreadyAddedError = Class.new(KuberKit::Error)

  attr_reader :object_class_name

  def initialize(object_class_name)
    @object_class_name = object_class_name
  end

  def add(item_name, item)
    unless item.is_a?(object_class_name)
      raise ArgumentError.new("#{self.object_class_name}: should be an instance of #{object_class_name}, got: #{item.inspect}")
    end

    unless items[item_name].nil?
      raise AlreadyAddedError, "#{self.object_class_name}: item with name #{item_name} was already added"
    end

    items[item_name] = item
  end

  def get(item_name)
    item = items[item_name]

    if item.nil?
      raise NotFoundError, "#{self.object_class_name}: item '#{item_name}' not found"
    end

    item
  end

  def items
    @items ||= {}
  end

  def reset!
    @items = {}
  end

  def size
    items.count
  end

  def exists?(name)
    !items[name].nil?
  end
end

Version data entries

95 entries across 95 versions & 1 rubygems

Version Path
kuber_kit-1.3.8 lib/kuber_kit/core/store.rb
kuber_kit-1.3.7 lib/kuber_kit/core/store.rb
kuber_kit-1.1.8 lib/kuber_kit/core/store.rb
kuber_kit-1.3.6 lib/kuber_kit/core/store.rb
kuber_kit-1.1.7 lib/kuber_kit/core/store.rb
kuber_kit-1.3.5 lib/kuber_kit/core/store.rb
kuber_kit-1.3.4 lib/kuber_kit/core/store.rb
kuber_kit-1.1.6 lib/kuber_kit/core/store.rb
kuber_kit-1.3.3 lib/kuber_kit/core/store.rb
kuber_kit-1.3.2 lib/kuber_kit/core/store.rb
kuber_kit-1.1.5 lib/kuber_kit/core/store.rb
kuber_kit-1.3.1 lib/kuber_kit/core/store.rb
kuber_kit-1.3.0 lib/kuber_kit/core/store.rb
kuber_kit-1.1.4 lib/kuber_kit/core/store.rb
kuber_kit-1.2.7 lib/kuber_kit/core/store.rb
kuber_kit-1.2.6 lib/kuber_kit/core/store.rb
kuber_kit-1.2.5 lib/kuber_kit/core/store.rb
kuber_kit-1.2.4 lib/kuber_kit/core/store.rb
kuber_kit-1.2.2 lib/kuber_kit/core/store.rb
kuber_kit-1.1.2 lib/kuber_kit/core/store.rb