rgeo-activerecord 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Version +1 -1
- data/lib/rgeo/active_record/arel_spatial_queries.rb +11 -11
- data/test/support/fake_record.rb +124 -0
- data/test/tc_basic.rb +14 -4
- data/test/test_helper.rb +21 -0
- metadata +26 -35
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 050dae83a358df1f39ade771d9a422d8fe9e15d7
|
4
|
+
data.tar.gz: 86c8fabb76788f275114d08cfd9568cf423a0fd5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aa37b062ba3f81ec42cbd761807d3345ba5c022c665495b96600025dfd146b8400b9d585344705e7b46e95298fc2f492acb784e23482288db777f288db8eb988
|
7
|
+
data.tar.gz: 13b9d228dad1a0aaa3c707dc6d04cd0cb9ba99f78b71f3265a2d9fa2fd30aa6f18c1a69594997b2065571c90622af0242dce3b2cb3e514c402459640f3b51347
|
data/Version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
@@ -62,13 +62,13 @@ module RGeo
|
|
62
62
|
# mapping for the database, and it also uses the type information
|
63
63
|
# in the node to determine when to cast string arguments to WKT,
|
64
64
|
|
65
|
-
def visit_RGeo_ActiveRecord_SpatialNamedFunction(node_)
|
65
|
+
def visit_RGeo_ActiveRecord_SpatialNamedFunction(node_, *args)
|
66
66
|
name_ = st_func(node_.name)
|
67
67
|
exprs_ = []
|
68
68
|
node_.expressions.each_with_index do |expr_, index_|
|
69
|
-
exprs_ << (node_.spatial_argument?(index_) ? visit_in_spatial_context(expr_) : visit(expr_))
|
69
|
+
exprs_ << (node_.spatial_argument?(index_) ? visit_in_spatial_context(expr_, *args) : visit(expr_, *args))
|
70
70
|
end
|
71
|
-
"#{name_}(#{node_.distinct ? 'DISTINCT ' : ''}#{exprs_.join(', ')})#{node_.alias ? " AS #{visit
|
71
|
+
"#{name_}(#{node_.distinct ? 'DISTINCT ' : ''}#{exprs_.join(', ')})#{node_.alias ? " AS #{visit(node_.alias, *args)}" : ''}"
|
72
72
|
end
|
73
73
|
|
74
74
|
|
@@ -76,16 +76,16 @@ module RGeo
|
|
76
76
|
# The node must be a string (in which case it is treated as WKT),
|
77
77
|
# an RGeo feature, or a spatial attribute.
|
78
78
|
|
79
|
-
def visit_in_spatial_context(node_)
|
79
|
+
def visit_in_spatial_context(node_, *args)
|
80
80
|
case node_
|
81
81
|
when ::String
|
82
|
-
"#{st_func('ST_WKTToSQL')}(#{visit_String(node_)})"
|
82
|
+
"#{st_func('ST_WKTToSQL')}(#{visit_String(node_, *args)})"
|
83
83
|
when ::RGeo::Feature::Instance
|
84
|
-
visit_RGeo_Feature_Instance(node_)
|
84
|
+
visit_RGeo_Feature_Instance(node_, *args)
|
85
85
|
when ::RGeo::Cartesian::BoundingBox
|
86
|
-
visit_RGeo_Cartesian_BoundingBox(node_)
|
86
|
+
visit_RGeo_Cartesian_BoundingBox(node_, *args)
|
87
87
|
else
|
88
|
-
visit(node_)
|
88
|
+
visit(node_, *args)
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
@@ -136,11 +136,11 @@ module RGeo
|
|
136
136
|
# by default.
|
137
137
|
|
138
138
|
::Arel::Visitors::Visitor.class_eval do
|
139
|
-
def visit_RGeo_ActiveRecord_SpatialConstantNode(node_)
|
139
|
+
def visit_RGeo_ActiveRecord_SpatialConstantNode(node_, *args)
|
140
140
|
if respond_to?(:visit_in_spatial_context)
|
141
|
-
visit_in_spatial_context(node_.delegate)
|
141
|
+
visit_in_spatial_context(node_.delegate, *args)
|
142
142
|
else
|
143
|
-
visit(node_.delegate)
|
143
|
+
visit(node_.delegate, *args)
|
144
144
|
end
|
145
145
|
end
|
146
146
|
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
# From https://github.com/rails/arel/blob/4-0-stable/test/support/fake_record.rb
|
2
|
+
module FakeRecord
|
3
|
+
class Column < Struct.new(:name, :type)
|
4
|
+
end
|
5
|
+
|
6
|
+
class Connection
|
7
|
+
attr_reader :tables
|
8
|
+
attr_accessor :visitor
|
9
|
+
|
10
|
+
def initialize(visitor = nil)
|
11
|
+
@tables = %w{ users photos developers products}
|
12
|
+
@columns = {
|
13
|
+
'users' => [
|
14
|
+
Column.new('id', :integer),
|
15
|
+
Column.new('name', :string),
|
16
|
+
Column.new('bool', :boolean),
|
17
|
+
Column.new('created_at', :date)
|
18
|
+
],
|
19
|
+
'products' => [
|
20
|
+
Column.new('id', :integer),
|
21
|
+
Column.new('price', :decimal)
|
22
|
+
]
|
23
|
+
}
|
24
|
+
@columns_hash = {
|
25
|
+
'users' => Hash[@columns['users'].map { |x| [x.name, x] }],
|
26
|
+
'products' => Hash[@columns['products'].map { |x| [x.name, x] }]
|
27
|
+
}
|
28
|
+
@primary_keys = {
|
29
|
+
'users' => 'id',
|
30
|
+
'products' => 'id'
|
31
|
+
}
|
32
|
+
@visitor = visitor
|
33
|
+
end
|
34
|
+
|
35
|
+
def columns_hash table_name
|
36
|
+
@columns_hash[table_name]
|
37
|
+
end
|
38
|
+
|
39
|
+
def primary_key name
|
40
|
+
@primary_keys[name.to_s]
|
41
|
+
end
|
42
|
+
|
43
|
+
def table_exists? name
|
44
|
+
@tables.include? name.to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
def columns name, message = nil
|
48
|
+
@columns[name.to_s]
|
49
|
+
end
|
50
|
+
|
51
|
+
def quote_table_name name
|
52
|
+
"\"#{name.to_s}\""
|
53
|
+
end
|
54
|
+
|
55
|
+
def quote_column_name name
|
56
|
+
"\"#{name.to_s}\""
|
57
|
+
end
|
58
|
+
|
59
|
+
def schema_cache
|
60
|
+
self
|
61
|
+
end
|
62
|
+
|
63
|
+
def quote thing, column = nil
|
64
|
+
if column && column.type == :integer
|
65
|
+
return 'NULL' if thing.nil?
|
66
|
+
return thing.to_i
|
67
|
+
end
|
68
|
+
|
69
|
+
case thing
|
70
|
+
when true
|
71
|
+
"'t'"
|
72
|
+
when false
|
73
|
+
"'f'"
|
74
|
+
when nil
|
75
|
+
'NULL'
|
76
|
+
when Numeric
|
77
|
+
thing
|
78
|
+
else
|
79
|
+
"'#{thing}'"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class ConnectionPool
|
85
|
+
class Spec < Struct.new(:config)
|
86
|
+
end
|
87
|
+
|
88
|
+
attr_reader :spec, :connection
|
89
|
+
|
90
|
+
def initialize
|
91
|
+
@spec = Spec.new(:adapter => 'america')
|
92
|
+
@connection = Connection.new
|
93
|
+
@connection.visitor = Arel::Visitors::ToSql.new(connection)
|
94
|
+
end
|
95
|
+
|
96
|
+
def with_connection
|
97
|
+
yield connection
|
98
|
+
end
|
99
|
+
|
100
|
+
def table_exists? name
|
101
|
+
connection.tables.include? name.to_s
|
102
|
+
end
|
103
|
+
|
104
|
+
def columns_hash
|
105
|
+
connection.columns_hash
|
106
|
+
end
|
107
|
+
|
108
|
+
def schema_cache
|
109
|
+
connection
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
class Base
|
114
|
+
attr_accessor :connection_pool
|
115
|
+
|
116
|
+
def initialize
|
117
|
+
@connection_pool = ConnectionPool.new
|
118
|
+
end
|
119
|
+
|
120
|
+
def connection
|
121
|
+
connection_pool.connection
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
data/test/tc_basic.rb
CHANGED
@@ -34,9 +34,7 @@
|
|
34
34
|
;
|
35
35
|
|
36
36
|
|
37
|
-
require '
|
38
|
-
require 'rgeo/active_record'
|
39
|
-
|
37
|
+
require 'test_helper'
|
40
38
|
|
41
39
|
module RGeo
|
42
40
|
module ActiveRecord
|
@@ -102,9 +100,21 @@ module RGeo
|
|
102
100
|
assert_equal({'type' => 'Point', 'coordinates' => [1.0, 2.0]}, p_.as_json)
|
103
101
|
end
|
104
102
|
|
103
|
+
def test_arel_visit_SpatialConstantNode
|
104
|
+
visitor = arel_visitor
|
105
|
+
sql = visitor.accept(Arel.spatial('POINT (1.0 2.0)'))
|
106
|
+
assert_equal("ST_WKTToSQL('POINT (1.0 2.0)')", sql)
|
107
|
+
end
|
105
108
|
|
109
|
+
# SpatialNamedFunction is not used in pre-2.1 Arel.
|
110
|
+
if(AREL_VERSION_MAJOR > 2 || (AREL_VERSION_MAJOR == 2 && AREL_VERSION_MINOR >= 1))
|
111
|
+
def test_arel_visit_SpatialNamedFunction
|
112
|
+
visitor = arel_visitor
|
113
|
+
sql = visitor.accept(Arel.spatial('POINT (1.0 2.0)').st_astext)
|
114
|
+
assert_equal("ST_AsText(ST_WKTToSQL('POINT (1.0 2.0)'))", sql)
|
115
|
+
end
|
116
|
+
end
|
106
117
|
end
|
107
|
-
|
108
118
|
end
|
109
119
|
end
|
110
120
|
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rgeo/active_record'
|
3
|
+
require 'support/fake_record'
|
4
|
+
|
5
|
+
AREL_VERSION_MAJOR, AREL_VERSION_MINOR, AREL_VERSION_PATCH = ::Arel::VERSION.split('.').map { |part| part.to_i }
|
6
|
+
Arel::Visitors::PostgreSQL.send(:include, ::RGeo::ActiveRecord::SpatialToSql)
|
7
|
+
Arel::Table.engine = Arel::Sql::Engine.new(FakeRecord::Base.new)
|
8
|
+
|
9
|
+
def arel_visitor
|
10
|
+
# The argument for constructing visitor objects depends on the version of
|
11
|
+
# Arel.
|
12
|
+
if(AREL_VERSION_MAJOR <= 2)
|
13
|
+
if(AREL_VERSION_MAJOR == 2 && AREL_VERSION_MINOR == 0)
|
14
|
+
Arel::Visitors::PostgreSQL.new(Arel::Table.engine)
|
15
|
+
else
|
16
|
+
Arel::Visitors::PostgreSQL.new(Arel::Table.engine.connection_pool)
|
17
|
+
end
|
18
|
+
else
|
19
|
+
Arel::Visitors::PostgreSQL.new(Arel::Table.engine.connection)
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,94 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rgeo-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.6.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Daniel Azuma
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-05-06 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rgeo
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 0.3.20
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 0.3.20
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: activerecord
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: 3.0.3
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: 3.0.3
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: arel
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: 2.0.6
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: 2.0.6
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: rake
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rdoc
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - ">="
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - ">="
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
description: RGeo is a geospatial data library for Ruby. RGeo::ActiveRecord is an
|
@@ -101,6 +90,11 @@ extra_rdoc_files:
|
|
101
90
|
- History.rdoc
|
102
91
|
- README.rdoc
|
103
92
|
files:
|
93
|
+
- History.rdoc
|
94
|
+
- README.rdoc
|
95
|
+
- Version
|
96
|
+
- lib/rgeo-activerecord.rb
|
97
|
+
- lib/rgeo/active_record.rb
|
104
98
|
- lib/rgeo/active_record/adapter_test_helper.rb
|
105
99
|
- lib/rgeo/active_record/ar_factory_settings.rb
|
106
100
|
- lib/rgeo/active_record/arel_spatial_queries.rb
|
@@ -109,35 +103,32 @@ files:
|
|
109
103
|
- lib/rgeo/active_record/spatial_expressions.rb
|
110
104
|
- lib/rgeo/active_record/task_hacker.rb
|
111
105
|
- lib/rgeo/active_record/version.rb
|
112
|
-
-
|
113
|
-
- lib/rgeo-activerecord.rb
|
106
|
+
- test/support/fake_record.rb
|
114
107
|
- test/tc_basic.rb
|
115
|
-
-
|
116
|
-
- README.rdoc
|
117
|
-
- Version
|
108
|
+
- test/test_helper.rb
|
118
109
|
homepage: http://dazuma.github.com/rgeo-activerecord
|
119
110
|
licenses: []
|
111
|
+
metadata: {}
|
120
112
|
post_install_message:
|
121
113
|
rdoc_options: []
|
122
114
|
require_paths:
|
123
115
|
- lib
|
124
116
|
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
-
none: false
|
126
117
|
requirements:
|
127
|
-
- -
|
118
|
+
- - ">="
|
128
119
|
- !ruby/object:Gem::Version
|
129
120
|
version: 1.8.7
|
130
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
-
none: false
|
132
122
|
requirements:
|
133
|
-
- -
|
123
|
+
- - ">="
|
134
124
|
- !ruby/object:Gem::Version
|
135
|
-
version:
|
125
|
+
version: '0'
|
136
126
|
requirements: []
|
137
127
|
rubyforge_project: virtuoso
|
138
|
-
rubygems_version:
|
128
|
+
rubygems_version: 2.2.2
|
139
129
|
signing_key:
|
140
|
-
specification_version:
|
130
|
+
specification_version: 4
|
141
131
|
summary: An RGeo module providing spatial extensions to ActiveRecord.
|
142
132
|
test_files:
|
143
133
|
- test/tc_basic.rb
|
134
|
+
has_rdoc:
|