Class: IPTables::Macro

Inherits:
Object
  • Object
show all
Defined in:
lib/iptables/expansions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, info) ⇒ Macro

Returns a new instance of Macro.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/iptables/expansions.rb', line 17

def initialize(name, info)
  @name = name
  @info = info
  @children = []

  case info
  when Array
    self.handle_array()
  when Hash
    self.handle_hash()
  when String
    self.handle_string()
  else
    raise "don't know how to handle info: #{info.inspect}"
  end
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



16
17
18
# File 'lib/iptables/expansions.rb', line 16

def children
  @children
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/iptables/expansions.rb', line 16

def name
  @name
end

Instance Method Details

#add_child(rule_hash) ⇒ Object



34
35
36
# File 'lib/iptables/expansions.rb', line 34

def add_child(rule_hash)
  @children.push(rule_hash)
end

#handle_arrayObject



38
39
40
41
42
# File 'lib/iptables/expansions.rb', line 38

def handle_array()
  @info.each{ |macro_hash|
    self.add_child(macro_hash)
  }
end

#handle_hashObject



44
45
46
# File 'lib/iptables/expansions.rb', line 44

def handle_hash()
  self.add_child( @info )
end

#handle_stringObject



48
49
50
# File 'lib/iptables/expansions.rb', line 48

def handle_string()
  self.add_child( {'raw' => @info} )
end