Class: Tablomat::IPSet::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/tablomat/ipset/entry.rb

Overview

interface to manage the entrys inside the sets

Instance Method Summary collapse

Constructor Details

#initialize(set, description) ⇒ Entry

Returns a new instance of Entry.



7
8
9
10
11
# File 'lib/tablomat/ipset/entry.rb', line 7

def initialize(set, description)
  @system = set.system
  @set = set
  @description = description
end

Instance Method Details

#add(add_options, exist = false) ⇒ Object



25
26
27
28
29
# File 'lib/tablomat/ipset/entry.rb', line 25

def add(add_options, exist = false)
  command = "#{@system.ipset_bin} add #{@set.name} #{@description} #{add_options}"
  command = "#{command} -!" if exist
  @system.exec command
end

#del(exist = false) ⇒ Object



31
32
33
34
35
# File 'lib/tablomat/ipset/entry.rb', line 31

def del(exist = false)
  command = "#{@system.ipset_bin} del #{@set.name} #{@description}"
  command = "#{command} -!" if exist
  @system.exec command
end

#exists?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tablomat/ipset/entry.rb', line 13

def exists?
  command = "#{@system.ipset_bin} del #{@set.name} #{@description}"
  @system.exec command
  command = "#{@system.ipset_bin} add #{@set.name} #{@description}"
  @system.exec command
  true
rescue IPSetError => e
  raise unless e.message.include?("Element cannot be deleted from the set: it's not added")

  false
end