the_geom_geojson 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9b923b316a16ae77ca598e803b10757e992adba8
4
- data.tar.gz: e70e6840959521ef9375a61754d4290105cf4faa
3
+ metadata.gz: fc02ba580ac039493fc7228507036db38174680d
4
+ data.tar.gz: a2516ef9680f359defc7656ac113cacf8a43033c
5
5
  SHA512:
6
- metadata.gz: 017a2f05ac92ad2d8722896f613f39066c77b95c445ad844c987a85c2705aa136e0510698112aa606bc29480de947357f2eb4a718c94c86a922fafefe29d1485
7
- data.tar.gz: 247a8189a55c71b300e2b8f568c026302dda564da710e9bf2d6d839495bd51231a91a4ebf6f5058f5c2934415177350ab69bde16579e91aa3794e60566eed6f1
6
+ metadata.gz: 9a1ca14c7a817883c4f1f2576e1915f8392925c49bf59c4cca56db60676bb19e3e54974caa5151a200563653f133f6cbd24f429776eb434e7827ffa41e83f56e
7
+ data.tar.gz: 8c4c00f3e442d4d1473a864302d1564838b16ef29b92b37a2a881710cbb67b7ee48bddcb709eebb3a81619c004c58f0334f5a5aec57d5c275f5b2a04ed75b299
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 0.0.2 / 2014-07-22
2
+
3
+ * Enhancements
4
+
5
+ * Support alternate primary keys set on ActiveRecord with `self.primary_key = X`
6
+
1
7
  0.0.1 / 2014-07-17
2
8
 
3
9
  initial release!
data/README.md CHANGED
@@ -6,6 +6,8 @@ For PostGIS/PostgreSQL and ActiveRecord, provides `the_geom_geojson` getter and
6
6
 
7
7
  Web mapping libraries like [Leaflet](http://leafletjs.com/) often don't support PostGIS's native [Well-Known Binary (WKB) and Well-Known Text (WKT)](http://postgis.net/docs/using_postgis_dbmanagement.html#OpenGISWKBWKT) representation, but they do support [GeoJSON](http://geojson.org/), so this library helps translate between the two.
8
8
 
9
+ <img src="https://www.nyu.edu/greyart/exhibits/cisneros/images/garcianew.jpg" alt="Composición constructiva 16" />
10
+
9
11
  ## Requirements
10
12
 
11
13
  * [PostgreSQL](postgresql.org) >=9
@@ -27,7 +27,7 @@ module TheGeomGeoJSON
27
27
  memo << 'the_geom = ST_SetSRID(ST_GeomFromGeoJSON(?), 4326)' if has_the_geom
28
28
  memo << ',' if has_the_geom && has_the_geom_webmercator
29
29
  memo << 'the_geom_webmercator = ST_Transform(ST_SetSRID(ST_GeomFromGeoJSON(?), 4326), 3857)' if has_the_geom_webmercator
30
- memo << ' WHERE id = ?'
30
+ memo << " WHERE #{model.quoted_primary_key} = ?"
31
31
  memo.join.freeze
32
32
  end)
33
33
  model.send :sanitize_sql_array, [sql, the_geom_geojson, the_geom_geojson, id]
@@ -48,7 +48,7 @@ module TheGeomGeoJSON
48
48
  @the_geom_geojson_change
49
49
  elsif id
50
50
  self.class.connection_pool.with_connection do |c|
51
- c.select_value "SELECT ST_AsGeoJSON(the_geom) FROM #{self.class.quoted_table_name} WHERE id = #{c.quote(id)} LIMIT 1"
51
+ c.select_value "SELECT ST_AsGeoJSON(the_geom) FROM #{self.class.quoted_table_name} WHERE #{self.class.quoted_primary_key} = #{c.quote(id)} LIMIT 1"
52
52
  end
53
53
  end
54
54
  end
@@ -1,3 +1,3 @@
1
1
  module TheGeomGeoJSON
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -5,10 +5,16 @@ unless ENV['FAST'] == 'true'
5
5
  system 'dropdb', '--if-exists', dbname
6
6
  system 'createdb', dbname
7
7
  system 'psql', dbname, '--command', 'CREATE EXTENSION postgis'
8
+ system 'psql', dbname, '--command', 'CREATE EXTENSION "uuid-ossp"'
8
9
  system 'psql', dbname, '--command', 'CREATE TABLE pets (id serial primary key, the_geom geometry(Geometry,4326), the_geom_webmercator geometry(Geometry,3857))'
10
+ system 'psql', dbname, '--command', 'CREATE TABLE pet_alt_ids (alt_id serial primary key, the_geom geometry(Geometry,4326), the_geom_webmercator geometry(Geometry,3857))'
11
+ system 'psql', dbname, '--command', 'CREATE TABLE pet_text_ids (id text unique not null, the_geom geometry(Geometry,4326), the_geom_webmercator geometry(Geometry,3857))'
12
+ system 'psql', dbname, '--command', 'CREATE TABLE pet_uuids (id uuid unique not null, the_geom geometry(Geometry,4326), the_geom_webmercator geometry(Geometry,3857))'
13
+ system 'psql', dbname, '--command', 'CREATE TABLE pet_auto_uuids (id uuid unique not null default uuid_generate_v4(), the_geom geometry(Geometry,4326), the_geom_webmercator geometry(Geometry,3857))'
9
14
  end
10
15
 
11
16
  require 'active_record'
17
+ require 'securerandom'
12
18
 
13
19
  ActiveRecord::Base.establish_connection "postgresql://127.0.0.1/#{dbname}"
14
20
 
@@ -22,6 +28,30 @@ class Pet < ActiveRecord::Base
22
28
  include TheGeomGeoJSON::ActiveRecord
23
29
  end
24
30
 
31
+ class PetAltId < ActiveRecord::Base
32
+ include TheGeomGeoJSON::ActiveRecord
33
+ self.primary_key = 'alt_id'
34
+ end
35
+
36
+ class PetTextId < ActiveRecord::Base
37
+ include TheGeomGeoJSON::ActiveRecord
38
+ self.primary_key = 'id'
39
+ end
40
+
41
+ class PetUuid < ActiveRecord::Base
42
+ include TheGeomGeoJSON::ActiveRecord
43
+ self.primary_key = 'id'
44
+ end
45
+
46
+ class PetAutoUuid < ActiveRecord::Base
47
+ include TheGeomGeoJSON::ActiveRecord
48
+ self.primary_key = 'id'
49
+
50
+ before_save do
51
+ self.id ||= SecureRandom.uuid
52
+ end
53
+ end
54
+
25
55
  if ENV['PRY'] == 'true'
26
56
  require 'pry'
27
57
  require 'logger'
@@ -61,43 +91,95 @@ describe TheGeomGeoJSON do
61
91
  end
62
92
  end
63
93
 
64
- describe "creating" do
65
- before do
66
- @pet = Pet.create! the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:burlington_point]
94
+ shared_examples 'different states of persistence' do
95
+ describe "creating" do
96
+ before do
97
+ @pet = create_pet the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:burlington_point]
98
+ end
99
+ it_behaves_like 'the_geom_geojson=(geojson)'
100
+ end
101
+
102
+ describe "building and saving" do
103
+ before do
104
+ @pet = build_pet the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:burlington_point]
105
+ @pet.save!
106
+ end
107
+ it_behaves_like 'the_geom_geojson=(geojson)'
67
108
  end
68
- it_behaves_like 'the_geom_geojson=(geojson)'
109
+
110
+ describe "modifying" do
111
+ before do
112
+ @pet = create_pet
113
+ @pet.the_geom_geojson = TheGeomGeoJSON::EXAMPLES[:burlington_point]
114
+ @pet.save!
115
+ end
116
+ it_behaves_like 'the_geom_geojson=(geojson)'
117
+ end
118
+
119
+ describe "building (without saving)" do
120
+ before do
121
+ @pet = build_pet the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:burlington_point]
122
+ end
123
+ it "raises exception if you try to access the_geom" do
124
+ expect{@pet.the_geom}.to raise_error(TheGeomGeoJSON::Dirty)
125
+ end
126
+ it "raises exception if you try to access the_geom_webmercator" do
127
+ expect{@pet.the_geom_webmercator}.to raise_error(TheGeomGeoJSON::Dirty)
128
+ end
129
+ it "lets you access the_geom_geojson" do
130
+ expect(@pet.the_geom_geojson).to eq(TheGeomGeoJSON::EXAMPLES[:burlington_point])
131
+ end
132
+ end
133
+ end
134
+
135
+ describe "with autoincrement id" do
136
+ def create_pet(attrs = {})
137
+ Pet.create! attrs
138
+ end
139
+ def build_pet(attrs = {})
140
+ Pet.new attrs
141
+ end
142
+ it_behaves_like 'different states of persistence'
69
143
  end
70
144
 
71
- describe "building and saving" do
72
- before do
73
- @pet = Pet.new the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:burlington_point]
74
- @pet.save!
145
+ describe "with alt id" do
146
+ def create_pet(attrs = {})
147
+ PetAltId.create! attrs
148
+ end
149
+ def build_pet(attrs = {})
150
+ PetAltId.new attrs
75
151
  end
76
- it_behaves_like 'the_geom_geojson=(geojson)'
152
+ it_behaves_like 'different states of persistence'
77
153
  end
78
154
 
79
- describe "modifying" do
80
- before do
81
- @pet = Pet.create!
82
- @pet.the_geom_geojson = TheGeomGeoJSON::EXAMPLES[:burlington_point]
83
- @pet.save!
155
+ describe "with auto-generating uuid" do
156
+ def create_pet(attrs = {})
157
+ PetAutoUuid.create! attrs
84
158
  end
85
- it_behaves_like 'the_geom_geojson=(geojson)'
159
+ def build_pet(attrs = {})
160
+ PetAutoUuid.new attrs
161
+ end
162
+ it_behaves_like 'different states of persistence'
86
163
  end
87
164
 
88
- describe "building (without saving)" do
89
- before do
90
- @pet = Pet.new the_geom_geojson: TheGeomGeoJSON::EXAMPLES[:burlington_point]
165
+ describe "with text id" do
166
+ def create_pet(attrs = {})
167
+ PetTextId.create! attrs.reverse_merge(id: rand.to_s)
91
168
  end
92
- it "raises exception if you try to access the_geom" do
93
- expect{@pet.the_geom}.to raise_error(TheGeomGeoJSON::Dirty)
169
+ def build_pet(attrs = {})
170
+ PetTextId.new attrs.reverse_merge(id: rand.to_s)
94
171
  end
95
- it "raises exception if you try to access the_geom_webmercator" do
96
- expect{@pet.the_geom_webmercator}.to raise_error(TheGeomGeoJSON::Dirty)
172
+ it_behaves_like 'different states of persistence'
173
+ end
174
+
175
+ describe "with uuid id" do
176
+ def create_pet(attrs = {})
177
+ PetUuid.create! attrs.reverse_merge(id: SecureRandom.uuid)
97
178
  end
98
- it "lets you access the_geom_geojson" do
99
- expect(@pet.the_geom_geojson).to eq(TheGeomGeoJSON::EXAMPLES[:burlington_point])
179
+ def build_pet(attrs = {})
180
+ PetUuid.new attrs.reverse_merge(id: SecureRandom.uuid)
100
181
  end
182
+ it_behaves_like 'different states of persistence'
101
183
  end
102
184
 
103
185
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_geom_geojson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-18 00:00:00.000000000 Z
11
+ date: 2014-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord