Sha256: 28c7e7504f08972d04d435de664a7672a22cd29dbe2a2479404326ff05a1ea91

Contents?: true

Size: 1.67 KB

Versions: 2

Compression:

Stored size: 1.67 KB

Contents

module Vedeu

  # Repository for storing and retrieving defined interfaces.
  #
  # @api private
  module Interfaces

    include Repository
    extend self

    # Stores the interface attributes defined by the API.
    #
    # @param attributes [Hash]
    # @return [Hash|FalseClass]
    def add(attributes)
      validate_attributes!(attributes)

      Vedeu.log("Registering interface: '#{attributes[:name]}'")

      storage.store(attributes[:name], attributes)

      register_event(attributes)

      true
    end

    # Create an instance of Interface from the stored attributes.
    #
    # @param name [String]
    # @return [Interface]
    def build(name)
      model.new(find(name))
    end

    # Reset the interfaces repository; removing all registered interfaces.
    # This will delete the interfaces themselves, and the client application
    # will need to either redefine interfaces before using them, or restart.
    #
    # Note: It also resets repositories which depend on interfaces being
    # registered.
    #
    # @return [Hash]
    def reset
      @_storage = in_memory

      Vedeu::Buffers.reset
      Vedeu::Cursors.reset
      Vedeu::Focus.reset
      Vedeu::Groups.reset

      @_storage
    end

    private

    # @return [Class] The model class for this repository.
    def model
      Vedeu::Interface
    end

    # @see Vedeu::Refresh.register_event
    # @param attributes [Hash]
    # @return [Boolean]
    def register_event(attributes)
      name  = attributes[:name]
      delay = attributes[:delay] || 0.0

      Vedeu::Refresh.register_event(:by_name, name, delay)
    end

    # @return [Hash]
    def in_memory
      {}
    end

  end # Interfaces

end # Vedeu

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vedeu-0.2.12 lib/vedeu/repositories/interfaces.rb
vedeu-0.2.11 lib/vedeu/repositories/interfaces.rb