matryoshka_view 0.2.4 → 0.2.5
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.
- checksums.yaml +4 -4
- data/CHANGELOG +6 -0
- data/lib/matryoshka_view.rb +10 -2
- data/lib/matryoshka_view/version.rb +1 -1
- data/spec/matryoshka_view_spec.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d33a23d2731d7f0e30c137531229374426ed23db
|
|
4
|
+
data.tar.gz: 865d5642e89137fd3c8f429c49c22fe0470e07ef
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 742c33963dc21a4f1352f988bef0b64f314944c30bcead9547ca300c7435786127f3c6234481f6e85744ed1003171c9e7ed1d4ba89c4df4ca5f82b95536bcaaf
|
|
7
|
+
data.tar.gz: 6b1195721ad3cb1e16cbd5e8dd1c0de008058a680644cd080aea4513d3010d080e10246c2adcf298ba0d63374a61f21934e3cfe3a45a16b10ec4c086f763db31
|
data/CHANGELOG
CHANGED
data/lib/matryoshka_view.rb
CHANGED
|
@@ -47,9 +47,17 @@ class MatryoshkaView
|
|
|
47
47
|
def lookup(geom_source: nil, the_geom_geojson: nil)
|
|
48
48
|
# FIXME move to Record class method
|
|
49
49
|
hit = if geom_source
|
|
50
|
-
|
|
50
|
+
with_connection do |c|
|
|
51
|
+
if geom_source.changed?
|
|
52
|
+
Record.where("(the_geom && #{c.quote geom_source.the_geom}) AND ST_Contains(ST_Buffer(the_geom, 0.00001), #{c.quote geom_source.the_geom})").order("ST_Area(the_geom, false) ASC").first
|
|
53
|
+
else
|
|
54
|
+
Record.where("(the_geom && (SELECT the_geom FROM #{geom_source.class.quoted_table_name} WHERE id = #{c.quote(geom_source.id)})) AND ST_Contains(ST_Buffer(the_geom, 0.00001), (SELECT the_geom FROM #{geom_source.class.quoted_table_name} WHERE id = #{c.quote(geom_source.id)}))").order("ST_Area(the_geom, false) ASC").first
|
|
55
|
+
end
|
|
56
|
+
end
|
|
51
57
|
elsif the_geom_geojson
|
|
52
|
-
|
|
58
|
+
with_connection do |c|
|
|
59
|
+
Record.where("the_geom && ST_SetSRID(ST_GeomFromGeoJSON(#{c.quote the_geom_geojson}), 4326) AND ST_Contains(ST_Buffer(the_geom, 0.00001), ST_SetSRID(ST_GeomFromGeoJSON(#{c.quote the_geom_geojson}), 4326))").order("ST_Area(the_geom, false) ASC").first
|
|
60
|
+
end
|
|
53
61
|
else
|
|
54
62
|
raise "expecting geom_source or the_geom_geojson"
|
|
55
63
|
end
|
|
@@ -108,5 +108,17 @@ describe MatryoshkaView do
|
|
|
108
108
|
it_behaves_like 'OK'
|
|
109
109
|
end
|
|
110
110
|
|
|
111
|
+
describe 'with the_geom' do
|
|
112
|
+
let(:burlington) { world.spawn geom_source: place(:burlington) }
|
|
113
|
+
it "tells you what view to use inside boundaries (inclusive)" do
|
|
114
|
+
burlington
|
|
115
|
+
expect(world.lookup(geom_source: place(:burlington_point))).to eq(burlington)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
it "falls back to original table outside boundaries" do
|
|
119
|
+
burlington
|
|
120
|
+
expect(world.lookup(geom_source: place(:montreal_canada))).to eq(world)
|
|
121
|
+
end
|
|
122
|
+
end
|
|
111
123
|
|
|
112
124
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: matryoshka_view
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Seamus Abshere
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2015-05-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|