geoip-rails 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,6 +26,8 @@ See [GitHub issues list](https://github.com/priithaamer/geoip-rails/issues).
26
26
  ## Database schema
27
27
 
28
28
  CREATE DATABASE geoip;
29
+
30
+ USE geoip;
29
31
 
30
32
  CREATE TABLE blocks (
31
33
  ip_poly POLYGON NOT NULL,
@@ -1,9 +1,13 @@
1
1
  module Geoip
2
2
  class Location < Geoip::Base
3
3
 
4
+ IPADDR_REGEX = /^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/
5
+
4
6
  has_many :blocks
5
7
 
6
8
  def self.find_by_ip(ip, &block)
9
+ return nil unless IPADDR_REGEX.match(ip)
10
+
7
11
  location = self.joins(:blocks).where('MBRCONTAINS(ip_poly, POINTFROMWKB(POINT(INET_ATON(?), 0)))', ip).first
8
12
 
9
13
  if location and block_given?
@@ -1,5 +1,5 @@
1
1
  module Geoip
2
2
  module Rails
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geoip-rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Priit Haamer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-26 00:00:00 +03:00
18
+ date: 2011-11-11 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21