Class: CiscoAclIntp::AccessControlContainer
- Inherits:
-
Object
- Object
- CiscoAclIntp::AccessControlContainer
- Defined in:
- lib/cisco_acl_intp/acc.rb
Overview
AccessControlContainer: abstract class of whole elements of ACL. It contains utility functions to stringify element and management status.
Direct Known Subclasses
Constant Summary collapse
- TERM_COLOR_TABLE =
Table of ACL Tag color codes for terminal
{ header: Term::ANSIColor.on_blue, type: Term::ANSIColor.underline, action: Term::ANSIColor.intense_magenta, name: Term::ANSIColor.bold, remark: Term::ANSIColor.blink, ip: [Term::ANSIColor.green, Term::ANSIColor.underline].join, mask: Term::ANSIColor.yellow, protocol: Term::ANSIColor.cyan, port: Term::ANSIColor.cyan, other_qualifier: Term::ANSIColor.green, error: [Term::ANSIColor.red, Term::ANSIColor.bold].join }.freeze
Class Attribute Summary collapse
-
.color_mode ⇒ Object
Color mode: defined as a class instance variable.
Class Method Summary collapse
-
.disable_color ⇒ Object
Disables coloring.
Instance Method Summary collapse
-
#clean_acl_string(str) ⇒ String
private
acl string clean-up.
-
#generate_tag_footer ⇒ String
private
Generate footer of ACL tag.
-
#generate_tag_header(tag) ⇒ String
private
Generate header of ACL tag.
-
#generate_tagged_str(tag, *args) ⇒ String
private
Generate tagged ACL string.
-
#method_missing(name, *args) ⇒ Object
private
Generate tagging method dynamically.
-
#to_s ⇒ String
abstract
Generate string for Cisco IOS access list.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
permalink #method_missing(name, *args) ⇒ Object (private)
Generate tagging method dynamically.
96 97 98 99 100 101 102 103 |
# File 'lib/cisco_acl_intp/acc.rb', line 96 def method_missing(name, *args) name.to_s =~ /^tag_(.+)$/ && tag = Regexp.last_match(1).intern if TERM_COLOR_TABLE.key?(tag) generate_tagged_str(tag, *args) else super end end |
Class Attribute Details
permalink .color_mode ⇒ Object
Color mode: defined as a class instance variable
17 18 19 |
# File 'lib/cisco_acl_intp/acc.rb', line 17 def color_mode @color_mode end |
Class Method Details
permalink .disable_color ⇒ Object
Disables coloring
21 22 23 |
# File 'lib/cisco_acl_intp/acc.rb', line 21 def self.disable_color @color_mode = :none end |
Instance Method Details
permalink #clean_acl_string(str) ⇒ String (private)
acl string clean-up
90 91 92 |
# File 'lib/cisco_acl_intp/acc.rb', line 90 def clean_acl_string(str) str.strip.gsub(/\s+/, ' ') end |
permalink #generate_tag_footer ⇒ String (private)
Generate footer of ACL tag
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/cisco_acl_intp/acc.rb', line 65 def case AccessControlContainer.color_mode when :term Term::ANSIColor.clear when :html '</span>' else '' end end |
permalink #generate_tag_header(tag) ⇒ String (private)
Generate header of ACL tag
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cisco_acl_intp/acc.rb', line 52 def generate_tag_header(tag) case AccessControlContainer.color_mode when :term TERM_COLOR_TABLE[tag] when :html %(<span class="acltag_#{tag}">) else '' end end |
permalink #generate_tagged_str(tag, *args) ⇒ String (private)
Generate tagged ACL string.
80 81 82 83 84 85 |
# File 'lib/cisco_acl_intp/acc.rb', line 80 def generate_tagged_str(tag, *args) tag_head = generate_tag_header(tag) tag_body = args.join tag_foot = [tag_head, tag_body, tag_foot].join end |
permalink #to_s ⇒ String
This method is abstract.
Generate string for Cisco IOS access list
28 29 30 |
# File 'lib/cisco_acl_intp/acc.rb', line 28 def to_s raise AclError, 'Not overridden AclContainerBase::to_s' end |