Class: IPScriptables::Rule
- Inherits:
-
Object
- Object
- IPScriptables::Rule
- Extended by:
- Forwardable
- Defined in:
- lib/ipscriptables/rule.rb,
lib/ipscriptables/pretty_print.rb
Constant Summary collapse
- OPTION_SYNONYMS =
Hashie::Mash[ :p => :protocol, :s => :source, :d => :destination, :j => :jump, :g => :goto, :i => :in_interface, :o => :out_interface, :f => :fragment, :m => :match, :sport => :source_port, :dport => :destination_port, :sports => :source_ports, :dports => :destination_ports ].freeze
Instance Attribute Summary collapse
-
#chain ⇒ Object
readonly
Returns the value of attribute chain.
-
#counters ⇒ Object
readonly
Returns the value of attribute counters.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #=~(other) ⇒ Object
- #[](k) ⇒ Object
-
#initialize(chain, rule, counters = nil) ⇒ Rule
constructor
rubocop:disable MethodLength.
- #inspect ⇒ Object
- #match ⇒ Object
- #original ⇒ Object
- #pretty_print(q) ⇒ Object
- #proto ⇒ Object
- #render ⇒ Object
- #render_counters ⇒ Object
- #target ⇒ Object
Constructor Details
#initialize(chain, rule, counters = nil) ⇒ Rule
rubocop:disable MethodLength
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ipscriptables/rule.rb', line 26 def initialize(chain, rule, counters = nil) # rubocop:disable MethodLength @chain, @rule, @counters = chain, rule, counters @parsed = Hashie::Mash.new @counters ||= original.counters if original @counters ||= [0, 0] if opts[:counters] key = nil Shellwords.shellsplit(rule).each do |word| case word when /^-+(.*)$/ self[key] = true if key key = Regexp.last_match[1].gsub('-', '_') else self[key] = word key = nil end end end |
Instance Attribute Details
#chain ⇒ Object (readonly)
Returns the value of attribute chain.
23 24 25 |
# File 'lib/ipscriptables/rule.rb', line 23 def chain @chain end |
#counters ⇒ Object (readonly)
Returns the value of attribute counters.
23 24 25 |
# File 'lib/ipscriptables/rule.rb', line 23 def counters @counters end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
23 24 25 |
# File 'lib/ipscriptables/rule.rb', line 23 def rule @rule end |
Instance Method Details
#==(other) ⇒ Object
50 51 52 53 |
# File 'lib/ipscriptables/rule.rb', line 50 def ==(other) other = other.rule if other.respond_to?(:rule) rule == other end |
#=~(other) ⇒ Object
72 73 74 |
# File 'lib/ipscriptables/rule.rb', line 72 def =~(other) rule =~ other end |
#[](k) ⇒ Object
55 56 57 58 |
# File 'lib/ipscriptables/rule.rb', line 55 def [](k) k = k.to_s.sub(/^-+/, '').gsub('-', '_') @parsed[OPTION_SYNONYMS.fetch(k, k)] end |
#inspect ⇒ Object
50 51 52 |
# File 'lib/ipscriptables/pretty_print.rb', line 50 def inspect "#<#{self.class} #{render_counters}#{rule}>" end |
#match ⇒ Object
64 65 66 |
# File 'lib/ipscriptables/rule.rb', line 64 def match Array(self[:m]) end |
#original ⇒ Object
46 47 48 |
# File 'lib/ipscriptables/rule.rb', line 46 def original chain.original.find { |rule| rule == self } if chain.original end |
#pretty_print(q) ⇒ Object
54 55 56 |
# File 'lib/ipscriptables/pretty_print.rb', line 54 def pretty_print(q) q.text("#{render_counters}#{rule}") end |
#proto ⇒ Object
60 61 62 |
# File 'lib/ipscriptables/rule.rb', line 60 def proto self[:protocol] end |
#render ⇒ Object
76 77 78 |
# File 'lib/ipscriptables/rule.rb', line 76 def render "#{render_counters}-A #{chain.name} #{rule}" end |
#render_counters ⇒ Object
80 81 82 |
# File 'lib/ipscriptables/rule.rb', line 80 def render_counters "[#{counters.join(':')}] " if counters end |
#target ⇒ Object
68 69 70 |
# File 'lib/ipscriptables/rule.rb', line 68 def target self[:jump] end |