Class: Riptables::DSL::Table

Inherits:
Global
  • Object
show all
Defined in:
lib/riptables/dsl/table.rb

Instance Method Summary collapse

Methods inherited from Global

#role, #zone

Constructor Details

#initialize(table) ⇒ Table

Returns a new instance of Table.



8
9
10
# File 'lib/riptables/dsl/table.rb', line 8

def initialize(table)
  @table = table
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(chain, *args, &block) ⇒ Object

 Any method which do not exist are most likely just new rules when inside this block.



33
34
35
36
37
38
39
# File 'lib/riptables/dsl/table.rb', line 33

def method_missing(chain, *args, &block)
  if block_given?
    self.rule(chain, *args, &block)
  else
    super
  end
end

Instance Method Details

#default_action(chain, action) ⇒ Object

Defines a default rule for a chain on this table



15
16
17
# File 'lib/riptables/dsl/table.rb', line 15

def default_action(chain, action)
  @table.chain(chain).default_action = action
end

#rule(chain, description = nil, &block) ⇒ Object

Add a new rule in this table



22
23
24
25
26
27
# File 'lib/riptables/dsl/table.rb', line 22

def rule(chain, description = nil, &block)
  rule = Riptables::Rule.new(@table.chain(chain))
  rule.description = description
  rule.dsl.instance_eval(&block)
  @table.chain(chain).rules << rule
end