Class: Puffy::RuleFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/puffy/rule_factory.rb

Overview

Puffy::Rule factory

Instance Method Summary collapse

Constructor Details

#initializeRuleFactory

Initialize a Puffy::Rule factory.



7
8
9
10
11
# File 'lib/puffy/rule_factory.rb', line 7

def initialize
  @af = nil
  @resolver = Resolver.instance
  load_services
end

Instance Method Details

#build(options = {}) ⇒ Array<Puffy::Rule>

Return an Array of Puffy::Rule for the provided options.

Parameters:

  • options (Hash) (defaults to: {})

Returns:



34
35
36
37
38
39
40
41
# File 'lib/puffy/rule_factory.rb', line 34

def build(options = {})
  return [] if options == {}

  options = { action: nil, return: false, dir: nil, af: nil, proto: nil, on: nil, from: { host: nil, port: nil }, to: { host: nil, port: nil }, nat_to: nil, rdr_to: { host: nil, port: nil } }.merge(options)

  options = resolv_hostnames_and_ports(options)
  instanciate_rules(options)
end

#ipv4Object

Limit the scope of a set of rules to IPv4 only.



14
15
16
17
18
19
20
# File 'lib/puffy/rule_factory.rb', line 14

def ipv4
  raise 'Address familly already scopped' if @af

  @af = :inet
  yield
  @af = nil
end

#ipv6Object

Limit the scope of a set of rules to IPv6 only.



23
24
25
26
27
28
29
# File 'lib/puffy/rule_factory.rb', line 23

def ipv6
  raise 'Address familly already scopped' if @af

  @af = :inet6
  yield
  @af = nil
end