Sha256: 6cc3de0988eb32e870dd43448f35e267c6b4bdeac74a744c684b756e8d3f460b

Contents?: true

Size: 1.4 KB

Versions: 2

Compression:

Stored size: 1.4 KB

Contents

module Vedeu

  # Stores interface views to be later combined with interface geometry to be
  # displayed.
  #
  # @api private
  module Buffers

    include Repository
    extend self

    # Add an interface view into the back buffer. If the buffer is already
    # registered, then we preserve its front buffer. Returns the name of the
    # buffer added to storage.
    #
    # @param attributes [Hash]
    # @return [String] The name of the buffer that has been added.
    def add(attributes)
      validate_attributes!(attributes)

      name = attributes[:name]

      if registered?(name)
        Vedeu.log("Adding new content to existing buffer: '#{name}'")

        find(name).add(attributes)

      else
        Vedeu.log("Adding new buffer: '#{name}'")

        Buffer.new({ name: name }).add(attributes)

      end

      name
    end

    # Update the repository with the provided Buffer. Returns a boolean
    # indicating whether this was successful.
    #
    # @param buffer [Buffer]
    # @return [Boolean]
    def update(buffer)
      storage.store(buffer.name, buffer)

      true
    end

    private

    # @return [Hash]
    def in_memory
      {}
    end

    # @param name [String]
    # @raise [BufferNotFound] When the entity cannot be found with this name.
    # @return [BufferNotFound]
    def not_found(name)
      fail BufferNotFound, "Cannot find buffer: '#{name}'"
    end

  end # Buffers

end # Vedeu

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vedeu-0.2.10 lib/vedeu/repositories/buffers.rb
vedeu-0.2.9 lib/vedeu/repositories/buffers.rb