Sha256: 1c2e85b96bb579e620a7ac87817e4b678a071b8f94ab21891df52098c9ded21c

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module Vedeu

  # Repository for storing and retrieving interfaces by their group name.
  #
  # @api private
  module Groups

    include Repository
    extend self

    # Add an interface name to a group, creating the group if it doesn't already
    # exist, and rejecting the interface if it is already known.
    #
    # @param attributes [Hash]
    # @return [Boolean]
    def add(attributes)
      validate_attributes!(attributes)

      return false unless defined_value?(attributes[:group])

      storage[attributes[:group]] << attributes[:name]

      register_event(attributes)

      true
    end

    private

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

      Vedeu::Refresh.register_event(:by_group, group_name, delay)
    end

    # @return [Hash]
    def in_memory
      Hash.new { |hash, key| hash[key] = Set.new }
    end

  end # Groups

end # Vedeu

Version data entries

2 entries across 2 versions & 1 rubygems

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