I'm trying to create an array of IP addresses so that when the application is ran Rack-Attack can identify from the set of IP addresses that are allowed to access the application. So what I have done is as followed:
a = "127.0.0.1"
Rack::Attack.blacklist('allow from localhost') do |req|
p "#{'127.0.0.1' == req.ip} "
a != req.ip
end
The above works, so localhost can access the application but I have tried the following below which seems to not work what so ever:
a = "127.0.0.1", "1.2.3.4"
Rack::Attack.blacklist('allow from localhost') do |req|
a.select{|x| x != req.ip}.join("")
end
Can someone explain what the correct way would be to do this. You can see that I create an array. I want Rack::Attack
to detect whether the IP address in the array has access or not.
An efficient way to do this would be to use a Set, a container that's like an array but provides fast lookup on individual, unique elements.
So, rewritten with that in mind:
In your original declaration:
In this case
a
is assigned to the first thing in that list,"x"
, and the rest is ignored.