Sha256: b2a5f1e99f558d78b2a47a4ad233371d43062356a7b6731c79a82d50efc8a167

Contents?: true

Size: 1.1 KB

Versions: 14

Compression:

Stored size: 1.1 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.
  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

14 entries across 14 versions & 1 rubygems

Version Path
vedeu-0.4.32 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.31 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.30 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.29 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.28 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.27 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.26 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.25 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.24 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.23 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.22 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.21 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.20 lib/vedeu/storage/conveyor_store.rb
vedeu-0.4.19 lib/vedeu/storage/conveyor_store.rb