Class: Netfilter::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/netfilter/filter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chain, type, definition) ⇒ Filter

Returns a new instance of Filter.



14
15
16
17
18
# File 'lib/netfilter/filter.rb', line 14

def initialize(chain, type, definition)
  self.chain = chain
  self.type = type
  self.definition = definition
end

Instance Attribute Details

#chainObject

Returns the value of attribute chain.



3
4
5
# File 'lib/netfilter/filter.rb', line 3

def chain
  @chain
end

#definitionObject

Returns the value of attribute definition.



5
6
7
# File 'lib/netfilter/filter.rb', line 5

def definition
  @definition
end

#typeObject

Returns the value of attribute type.



4
5
6
# File 'lib/netfilter/filter.rb', line 4

def type
  @type
end

Class Method Details

.import(chain, data) ⇒ Object



9
10
11
12
# File 'lib/netfilter/filter.rb', line 9

def self.import(chain, data)
  data = data.symbolize_keys
  new(chain, data[:type], data[:definition])
end

Instance Method Details

#argsObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/netfilter/filter.rb', line 24

def args
  [].tap do |args|
    definition.each_pair do |key, value|
      key = object_to_argument(key)
      value = object_to_argument(value)
      value = "#{namespace}-#{value}" if key == "jump" && namespace && !NATIVE_TARGETS.include?(value.downcase)
      args << "--#{key} #{value}"
    end
  end
end

#exportObject



35
36
37
38
39
40
# File 'lib/netfilter/filter.rb', line 35

def export
  {
    :type => type,
    :definition => definition,
  }
end

#to_sObject



20
21
22
# File 'lib/netfilter/filter.rb', line 20

def to_s
  args*" "
end