Sha256: 31ca3c58183744e4994f855a0bc2af47361ec06c4936cb3e34ada139422260ff

Contents?: true

Size: 1.12 KB

Versions: 8

Compression:

Stored size: 1.12 KB

Contents

module Vedeu

  # Conveyor belt like storage. The belt can move forward (`load_next`) or
  # backwards (`load_previous`), or a named entry can be retrieved.
  #
  # @api private
  class ConveyorStore

    include Vedeu::Store

    # @param storage [Array]
    # @return [Vedeu::ConveyorStore]
    def initialize(storage = [])
      @storage = storage
    end

    # @return [Object]
    def load
      storage.first
    end
    alias_method :current, :load

    # @param name [String]
    # @return [Object]
    def load_named(name)
      return nil if empty?

      return nil unless storage.include?(name)

      storage.rotate!(storage.index(name))

      load
    end

    # @return [Object]
    def load_next
      storage.rotate!

      load
    end

    # @return [Object]
    def load_previous
      storage.rotate!(-1)

      load
    end

    # @param data [Object]
    # @param front [Boolean]
    def save(data, front = false)
      if front
        storage.push(data)

      else
        storage.unshift(data)

      end
    end

    private

    # @return [Array]
    def in_memory
      []
    end

  end # ConveyorStore

end # Vedeu

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
vedeu-0.4.40 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.39 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.38 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.37 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.36 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.35 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.34 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.33 lib/vedeu/storage/conveyor_store.rb