Class: IpRestriction::IpChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/ip_restriction/ip_checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ranges) ⇒ IpChecker

Returns a new instance of IpChecker.



7
8
9
# File 'lib/ip_restriction/ip_checker.rb', line 7

def initialize(ranges)
  @ranges = ranges
end

Instance Attribute Details

#rangesObject (readonly)

Returns the value of attribute ranges.



5
6
7
# File 'lib/ip_restriction/ip_checker.rb', line 5

def ranges
  @ranges
end

Instance Method Details

#allowed?(ip) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
# File 'lib/ip_restriction/ip_checker.rb', line 11

def allowed?(ip)
  ranges.any? do |range_or_ip|
    IPAddr.new(range_or_ip).include?(IPAddr.new(ip))
  end
end