rgeo-activerecord-dschee 5.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1878a64950dfeca28535eda8b6599aa717d685c9
4
+ data.tar.gz: 81267038dfbb7ecc3e19ecdf6df1c29a51e7b572
5
+ SHA512:
6
+ metadata.gz: 21023f0ae7931de711cca2e2d780a6ea686348c1a7e4e72cc6fbf667f3dbaabc1de5ebbc36783da102994c516daf8534e1e5baddaf2480d60e6f7befead97085
7
+ data.tar.gz: b144106f54dc3c7fd9c2ee56eb614f9cd030988187a803851a9e7ad7f3f91e5f12f1a0242208ba390472a7bd748ed763cc6ff71c6c1e630d1aac754029d85fa3
@@ -0,0 +1,207 @@
1
+ ### 4.0.5 / 2015-12-29
2
+
3
+ * Fix #geometric_type_from_name for :geometrycollection
4
+
5
+ ### 4.0.4 / 2015-12-29
6
+
7
+ * Restore rgeo/active_record.rb
8
+
9
+ ### 4.0.3 / 2015-12-28
10
+
11
+ * Fix json parser for rgeo-geojson 0.4.0+
12
+
13
+ ### 4.0.2 / 2015-12-28
14
+
15
+ * Remove unnecessary root namespacing
16
+ * Remove unnecessary namespace qualifiers
17
+ * Remove rgeo/active_record.rb
18
+
19
+ ### 4.0.1 / 2015-12-25
20
+
21
+ * Rubocop style cleanup #31
22
+ * Do not distribute test files with gem
23
+
24
+ ### 4.0.0 / 2015-05-24
25
+
26
+ * Remove GeoTableDefinitions, GeoConnectionAdapter
27
+
28
+ ### 3.0.0 / 2015-05-09
29
+
30
+ * Remove AdapterTestHelper module
31
+ * Remove RGeoFactorySettings
32
+ * Remove #set_rgeo_factory_for_column, #rgeo_factory_for_column, etc
33
+ * Add SpatialFactoryStore (see https://github.com/rgeo/rgeo-activerecord/commit/b1da5cb222)
34
+
35
+ ### 2.1.1 / 2015-03-18
36
+
37
+ * Fix collector calls for arel 6.0 API
38
+
39
+ ### 2.1.0 / 2015-02-07
40
+
41
+ * Update visit API for arel 6.0
42
+ * Remove attribute caching (removed in AR 4.2)
43
+ * Remove support for `spatial: true` index option (use standard `using: :gist`)
44
+
45
+ ### 2.0.0 / 2014-12-02
46
+
47
+ * Dump schema using new style hash - https://github.com/rgeo/rgeo-activerecord/pull/18
48
+ * Require ActiveRecord 4.2
49
+
50
+ ### 1.2.0 / 2014-08-21
51
+
52
+ * Support ActiveRecord 4.2
53
+
54
+ ### 1.1.0 / 2014-06-17
55
+
56
+ * Relax rgeo gem dependency
57
+
58
+ ### 1.0.0 / 2014-05-06
59
+
60
+ * Require ruby 1.9.3+
61
+ * Require ActiveRecord 4+
62
+ * General refactoring and cleanup
63
+
64
+ ### 0.6.0 / 2014-05-06
65
+
66
+ * Support Rails 4, Arel 4
67
+
68
+ ### 0.5.0 / 2013-02-27
69
+
70
+ * No changes. Rereleased as 0.5.0 final.
71
+
72
+
73
+ ### 0.5.0.beta2 / 2013-02-04
74
+
75
+ * Revert change made to SpatialIndexDefinition in beta1.
76
+ * Fix some deprecations in the post-test cache cleanup.
77
+
78
+
79
+ ### 0.5.0.beta1 / 2013-02-04
80
+
81
+ * Updates for compatibility with Rails 4 and support of Rails 4 oriented
82
+ adapters.
83
+ * Testing tool is better factored to allow customization of cleanup
84
+
85
+
86
+ ### 0.4.6 / 2012-12-11
87
+
88
+ * You can now provide both a default and an override database config file in
89
+ the test helper.
90
+ * The gemspec no longer includes the timestamp in the version, so that
91
+ bundler can pull from github. (Reported by corneverbruggen)
92
+
93
+
94
+ ### 0.4.5 / 2012-04-13
95
+
96
+ * Task hacker failed ungracefully when attempting to hack a nonexistent
97
+ task. Fixed.
98
+
99
+
100
+ ### 0.4.4 / 2012-04-12
101
+
102
+ * Support cartesian bounding boxes in queries.
103
+
104
+
105
+ ### 0.4.3 / 2012-02-22
106
+
107
+ * Some fixes for Rails 3.2 compatibility.
108
+
109
+
110
+ ### 0.4.2 / 2012-01-09
111
+
112
+ * Added an "rgeo-activerecord.rb" wrapper so bundler's auto-require will
113
+ work without modification. (Reported by Mauricio Pasquier Juan.)
114
+ * Fixed unit tests so they actually pass...
115
+
116
+
117
+ ### 0.4.1 / 2011-10-26
118
+
119
+ * Fixed wrong variable name crash in rgeo_factory_for_column (patch by Andy
120
+ Allan).
121
+
122
+
123
+ ### 0.4.0 / 2011-08-15
124
+
125
+ * Several compatibility fixes for Rails 3.1.
126
+ * Revamped factory setter mechanism with a system that should be more
127
+ robust.
128
+ * Some general code cleanup.
129
+
130
+
131
+ ### 0.3.4 / 2011-05-23
132
+
133
+ * Uses the mixin feature of RGeo 0.3 to add an as_json method to all
134
+ geometry objects. This should allow ActiveRecord's JSON serialization to
135
+ function for models with geometry fields. (Reported by thenetduck and
136
+ tonyc on github.)
137
+
138
+
139
+ ### 0.3.3 / 2011-04-11
140
+
141
+ * A .gemspec file is now available for gem building and bundler git
142
+ integration.
143
+
144
+
145
+ ### 0.3.2 / 2011-02-28
146
+
147
+ * Fixed a bug that sometimes caused spatial column detection to fail, which
148
+ could result in exceptions or incorrect spatial queries.
149
+
150
+
151
+ ### 0.3.1 / 2011-02-28
152
+
153
+ * Fixed a bug that could cause some spatial ActiveRecord adapters to fail to
154
+ create multiple spatial columns in a migration.
155
+
156
+
157
+ ### 0.3.0 / 2011-01-26
158
+
159
+ * Experimental support for complex spatial queries. (Requires Arel 2.1,
160
+ which is expected to be released with Rails 3.1.) Currently, only a
161
+ low-level Arel-based interface is supported.
162
+ * Better support for geography types in PostGIS.
163
+ * Adapters can now define additional column constructors.
164
+ * Support for spatial column constructors on change_table.
165
+ * Fixed column type inference for some cases where the column included Z
166
+ and/or M.
167
+ * IS NULL predicates now work properly with spatial types.
168
+ * Preferred attribute type is now :spatial rather than :geometry.
169
+ * The gem version is now accessible via an api.
170
+ * Some code reorganization.
171
+
172
+
173
+ ### 0.2.4 / 2011-01-13
174
+
175
+ * Fixed a problem that caused a hang during rake db:rollback, as well as
176
+ probably certain other functions that use ActiveRecord::Base directly
177
+ rather than a subclass. (Reported by Alexander Graefe.)
178
+
179
+
180
+ ### 0.2.3 / 2011-01-07
181
+
182
+ * Updated gem dependencies to include Arel 2.0.6, since some earlier Arel
183
+ versions weren't working. (Reported by Pirmin Kalberer.)
184
+
185
+
186
+ ### 0.2.2 / 2011-01-06
187
+
188
+ * Some adjustments to the Arel integration for future Arel compatibility.
189
+ (Thanks to Aaron Patterson.)
190
+ * Support code for hacking ActiveRecord's rake tasks.
191
+
192
+
193
+ ### 0.2.1 / 2010-12-27
194
+
195
+ * Support for RGeo features as nodes in the Arel AST.
196
+ * Basic utility Arel visitor methods for handling spatial equality nodes in
197
+ where-expressions.
198
+
199
+
200
+ ### 0.2.0 / 2010-12-07
201
+
202
+ * Initial public alpha release. Spun rgeo-activerecord off from the core
203
+ rgeo gem.
204
+ * Support for setting factory by column.
205
+
206
+
207
+ For earlier history, see the History file for the rgeo gem.
@@ -0,0 +1,29 @@
1
+ # -----------------------------------------------------------------------------
2
+ # Copyright 2010-2012 Daniel Azuma
3
+ #
4
+ # All rights reserved.
5
+ #
6
+ # Redistribution and use in source and binary forms, with or without
7
+ # modification, are permitted provided that the following conditions are met:
8
+ #
9
+ # * Redistributions of source code must retain the above copyright notice,
10
+ # this list of conditions and the following disclaimer.
11
+ # * Redistributions in binary form must reproduce the above copyright notice,
12
+ # this list of conditions and the following disclaimer in the documentation
13
+ # and/or other materials provided with the distribution.
14
+ # * Neither the name of the copyright holder, nor the names of any other
15
+ # contributors to this software, may be used to endorse or promote products
16
+ # derived from this software without specific prior written permission.
17
+ #
18
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
+ # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22
+ # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23
+ # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
+ # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
+ # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
+ # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
+ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
+ # POSSIBILITY OF SUCH DAMAGE.
29
+ # -----------------------------------------------------------------------------
@@ -0,0 +1,121 @@
1
+ ## RGeo::ActiveRecord
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/rgeo-activerecord.svg)](http://badge.fury.io/rb/rgeo-activerecord)
4
+ [![Build Status](https://travis-ci.org/rgeo/rgeo-activerecord.svg?branch=master)](https://travis-ci.org/rgeo/rgeo-activerecord)
5
+ [![Code Climate](https://codeclimate.com/github/rgeo/rgeo-activerecord.png)](https://codeclimate.com/github/rgeo/rgeo-activerecord)
6
+
7
+ RGeo::ActiveRecord is an optional [RGeo](http://github.com/dazuma/rgeo) module
8
+ providing spatial extensions for ActiveRecord, as well as a set of helpers for
9
+ writing spatial ActiveRecord adapters based on RGeo.
10
+
11
+ ### Summary
12
+
13
+ RGeo is a key component for writing location-aware applications in the Ruby
14
+ programming language. At its core is an implementation of the industry
15
+ standard OGC Simple Features Specification, which provides data
16
+ representations of geometric objects such as points, lines, and polygons,
17
+ along with a set of geometric analysis operations. See the README for the
18
+ "rgeo" gem for more information.
19
+
20
+ RGeo::ActiveRecord is an optional RGeo add-on module providing spatial
21
+ extensions for ActiveRecord, as well as a set of helpers for writing spatial
22
+ ActiveRecord adapters based on RGeo.
23
+
24
+ ### Installation
25
+
26
+ Gemfile:
27
+
28
+ ```ruby
29
+ gem 'rgeo-activerecord'
30
+ ```
31
+
32
+ `rgeo-activerecord` has the following requirements:
33
+
34
+ * Ruby 1.9.3 or later
35
+ * rgeo 0.3.20 or later.
36
+
37
+ The latest version supports ActiveRecord 4.2 and later.
38
+
39
+ Version `1.1.0` supports ActiveRecord 4.0 and 4.1
40
+
41
+ Version `0.6.0` supports earlier versions of ruby and ActiveRecord:
42
+
43
+ * Ruby 1.8.7 or later
44
+ * ActiveRecord 3.0.3 - 3.2.x
45
+ * rgeo 0.3.20 or later
46
+ * arel 2.0.6 or later
47
+
48
+ ### Spatial Factories for Columns
49
+
50
+ `rgeo_factory_generator` and related methods were removed in version 4.0, since column types
51
+ are no longer tied to their database column in ActiveRecord 4.2.
52
+
53
+ Register spatial factories in the `SpatialFactoryStore` singleton class. Each spatial type
54
+ in your ActiveRecord models will use the `SpatialFactoryStore` to retrieve
55
+ a factory matching the properties of its type. For example, you can set a different
56
+ spatial factory for point types, or for types matching a specific SRID, or having
57
+ a Z coordinate, or any combination of attributes.
58
+
59
+ The supported keys when registering a spatial type are listed here with their default values
60
+ and other allowed values:
61
+
62
+ ```
63
+ geo_type: "geometry", # point, polygon, line_string, geometry_collection,
64
+ # multi_line_string, multi_point, multi_polygon
65
+ has_m: false, # true
66
+ has_z: false, # true
67
+ sql_type: "geometry", # geography
68
+ srid: 0, # (any valid SRID)
69
+ ```
70
+
71
+ The default factories are `RGeo::Geographic.spherical_factory` for
72
+ geographic types, and `RGeo::Cartesian.preferred_factory` for geometric types.
73
+
74
+ Here is an example setup:
75
+
76
+ ```ruby
77
+ RGeo::ActiveRecord::SpatialFactoryStore.instance.tap do |config|
78
+ # By default, use the GEOS implementation for spatial columns.
79
+ config.default = RGeo::Geos.factory_generator
80
+
81
+ # But use a geographic implementation for point columns.
82
+ config.register(RGeo::Geographic.spherical_factory(srid: 4326), geo_type: "point")
83
+ end
84
+ ```
85
+
86
+ ### RGeo Dependency
87
+
88
+ See the README for the [rgeo](https://github.com/rgeo/rgeo) gem, a dependency, for further
89
+ installation information.
90
+
91
+ ### Development and support
92
+
93
+ This README is the official documentation.
94
+
95
+ RDoc documentation is available at http://rdoc.info/gems/rgeo-activerecord
96
+
97
+ Source code is hosted on Github at http://github.com/rgeo/rgeo-activerecord
98
+
99
+ Contributions are welcome. Fork the project on Github.
100
+
101
+ Report bugs on Github issues at
102
+ http://github.com/rgeo/rgeo-activerecord/issues
103
+
104
+ Support available on the rgeo-users google group at
105
+ http://groups.google.com/group/rgeo-users
106
+
107
+ ### Acknowledgments
108
+
109
+ [Daniel Azuma](http://www.daniel-azuma.com) created RGeo.
110
+ [Tee Parham](http://twitter.com/teeparham) is the current maintainer.
111
+
112
+ Development is supported by:
113
+
114
+ * [Pirq](http://pirq.com)
115
+ * [Neighborland](https://neighborland.com)
116
+
117
+ ### License
118
+
119
+ Copyright 2015 Daniel Azuma, Tee Parham
120
+
121
+ https://github.com/rgeo/rgeo-activerecord/blob/master/LICENSE.txt
@@ -0,0 +1 @@
1
+ require "rgeo/active_record"
@@ -0,0 +1,8 @@
1
+ require "rgeo"
2
+ require "active_record"
3
+ require "rgeo/active_record/version"
4
+ require "rgeo/active_record/spatial_expressions"
5
+ require "rgeo/active_record/spatial_factory_store"
6
+ require "rgeo/active_record/arel_spatial_queries"
7
+ require "rgeo/active_record/common_adapter_elements"
8
+ require "rgeo/active_record/geometry_mixin"
@@ -0,0 +1,120 @@
1
+ module RGeo
2
+ module ActiveRecord
3
+ # A set of common Arel visitor hacks for spatial ToSql visitors.
4
+ # Generally, a spatial ActiveRecord adapter should provide a custom
5
+ # ToSql Arel visitor that includes and customizes this module.
6
+ # See the existing spatial adapters (i.e. postgis, spatialite,
7
+ # mysqlspatial, and mysql2spatial) for usage examples.
8
+
9
+ module SpatialToSql
10
+ # Map a standard OGC SQL function name to the actual name used by
11
+ # a particular database. This method should take a name and
12
+ # return either the changed name or the original name.
13
+
14
+ def st_func(standard_name)
15
+ standard_name
16
+ end
17
+
18
+ # Visit the SpatialNamedFunction node. This operates similarly to
19
+ # the standard NamedFunction node, but it performs function name
20
+ # mapping for the database, and it also uses the type information
21
+ # in the node to determine when to cast string arguments to WKT,
22
+
23
+ def visit_RGeo_ActiveRecord_SpatialNamedFunction(node, collector)
24
+ name = st_func(node.name)
25
+ exprs = []
26
+ node.expressions.each_with_index do |expr, index|
27
+ exprs << (node.spatial_argument?(index) ? visit_in_spatial_context(expr, collector) : visit(expr, collector))
28
+ end
29
+ collector << name
30
+ collector << "("
31
+ collector << "DISTINCT " if node.distinct
32
+ collector << exprs.join(", ")
33
+ collector << ")"
34
+ collector << " AS #{visit(node.alias, collector)}" if node.alias
35
+ collector
36
+ end
37
+
38
+ # Generates SQL for a spatial node.
39
+ # The node must be a string (in which case it is treated as WKT),
40
+ # an RGeo feature, or a spatial attribute.
41
+ def visit_in_spatial_context(node, collector)
42
+ case node
43
+ when String
44
+ collector << "#{st_func('ST_WKTToSQL')}(#{quote(node)})"
45
+ when RGeo::Feature::Instance
46
+ collector << visit_RGeo_Feature_Instance(node, collector)
47
+ when RGeo::Cartesian::BoundingBox
48
+ collector << visit_RGeo_Cartesian_BoundingBox(node, collector)
49
+ else
50
+ visit(node, collector)
51
+ end
52
+ end
53
+ end
54
+
55
+ # This node wraps an RGeo feature and gives it spatial expression constructors.
56
+ class SpatialConstantNode
57
+ include SpatialExpressions
58
+
59
+ # The delegate should be the RGeo feature.
60
+ def initialize(delegate)
61
+ @delegate = delegate
62
+ end
63
+
64
+ # Return the RGeo feature
65
+ attr_reader :delegate
66
+ end
67
+
68
+ # :stopdoc:
69
+
70
+ # Make sure the standard Arel visitors can handle RGeo feature objects by default.
71
+
72
+ Arel::Visitors::Visitor.class_eval do
73
+ def visit_RGeo_ActiveRecord_SpatialConstantNode(node, collector)
74
+ if respond_to?(:visit_in_spatial_context)
75
+ visit_in_spatial_context(node.delegate, collector)
76
+ else
77
+ visit(node.delegate, collector)
78
+ end
79
+ end
80
+ end
81
+
82
+ Arel::Visitors::Dot.class_eval do
83
+ alias :visit_RGeo_Feature_Instance :visit_String
84
+ alias :visit_RGeo_Cartesian_BoundingBox :visit_String
85
+ end
86
+
87
+ Arel::Visitors::DepthFirst.class_eval do
88
+ alias :visit_RGeo_Feature_Instance :terminal
89
+ alias :visit_RGeo_Cartesian_BoundingBox :terminal
90
+ end
91
+
92
+ Arel::Visitors::ToSql.class_eval do
93
+ alias :visit_RGeo_Feature_Instance :visit_String
94
+ alias :visit_RGeo_Cartesian_BoundingBox :visit_String
95
+ end
96
+
97
+ # A NamedFunction subclass that keeps track of the spatial-ness of
98
+ # the arguments and return values, so that it can provide context to
99
+ # visitors that want to interpret syntax differently when dealing with
100
+ # spatial elements.
101
+ class SpatialNamedFunction < Arel::Nodes::NamedFunction
102
+ include SpatialExpressions
103
+
104
+ def initialize(name, expr, spatial_flags = [], aliaz = nil)
105
+ super(name, expr, aliaz)
106
+ @spatial_flags = spatial_flags
107
+ end
108
+
109
+ def spatial_result?
110
+ @spatial_flags.first
111
+ end
112
+
113
+ def spatial_argument?(index)
114
+ @spatial_flags[index + 1]
115
+ end
116
+ end
117
+
118
+ # :startdoc:
119
+ end
120
+ end
@@ -0,0 +1,39 @@
1
+ # autoload AbstractAdapter
2
+ ActiveRecord::ConnectionAdapters::AbstractAdapter
3
+
4
+ module RGeo
5
+ module ActiveRecord
6
+ # Some default column constructors specifications for most spatial
7
+ # databases. Individual adapters may add to or override this list.
8
+ DEFAULT_SPATIAL_COLUMN_CONSTRUCTORS = {
9
+ geometry_collection: {}.freeze,
10
+ geometry: {}.freeze,
11
+ line_string: {}.freeze,
12
+ multi_line_string: {}.freeze,
13
+ multi_point: {}.freeze,
14
+ multi_polygon: {}.freeze,
15
+ point: {}.freeze,
16
+ polygon: {}.freeze,
17
+ spatial: { type: "geometry" }.freeze,
18
+ }.freeze
19
+
20
+ # Index definition struct with a spatial flag field.
21
+
22
+ SpatialIndexDefinition = Struct.new(:table, :name, :unique, :columns, :lengths, :orders, :where, :spatial)
23
+
24
+ # Returns a feature type module given a string type.
25
+
26
+ def self.geometric_type_from_name(name)
27
+ case name.to_s
28
+ when /^geometrycollection/i then Feature::GeometryCollection
29
+ when /^geometry/i then Feature::Geometry
30
+ when /^linestring/i then Feature::LineString
31
+ when /^multilinestring/i then Feature::MultiLineString
32
+ when /^multipoint/i then Feature::MultiPoint
33
+ when /^multipolygon/i then Feature::MultiPolygon
34
+ when /^point/i then Feature::Point
35
+ when /^polygon/i then Feature::Polygon
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,58 @@
1
+ module RGeo
2
+ module ActiveRecord
3
+ # This module is mixed into all geometry objects. It provides an
4
+ # as_json method so that ActiveRecord knows how to generate JSON
5
+ # for a geometry-valued field.
6
+
7
+ module GeometryMixin
8
+ # The default JSON generator Proc. Renders geometry fields as WKT.
9
+ DEFAULT_JSON_GENERATOR = Proc.new(&:to_s)
10
+
11
+ @json_generator = DEFAULT_JSON_GENERATOR
12
+
13
+ # Set the style of JSON generation used for geometry fields in an
14
+ # ActiveRecord model by default. You may pass nil to use
15
+ # DEFAULT_JSON_GENERATOR, a proc that takes a geometry as the
16
+ # argument and returns an object that can be converted to JSON
17
+ # (i.e. usually a hash or string), or one of the following symbolic
18
+ # values:
19
+ #
20
+ # <tt>:wkt</tt>::
21
+ # Well-known text format. (Same as DEFAULT_JSON_GENERATOR.)
22
+ # <tt>:geojson</tt>::
23
+ # GeoJSON format. Requires the rgeo-geojson gem.
24
+
25
+ def self.set_json_generator(value = nil, &block)
26
+ if block && !value
27
+ value = block
28
+ elsif value == :geojson
29
+ require "rgeo/geo_json"
30
+ value = proc { |geom| GeoJSON.encode(geom) }
31
+ end
32
+ if value.is_a?(Proc)
33
+ @json_generator = value
34
+ else
35
+ @json_generator = DEFAULT_JSON_GENERATOR
36
+ end
37
+ end
38
+
39
+ # Given a feature, returns an object that can be serialized as JSON
40
+ # (i.e. usually a hash or string), using the current json_generator.
41
+ # This is used to generate JSON for geometry-valued ActiveRecord
42
+ # fields by default.
43
+
44
+ def self.generate_json(geom)
45
+ @json_generator.call(geom)
46
+ end
47
+
48
+ # Serializes this object as JSON for ActiveRecord.
49
+
50
+ def as_json(opts = nil)
51
+ GeometryMixin.generate_json(self)
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ RGeo::Feature::MixinCollection::GLOBAL.for_type(RGeo::Feature::Geometry)
58
+ .add(RGeo::ActiveRecord::GeometryMixin)
@@ -0,0 +1,254 @@
1
+ module RGeo
2
+ module ActiveRecord
3
+ # Returns true if spatial expressions (i.e. the methods in the
4
+ # SpatialExpressions module) are supported.
5
+ def self.spatial_expressions_supported?
6
+ defined?(Arel::Nodes::NamedFunction)
7
+ end
8
+
9
+ # A set of spatial expression builders.
10
+ # These methods can be chained off other spatial expressions to form
11
+ # complex expressions.
12
+ module SpatialExpressions
13
+ #--
14
+ # Generic functions
15
+ #++
16
+
17
+ def st_function(function, *args)
18
+ spatial_info = args.last.is_a?(::Array) ? args.pop : []
19
+ SpatialNamedFunction.new(function, [self] + args, spatial_info)
20
+ end
21
+
22
+ #--
23
+ # Geometry functions
24
+ #++
25
+
26
+ def st_dimension
27
+ SpatialNamedFunction.new("ST_Dimension", [self], [false, true])
28
+ end
29
+
30
+ def st_geometrytype
31
+ SpatialNamedFunction.new("ST_GeometryType", [self], [false, true])
32
+ end
33
+
34
+ def st_astext
35
+ SpatialNamedFunction.new("ST_AsText", [self], [false, true])
36
+ end
37
+
38
+ def st_asbinary
39
+ SpatialNamedFunction.new("ST_AsBinary", [self], [false, true])
40
+ end
41
+
42
+ def st_srid
43
+ SpatialNamedFunction.new("ST_SRID", [self], [false, true])
44
+ end
45
+
46
+ def st_isempty
47
+ SpatialNamedFunction.new("ST_IsEmpty", [self], [false, true])
48
+ end
49
+
50
+ def st_issimple
51
+ SpatialNamedFunction.new("ST_IsSimple", [self], [false, true])
52
+ end
53
+
54
+ def st_boundary
55
+ SpatialNamedFunction.new("ST_Boundary", [self], [true, true])
56
+ end
57
+
58
+ def st_envelope
59
+ SpatialNamedFunction.new("ST_Envelope", [self], [true, true])
60
+ end
61
+
62
+ def st_equals(rhs)
63
+ SpatialNamedFunction.new("ST_Equals", [self, rhs], [false, true, true])
64
+ end
65
+
66
+ def st_disjoint(rhs)
67
+ SpatialNamedFunction.new("ST_Disjoint", [self, rhs], [false, true, true])
68
+ end
69
+
70
+ def st_intersects(rhs)
71
+ SpatialNamedFunction.new("ST_Intersects", [self, rhs], [false, true, true])
72
+ end
73
+
74
+ def st_touches(rhs)
75
+ SpatialNamedFunction.new("ST_Touches", [self, rhs], [false, true, true])
76
+ end
77
+
78
+ def st_crosses(rhs)
79
+ SpatialNamedFunction.new("ST_Crosses", [self, rhs], [false, true, true])
80
+ end
81
+
82
+ def st_within(rhs)
83
+ SpatialNamedFunction.new("ST_Within", [self, rhs], [false, true, true])
84
+ end
85
+
86
+ def st_contains(rhs)
87
+ SpatialNamedFunction.new("ST_Contains", [self, rhs], [false, true, true])
88
+ end
89
+
90
+ def st_overlaps(rhs)
91
+ SpatialNamedFunction.new("ST_Overlaps", [self, rhs], [false, true, true])
92
+ end
93
+
94
+ def st_relate(rhs, matrix = nil)
95
+ args = [self, rhs]
96
+ args << matrix.to_s if matrix
97
+ SpatialNamedFunction.new("ST_Relate", args, [false, true, true, false])
98
+ end
99
+
100
+ def st_distance(rhs, units = nil)
101
+ args = [self, rhs]
102
+ args << units.to_s if units
103
+ SpatialNamedFunction.new("ST_Distance", args, [false, true, true, false])
104
+ end
105
+
106
+ def st_intersection(rhs)
107
+ SpatialNamedFunction.new("ST_Intersection", [self, rhs], [true, true, true])
108
+ end
109
+
110
+ def st_difference(rhs)
111
+ SpatialNamedFunction.new("ST_Difference", [self, rhs], [true, true, true])
112
+ end
113
+
114
+ def st_union(rhs)
115
+ SpatialNamedFunction.new("ST_Union", [self, rhs], [true, true, true])
116
+ end
117
+
118
+ def st_symdifference(rhs)
119
+ SpatialNamedFunction.new("ST_SymDifference", [self, rhs], [true, true, true])
120
+ end
121
+
122
+ def st_buffer(distance, units = nil)
123
+ args = [self, distance.to_f]
124
+ args << units.to_s if units
125
+ SpatialNamedFunction.new("ST_Buffer", args, [true, true, false])
126
+ end
127
+
128
+ def st_convexhull
129
+ SpatialNamedFunction.new("ST_ConvexHull", [self], [true, true])
130
+ end
131
+
132
+ #--
133
+ # Point functions
134
+ #++
135
+
136
+ def st_x
137
+ SpatialNamedFunction.new("ST_X", [self], [false, true])
138
+ end
139
+
140
+ def st_y
141
+ SpatialNamedFunction.new("ST_Y", [self], [false, true])
142
+ end
143
+
144
+ def st_z
145
+ SpatialNamedFunction.new("ST_Z", [self], [false, true])
146
+ end
147
+
148
+ def st_m
149
+ SpatialNamedFunction.new("ST_M", [self], [false, true])
150
+ end
151
+
152
+ #--
153
+ # Curve functions
154
+ #++
155
+
156
+ def st_startpoint
157
+ SpatialNamedFunction.new("ST_StartPoint", [self], [true, true])
158
+ end
159
+
160
+ def st_endpoint
161
+ SpatialNamedFunction.new("ST_EndPoint", [self], [true, true])
162
+ end
163
+
164
+ def st_isclosed
165
+ SpatialNamedFunction.new("ST_IsClosed", [self], [false, true])
166
+ end
167
+
168
+ def st_isring
169
+ SpatialNamedFunction.new("ST_IsRing", [self], [false, true])
170
+ end
171
+
172
+ def st_length(units = nil)
173
+ args = [self]
174
+ args << units.to_s if units
175
+ SpatialNamedFunction.new("ST_Length", args, [false, true, false])
176
+ end
177
+
178
+ #--
179
+ # LineString functions
180
+ #++
181
+
182
+ def st_numpoints
183
+ SpatialNamedFunction.new("ST_NumPoints", [self], [false, true])
184
+ end
185
+
186
+ def st_pointn(n)
187
+ SpatialNamedFunction.new("ST_PointN", [self, n.to_i], [true, true, false])
188
+ end
189
+
190
+ #--
191
+ # Surface functions
192
+ #++
193
+
194
+ def st_area(units = nil)
195
+ args = [self]
196
+ args << units.to_s if units
197
+ SpatialNamedFunction.new("ST_StartPoint", args, [false, true, false])
198
+ end
199
+
200
+ def st_centroid
201
+ SpatialNamedFunction.new("ST_Centroid", [self], [true, true])
202
+ end
203
+
204
+ def st_pointonsurface
205
+ SpatialNamedFunction.new("ST_PointOnSurface", [self], [true, true])
206
+ end
207
+
208
+ #--
209
+ # Polygon functions
210
+ #++
211
+
212
+ def st_exteriorring
213
+ SpatialNamedFunction.new("ST_ExteriorRing", [self], [true, true])
214
+ end
215
+
216
+ def st_numinteriorrings
217
+ # Note: the name difference is intentional. The standard
218
+ # names this function incorrectly.
219
+ SpatialNamedFunction.new("ST_NumInteriorRing", [self], [false, true])
220
+ end
221
+
222
+ def st_interiorringn(n)
223
+ SpatialNamedFunction.new("ST_InteriorRingN", [self, n.to_i], [true, true, false])
224
+ end
225
+
226
+ #--
227
+ # GeometryCollection functions
228
+ #++
229
+
230
+ def st_numgeometries
231
+ SpatialNamedFunction.new("ST_NumGeometries", [self], [false, true])
232
+ end
233
+
234
+ def st_geometryn(n)
235
+ SpatialNamedFunction.new("ST_GeometryN", [self, n.to_i], [true, true, false])
236
+ end
237
+ end
238
+ end
239
+ end
240
+
241
+ # Add tools to build spatial structures in the AST.
242
+
243
+ # Allow chaining of spatial expressions from attributes
244
+ Arel::Attribute.send :include, RGeo::ActiveRecord::SpatialExpressions
245
+
246
+ module Arel
247
+ # Create a spatial constant node.
248
+ # This node wraps a spatial value (such as an RGeo feature or a text
249
+ # string in WKT format). It supports chaining with the functions
250
+ # defined by RGeo::ActiveRecord::SpatialExpressions.
251
+ def self.spatial(arg)
252
+ RGeo::ActiveRecord::SpatialConstantNode.new(arg)
253
+ end
254
+ end
@@ -0,0 +1,61 @@
1
+ module RGeo
2
+ module ActiveRecord
3
+ class SpatialFactoryStore
4
+ include Singleton
5
+
6
+ attr_accessor :registry
7
+
8
+ def initialize
9
+ @registry = {}
10
+ end
11
+
12
+ def register(factory, attrs = {})
13
+ registry[key(attrs)] = factory
14
+ end
15
+
16
+ def default(attrs = {})
17
+ @default || default_for_attrs(attrs)
18
+ end
19
+
20
+ def default=(factory)
21
+ @default = factory
22
+ end
23
+
24
+ def factory(attrs)
25
+ registry[key(attrs)] || default(attrs)
26
+ end
27
+
28
+ def clear
29
+ @registry = {}
30
+ end
31
+
32
+ private
33
+
34
+ def default_for_attrs(attrs)
35
+ if attrs[:sql_type] =~ /geography/
36
+ Geographic.spherical_factory(to_factory_attrs(attrs))
37
+ else
38
+ Cartesian.preferred_factory(to_factory_attrs(attrs))
39
+ end
40
+ end
41
+
42
+ def to_factory_attrs(attrs)
43
+ {
44
+ has_m_coordinate: attrs[:has_m],
45
+ has_z_coordinate: attrs[:has_z],
46
+ srid: (attrs[:srid] || 0),
47
+ }
48
+ end
49
+
50
+ def key(attrs)
51
+ {
52
+ geo_type: "geometry",
53
+ has_m: false,
54
+ has_z: false,
55
+ sql_type: "geometry",
56
+ srid: 0,
57
+ }.merge(attrs).hash
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,5 @@
1
+ module RGeo
2
+ module ActiveRecord
3
+ VERSION = "5.0.0".freeze
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rgeo-activerecord-dschee
3
+ version: !ruby/object:Gem::Version
4
+ version: 5.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Azuma, Tee Parham
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rgeo-dschee
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 5.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 5.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: appraisal
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rgeo-geojson
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 0.4.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 0.4.1
111
+ description: RGeo is a geospatial data library for Ruby. RGeo::ActiveRecord is an
112
+ optional RGeo module providing some spatial extensions to ActiveRecord, as well
113
+ as common tools used by RGeo-based spatial adapters.
114
+ email: dazuma@gmail.com, parhameter@gmail.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - History.md
120
+ - LICENSE.txt
121
+ - README.md
122
+ - lib/rgeo-activerecord.rb
123
+ - lib/rgeo/active_record.rb
124
+ - lib/rgeo/active_record/arel_spatial_queries.rb
125
+ - lib/rgeo/active_record/common_adapter_elements.rb
126
+ - lib/rgeo/active_record/geometry_mixin.rb
127
+ - lib/rgeo/active_record/spatial_expressions.rb
128
+ - lib/rgeo/active_record/spatial_factory_store.rb
129
+ - lib/rgeo/active_record/version.rb
130
+ homepage: https://github.com/rgeo/rgeo-activerecord
131
+ licenses: []
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: 2.2.2
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.4.8
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: An RGeo module providing spatial extensions to ActiveRecord.
153
+ test_files: []
154
+ has_rdoc: