Sha256: d346d3eb2e4b18e4365c0171982e32e3ff03227f8a07a2ac72e22d87a9051042

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

module Vedeu
  module Buffers

    extend self

    # @param attributes [Hash]
    # @return [Hash]
    def create(attributes)
      store_attributes(attributes)

      groups.add(attributes[:group], attributes[:name], attributes[:delay])

      focus.add(attributes[:name])

      store_interface(Interface.new(attributes))
    end

    # @return [Hash]
    def reset
      @_storage = {}
      @_buffers = {}
      groups.reset
    end

    # @param name [String]
    # @return [Hash]
    def retrieve_attributes(name)
      storage.fetch(name) { fail EntityNotFound, 'Interface was not found.' }
    end

    # @param name [String]
    # @return [Buffer]
    def retrieve_interface(name)
      buffers.fetch(name) { fail EntityNotFound, 'Interface was not found.' }
    end

    # @param attributes [Hash]
    # @return [Hash]
    def store_attributes(attributes)
      storage.store(attributes[:name], attributes)
    end

    # @param interface [Interface]
    # @return [Buffer]
    def store_interface(interface)
      update(interface.name,
        Buffer.new(interface: interface, back: nil, front: nil))
    end

    # @param name [String]
    # @param view [Interface]
    # @return []
    def enqueue(name, view)
      update(name, retrieve_interface(name).enqueue(view))
    end

    # @return [Array]
    def refresh_all
      buffers.keys.map { |name| refresh(name) }
    end

    # @return [Array]
    def refresh_group(group_name)
      groups.find(group_name).map { |name| refresh(name) }
    end

    # @param name [String]
    # @return []
    def refresh(name)
      update(name, retrieve_interface(name).refresh)
    end

    private

    def update(name, buffer)
      buffers.store(name, buffer)
    end

    def focus
      @_focus ||= Focus.new
    end

    def groups
      @_groups ||= Groups.new
    end

    def buffers
      @_buffers ||= {}
    end

    def storage
      @_storage ||= {}
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.1.17 lib/vedeu/support/buffers.rb