Class: Rack::IpRestrictor::IpGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/rack_ip_restrictor/ip_group.rb

Overview

Stores and handles groups of IP's added as String, converted into hash of IpAddr

Instance Method Summary (collapse)

Constructor Details

- (IpGroup) initialize



5
6
7
# File 'lib/rack_ip_restrictor/ip_group.rb', line 5

def initialize
  @addresses = {}
end

Instance Method Details

- (Object) add(ip_arg)

Adds an IP address to the list of addresses as instance of IPAddr



12
13
14
# File 'lib/rack_ip_restrictor/ip_group.rb', line 12

def add(ip_arg)
  @addresses[ip_arg] = IPAddr.new(ip_arg)
end

- (Boolean) include?(remote_addr)



22
23
24
25
26
27
# File 'lib/rack_ip_restrictor/ip_group.rb', line 22

def include?(remote_addr)
  @addresses.each do |key, value|
    return true if value.include? remote_addr
  end
  false
end

- (Array) ips



17
18
19
# File 'lib/rack_ip_restrictor/ip_group.rb', line 17

def ips
  @addresses.keys
end