Class: Baykit::BayServer::Util::IpMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/baykit/bayserver/util/ip_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip_desc) ⇒ IpMatcher

Returns a new instance of IpMatcher.



8
9
10
11
12
13
14
# File 'lib/baykit/bayserver/util/ip_matcher.rb', line 8

def initialize(ip_desc)
  @match_all = (ip_desc == "*")

  if !@match_all
    parse_cidr(ip_desc)
  end
end

Instance Attribute Details

#cidr_ipObject (readonly)

Returns the value of attribute cidr_ip.



6
7
8
# File 'lib/baykit/bayserver/util/ip_matcher.rb', line 6

def cidr_ip
  @cidr_ip
end

#match_allObject (readonly)

Returns the value of attribute match_all.



5
6
7
# File 'lib/baykit/bayserver/util/ip_matcher.rb', line 5

def match_all
  @match_all
end

Instance Method Details

#match(ip) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/baykit/bayserver/util/ip_matcher.rb', line 16

def match(ip)
  BayLog.debug("match_ip %s net=%s mask=%s", ip, @net_addr, @mask_addr)
  if @match_all
    return true
  else
    return @cidr_ip.include?(ip)
  end
end