Class: Construqt::Flavour::Ubuntu::EtcNetworkIptables::Section::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb

Defined Under Namespace

Classes: Row, RowFactory

Instance Method Summary collapse

Constructor Details

#initialize(section) ⇒ Block

Returns a new instance of Block.



82
83
84
85
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 82

def initialize(section)
  @section = section
  @rows = []
end

Instance Method Details

#commitObject



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 130

def commit
  #puts @rows.inspect
  tables = @rows.inject({}) do |r, row|
    r[row.get_table] ||= {}
    r[row.get_table][row.get_chain] ||= []
    r[row.get_table][row.get_chain] << row
    r
  end

  return "" if tables.empty?
  ret = ["*#{@section.name}"]
  ret += tables.keys.sort.map do |k|
    v = tables[k]
    if k.empty?
      v.keys.map{|o| ":#{o} ACCEPT [0:0]" }
    else
      ":#{k} - [0:0]"
    end
  end

  tables.keys.sort.each do |k,v|
    v = tables[k]
    v.keys.sort.each do |chain|
      rows = v[chain]
      table = !k.empty? ? "-A #{k}" : "-A #{chain}"
      rows.each do |row|
        ret << "#{table} #{row.get_row}"
      end
    end
  end

  ret << "COMMIT"
  ret << ""
  ret.join("\n")
end

#forwardObject



118
119
120
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 118

def forward
  table("", 'FORWARD')
end

#inputObject



126
127
128
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 126

def input
  table("", 'INPUT')
end

#outputObject



122
123
124
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 122

def output
  table("", 'OUTPUT')
end

#postroutingObject



114
115
116
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 114

def postrouting
  table("", 'POSTROUTING')
end

#preroutingObject



110
111
112
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 110

def prerouting
  table("", 'PREROUTING')
end

#table(table, chain = nil) ⇒ Object



106
107
108
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 106

def table(table, chain = nil)
  RowFactory.new.rows(@rows).table(table).chain(chain)
end