geoip-rails 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -12,7 +12,12 @@ In your Rails app, `Geoip::Location` model is available. To get the location inf
12
12
 
13
13
  Geoip::Location.find_by_ip('123.123.123.123')
14
14
  # => #<Geoip::Location id: 33447, country: "EE", region: "18", city: "Tartu", postal_code: 0, latitude: 58.3661, longitude: 26.7361, metro_code: 0, area_code: 0>
15
-
15
+
16
+ This method also accepts block that will be called when location is found by given ip address:
17
+
18
+ Geoip::Location.find_by_ip('123.123.123.123') do |location|
19
+ puts "I know that you live in #{location.city}"
20
+ end
16
21
 
17
22
  ## TODO
18
23
 
@@ -3,8 +3,14 @@ module Geoip
3
3
 
4
4
  has_many :blocks
5
5
 
6
- def self.find_by_ip(ip)
7
- self.joins(:blocks).where('MBRCONTAINS(ip_poly, POINTFROMWKB(POINT(INET_ATON(?), 0)))', ip).first
6
+ def self.find_by_ip(ip, &block)
7
+ location = self.joins(:blocks).where('MBRCONTAINS(ip_poly, POINTFROMWKB(POINT(INET_ATON(?), 0)))', ip).first
8
+
9
+ if location and block_given?
10
+ yield location
11
+ else
12
+ location
13
+ end
8
14
  end
9
15
  end
10
16
  end
@@ -1,5 +1,5 @@
1
1
  module Geoip
2
2
  module Rails
3
- VERSION = '0.0.1'
3
+ VERSION = '0.1.1'
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: 29
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 1
10
+ version: 0.1.1
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-20 00:00:00 +03:00
18
+ date: 2011-05-26 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies: []
21
21