Sha256: 04b6f1f20c29006d46eb7e2df0b4a359c5c4735c6fd3726813c4e1925830be85

Contents?: true

Size: 911 Bytes

Versions: 2

Compression:

Stored size: 911 Bytes

Contents

module Vedeu
  class Groups

    # @return [Groups]
    def initialize; end

    # @return [Set]
    def all
      @_storage
    end

    # @param name [String]
    # @return [Set]
    def find(name)
      storage.fetch(name) do
        fail GroupNotFound, 'Cannot find interface group with this name.'
      end
    end

    # @param group [String]
    # @param name [String]
    # @param delay [Float]
    # @return [Groups|FalseClass]
    def add(group, name, delay = 0.0)
      return false if group.empty?

      storage[group] << name

      Vedeu.event("_refresh_group_#{group}_".to_sym, { delay: delay }) do
        Buffers.refresh_group(group)
      end

      self
    end

    # @return [Hash]
    def reset
      @_storage = in_memory
    end

    private

    def storage
      @_storage ||= in_memory
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vedeu-0.1.17 lib/vedeu/support/groups.rb
vedeu-0.1.16 lib/vedeu/support/groups.rb