Module: Moneta::EachKeySupport Private

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

This provides an each_key implementation that works in most cases.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



441
442
443
# File 'lib/moneta/mixins.rb', line 441

def self.included(base)
  base.supports(:each_key) if base.respond_to?(:supports)
end

Instance Method Details

#each_keyObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
# File 'lib/moneta/mixins.rb', line 423

def each_key
  return enum_for(:each_key) unless block_given?

  if @backend.respond_to?(:each_key)
    @backend.each_key { |key| yield key }
  elsif @backend.respond_to?(:keys)
    if keys = @backend.keys
      keys.each { |key| yield key }
    end
  elsif @backend.respond_to?(:each)
    @backend.each { |key, _| yield key }
  else
    raise ::NotImplementedError, "No enumerable found on backend"
  end

  self
end