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

#initializeIpGroup

Returns a new instance of IpGroup



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

def initialize
  @addresses = {}
end

Instance Method Details

#add(ip_arg) ⇒ Object

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

Parameters:

  • ip_arg (String)

    IP address as String



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

#include?(remote_addr) ⇒ Boolean

Parameters:

  • remote_addr (IpAddr)

    The IP address of the requester

Returns:

  • (Boolean)


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

#ipsArray

Returns Keys of addresses set

Returns:

  • (Array)

    Keys of addresses set



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

def ips
  @addresses.keys
end