kingpin 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +12 -4
- data/VERSION +1 -1
- data/kingpin.gemspec +1 -1
- data/lib/king_pin.rb +24 -2
- data/lib/pincaster.rb +1 -1
- metadata +4 -4
data/README.markdown
CHANGED
@@ -59,11 +59,11 @@ Integration
|
|
59
59
|
-----------
|
60
60
|
|
61
61
|
Integration into you models is straight forward. Assuming that your model has an attribute_reader or accessor_method like one of the following:
|
62
|
-
[:latitude, :ltt, :ltd, :lat]
|
62
|
+
[:latitude, :lati, :ltt, :ltd, :lat, :lttd]
|
63
63
|
|
64
64
|
as well as one of the following for longitude:
|
65
65
|
|
66
|
-
[:longitude, :long, :lng, :lgt, :
|
66
|
+
[:longitude, :long, :lng, :lgt, :lgtd, :lngtd]
|
67
67
|
|
68
68
|
**and** the values are in *DEG* **not** *RAD*, your way of integration looks like that:
|
69
69
|
|
@@ -78,7 +78,7 @@ Either way, Kingpin tries to minimize your pain, so some configuration options a
|
|
78
78
|
* `:methods => {:lat => :your_latitude, :lng => :your_longitude}` in case your location accessors have different names
|
79
79
|
* `:rad => true` defaults to *false* if not mentioned, and assumes your lat and lng in *RAD* instead of *DEG*
|
80
80
|
* `:autopin => true` automatically generates a Pincaster record every time an instance of an enabled model is saved
|
81
|
-
* `:include => [
|
81
|
+
* `:include => :all | {:only => [:attr_1, :attr_2, ...]} | {:except => [:attr_1, :attr_2, ...]}`
|
82
82
|
|
83
83
|
Example: In case your longitude resides at :cool_longitude, your latitude at :cool_latitude, the values are stored in *RAD* and you would like to automatically create Pincaster pins, your classes head should look like this:
|
84
84
|
|
@@ -87,6 +87,15 @@ Example: In case your longitude resides at :cool_longitude, your latitude at :co
|
|
87
87
|
...
|
88
88
|
end
|
89
89
|
|
90
|
+
In case you would like to integrate the instances values for :name and :title only into the pin, your class definition looked like that:
|
91
|
+
|
92
|
+
class FooWithLocation
|
93
|
+
pinnable :include => {:only => [:name, :title]}
|
94
|
+
...
|
95
|
+
end
|
96
|
+
|
97
|
+
Vice versa `:include => {:except => [:name, :title]}` would integrate all attributes but :name and :title, `:include => :all` integrated all available attributes of the instance.
|
98
|
+
|
90
99
|
Indexing
|
91
100
|
--------
|
92
101
|
|
@@ -189,7 +198,6 @@ Coming soon
|
|
189
198
|
Kingpin is missing some functionality yet, but this will arrive soon:
|
190
199
|
|
191
200
|
- support for rectangle search
|
192
|
-
- support for storage of optional AR attributes of an instance via include
|
193
201
|
- distance integration into every returned AR record at retrieval time
|
194
202
|
- automated Raketask for index creation
|
195
203
|
- tests
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/kingpin.gemspec
CHANGED
data/lib/king_pin.rb
CHANGED
@@ -50,7 +50,7 @@ module KingpinInstanceMethods
|
|
50
50
|
# returns objects longitude depending on configured method name for access as well as DEG or RAD configuration
|
51
51
|
def pin_lng
|
52
52
|
if not !!self.class.kingpin_args[:methods]
|
53
|
-
[:longitude, :long, :lng, :lgt, :
|
53
|
+
[:longitude, :long, :lng, :lgt, :lgtd, :lngtd].each do |l|
|
54
54
|
if self.respond_to?(l)
|
55
55
|
return !!self.class.kingpin_args[:rad] ? self.send(l).to_f * 180 / Math::PI : self.send(l)
|
56
56
|
end
|
@@ -64,7 +64,7 @@ module KingpinInstanceMethods
|
|
64
64
|
# returns objects latitude depending on configured method name for access as well as DEG or RAD configuration
|
65
65
|
def pin_lat
|
66
66
|
if not !!self.class.kingpin_args[:methods]
|
67
|
-
[:latitude, :lati, :ltt, :ltd, :lat].each do |l|
|
67
|
+
[:latitude, :lati, :ltt, :ltd, :lat, :lttd].each do |l|
|
68
68
|
if self.respond_to?(l)
|
69
69
|
return !!self.class.kingpin_args[:rad] ? self.send(l).to_f * 180 / Math::PI : self.send(l)
|
70
70
|
end
|
@@ -80,6 +80,28 @@ module KingpinInstanceMethods
|
|
80
80
|
self.add_pin
|
81
81
|
end
|
82
82
|
|
83
|
+
# returns additional attributes of self that shall be included into the pin
|
84
|
+
def additional_attributes
|
85
|
+
return {} unless !!self.class.kingpin_args[:include]
|
86
|
+
case self.class.kingpin_args[:include].class.to_s
|
87
|
+
when "Symbol"
|
88
|
+
raise ":all is the only stand alone symbol that is allowed with :include" unless self.class.kingpin_args[:include] == :all
|
89
|
+
self.attributes
|
90
|
+
when "Hash"
|
91
|
+
if self.class.kingpin_args[:include].size > 1 or not [:only, :except].include? self.class.kingpin_args[:include].first.first
|
92
|
+
raise ":include supports :only => [:foo, :bar] and :except => [:scooby, :doo] only"
|
93
|
+
end
|
94
|
+
case self.class.kingpin_args[:include].first.first
|
95
|
+
when :only
|
96
|
+
self.attributes.delete_if{ |name, value| !self.class.kingpin_args[:include].first[1].include?(name.to_sym) }
|
97
|
+
when :except
|
98
|
+
self.attributes.delete_if{ |name, value| self.class.kingpin_args[:include].first[1].include?(name.to_sym) }
|
99
|
+
end
|
100
|
+
else
|
101
|
+
raise ":include needs :all, {:only => [:foo, :bar]} or {:except => [:scooby, :doo]}"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
83
105
|
end
|
84
106
|
|
85
107
|
###
|
data/lib/pincaster.rb
CHANGED
@@ -67,7 +67,7 @@ class Pincaster
|
|
67
67
|
"/records/#{record.class.to_s}/#{record.id}.json",
|
68
68
|
nil,
|
69
69
|
nil,
|
70
|
-
{:_loc => "#{record.pin_lat},#{record.pin_lng}"}).code == "200" ? true : false
|
70
|
+
{:_loc => "#{record.pin_lat},#{record.pin_lng}"}.merge(record.additional_attributes)).code == "200" ? true : false
|
71
71
|
end
|
72
72
|
|
73
73
|
# returns a pin object for the given ActiveRecord object
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kingpin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 7
|
9
|
+
- 0
|
10
|
+
version: 0.7.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jan Roesner
|