Class: Puffy::Formatters::Base::Ruleset

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

Overview

Base class for Puffy Formatter Rulesets

Direct Known Subclasses

Netfilter::Ruleset, Pf::Ruleset

Instance Method Summary collapse

Constructor Details

#initializeRuleset

Returns a new instance of Ruleset.



29
30
31
# File 'lib/puffy/formatters/base.rb', line 29

def initialize
  @rule_formatter = Class.const_get(self.class.name.sub(/set$/, '')).new
end

Instance Method Details

#emit_headerObject



33
34
35
# File 'lib/puffy/formatters/base.rb', line 33

def emit_header
  ["# Generated by puffy v#{Puffy::VERSION} on #{Time.now.strftime('%c')}"]
end

#emit_ruleset(rules, _policy = nil) ⇒ String

Returns a String representation of the provided rules Array of Puffy::Rule with the policy policy.

Parameters:

  • rules (Array<Puffy::Rule>)

    array of Puffy::Rule.

  • _policy (Symbol) (defaults to: nil)

    ruleset policy.

Returns:

  • (String)


42
43
44
# File 'lib/puffy/formatters/base.rb', line 42

def emit_ruleset(rules, _policy = nil)
  rules.collect { |rule| @rule_formatter.emit_rule(rule) }.join("\n")
end

#filename_fragmentArray<String>

Filename for a firewall configuration fragment emitted by the formatter.

Returns:



49
50
51
# File 'lib/puffy/formatters/base.rb', line 49

def filename_fragment
  raise 'Formatters#filename_fragment MUST be overriden'
end