Class: CiscoAclIntp::AccessControlContainer

Inherits:
Object
  • Object
show all
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

AceBase, AceSpecBase, AclBase

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

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object (private)

Generate tagging method dynamically.

Raises:

  • (NoMethodError)


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

.color_modeObject

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

.disable_colorObject

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

#clean_acl_string(str) ⇒ String (private)

acl string clean-up

Parameters:

  • str (String)

    ACL string.

Returns:

  • (String)


90
91
92
# File 'lib/cisco_acl_intp/acc.rb', line 90

def clean_acl_string(str)
  str.strip.gsub(/\s+/, ' ')
end

Generate footer of ACL tag

Returns:

  • (String)

    Tagged string.



65
66
67
68
69
70
71
72
73
74
# File 'lib/cisco_acl_intp/acc.rb', line 65

def generate_tag_footer
  case AccessControlContainer.color_mode
  when :term
    Term::ANSIColor.clear
  when :html
    '</span>'
  else
    ''
  end
end

#generate_tag_header(tag) ⇒ String (private)

Generate header of ACL tag

Parameters:

  • tag (Symbol)

    Tag symbol.

Returns:

  • (String)

    Tagged string.



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

#generate_tagged_str(tag, *args) ⇒ String (private)

Generate tagged ACL string.

Parameters:

  • tag (Symbol)

    Tag symbol.

  • args (Array)

    Array of argments.

Returns:

  • (String)

    Tagged 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 = generate_tag_footer
  [tag_head, tag_body, tag_foot].join
end

#to_sString

This method is abstract.

Generate string for Cisco IOS access list

Returns:

  • (String)

Raises:



28
29
30
# File 'lib/cisco_acl_intp/acc.rb', line 28

def to_s
  raise AclError, 'Not overridden AclContainerBase::to_s'
end