Class: CiscoAclIntp::StandardAce

Inherits:
AceBase show all
Defined in:
lib/cisco_acl_intp/ace_standard.rb

Overview

ACE for standard access list

Direct Known Subclasses

ExtendedAce

Constant Summary

Constants inherited from AceBase

AceBase::NO_SEQ_NUMBER

Constants inherited from AccessControlContainer

AccessControlContainer::TERM_COLOR_TABLE

Instance Attribute Summary collapse

Attributes inherited from AceBase

#seq_number

Instance Method Summary collapse

Methods inherited from AceBase

#<=>, #seq_number?

Methods inherited from AccessControlContainer

#clean_acl_string, disable_color, #generate_tag_footer, #generate_tag_header, #generate_tagged_str, #method_missing

Constructor Details

#initialize(opts) ⇒ StandardAce

Constructor

Parameters:

  • opts (Hash)

    Options

Options Hash (opts):

  • :number (Integer)

    Sequence number

  • :action (String)

    Action (permit/deny)

  • :src (AceSrcDstSpec)

    Source spec object

  • :src (Hash)

    Source spec parmeters

  • :log (AceLogSpec)

    Log spec object

Raises:



28
29
30
31
32
33
34
# File 'lib/cisco_acl_intp/ace_standard.rb', line 28

def initialize(opts)
  super
  @options = opts
  @action = define_action
  @src_spec = define_src_spec
  @log_spec = define_log_spec
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CiscoAclIntp::AccessControlContainer

Instance Attribute Details

#actionString

Parameters:

  • value (String)

    Action

Returns:

  • (String)


9
10
11
# File 'lib/cisco_acl_intp/ace_standard.rb', line 9

def action
  @action
end

#log_specAceLogSpec

Parameters:

Returns:



17
18
19
# File 'lib/cisco_acl_intp/ace_standard.rb', line 17

def log_spec
  @log_spec
end

#src_specAceSrcDstSpec

Parameters:

Returns:



13
14
15
# File 'lib/cisco_acl_intp/ace_standard.rb', line 13

def src_spec
  @src_spec
end

Instance Method Details

#==(other) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/cisco_acl_intp/ace_standard.rb', line 37

def ==(other)
  @action == other.action && @src_spec == other.src_spec
end

#contains?(other) ⇒ Boolean

Search matched ACE

Parameters:

Returns:

  • (Boolean)

    Matched or not



55
56
57
58
# File 'lib/cisco_acl_intp/ace_standard.rb', line 55

def contains?(other)
  other.is_a?(StandardAce) &&
    @src_spec.contains?(other.src_spec)
end

#define_actionString (private)

Set instance variables

Returns:

  • (String)

    Action string

Raises:



65
66
67
68
69
70
71
# File 'lib/cisco_acl_intp/ace_standard.rb', line 65

def define_action
  if @options.key?(:action)
    @options[:action]
  else
    raise AclArgumentError, 'Not specified action'
  end
end

#define_log_specString (private)

Set instance variables

Returns:

  • (String)

    Log spec object

Raises:



95
96
97
# File 'lib/cisco_acl_intp/ace_standard.rb', line 95

def define_log_spec
  @options[:log] || nil
end

#define_src_specAceSrcDstSpec (private)

Set instance variables

Returns:

Raises:



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/cisco_acl_intp/ace_standard.rb', line 76

def define_src_spec
  if @options.key?(:src)
    src = @options[:src]
    case src
    when Hash
      AceSrcDstSpec.new(src)
    when AceSrcDstSpec
      src
    else
      raise AclArgumentError, 'src spec: unknown class'
    end
  else
    raise AclArgumentError, 'Not specified src spec'
  end
end

#to_sString

Generate string for Cisco IOS access list

Returns:

  • (String)


43
44
45
46
47
48
49
50
# File 'lib/cisco_acl_intp/ace_standard.rb', line 43

def to_s
  format(
    '%s %s %s',
    tag_action(@action.to_s),
    @src_spec,
    tag_other_qualifier(@log_spec ? @log_spec : '')
  )
end