rgeo-activerecord 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +5 -0
- data/Version +1 -1
- data/lib/rgeo/active_record/arel_modifications.rb +8 -26
- data/lib/rgeo/active_record/common.rb +39 -16
- data/lib/rgeo/active_record/task_hacker.rb +86 -0
- metadata +6 -5
data/History.rdoc
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
=== 0.2.2 / 2011-01-06
|
2
|
+
|
3
|
+
* Some adjustments to the Arel integration for future Arel compatibility. (Thanks to Aaron Patterson.)
|
4
|
+
* Support code for hacking ActiveRecord's rake tasks.
|
5
|
+
|
1
6
|
=== 0.2.1 / 2010-12-27
|
2
7
|
|
3
8
|
* Support for RGeo features as nodes in the Arel AST.
|
data/Version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
@@ -64,52 +64,34 @@ module Arel
|
|
64
64
|
|
65
65
|
# :stopdoc:
|
66
66
|
|
67
|
+
|
68
|
+
# Hack Attributes dispatcher to recognize geometry columns.
|
69
|
+
# This is deprecated but necessary to support legacy Arel versions.
|
67
70
|
module Attributes
|
68
|
-
|
69
|
-
# New attribute type for geometry-valued column
|
70
|
-
class Geometry < Attribute; end
|
71
|
-
|
72
|
-
# Hack Attributes dispatcher to recognize geometry columns
|
73
71
|
class << self
|
74
|
-
|
75
|
-
|
76
|
-
|
72
|
+
if method_defined?(:for)
|
73
|
+
alias_method :for_without_geometry, :for
|
74
|
+
def for(column_)
|
75
|
+
column_.type == :geometry ? Attribute : for_without_geometry(column_)
|
76
|
+
end
|
77
77
|
end
|
78
78
|
end
|
79
|
-
|
80
79
|
end
|
81
80
|
|
82
81
|
module Visitors
|
83
82
|
|
84
|
-
# Hack visit dispatcher to recognize RGeo features as nodes.
|
85
|
-
# We need a special dispatcher code because the default dispatcher
|
86
|
-
# triggers on class name. RGeo features tend to have opaque classes.
|
87
|
-
class Visitor
|
88
|
-
alias_method :visit_without_rgeo_types, :visit
|
89
|
-
def visit(object_)
|
90
|
-
if object_.kind_of?(::RGeo::Feature::Instance) && respond_to?(:visit_RGeo_Feature_Instance)
|
91
|
-
visit_RGeo_Feature_Instance(object_)
|
92
|
-
else
|
93
|
-
visit_without_rgeo_types(object_)
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
83
|
# Dot visitor handlers for geometry attributes and values.
|
99
84
|
class Dot
|
100
|
-
alias :visit_Arel_Attributes_Geometry :visit_Arel_Attribute
|
101
85
|
alias :visit_RGeo_Feature_Instance :visit_String
|
102
86
|
end
|
103
87
|
|
104
88
|
# DepthFirst visitor handlers for geometry attributes and values.
|
105
89
|
class DepthFirst
|
106
|
-
alias :visit_Arel_Attributes_Geometry :visit_Arel_Attribute
|
107
90
|
alias :visit_RGeo_Feature_Instance :terminal
|
108
91
|
end
|
109
92
|
|
110
93
|
# ToSql visitor handlers for geometry attributes and values.
|
111
94
|
class ToSql
|
112
|
-
alias :visit_Arel_Attributes_Geometry :visit_Arel_Attributes_Attribute
|
113
95
|
alias :visit_RGeo_Feature_Instance :visit_String
|
114
96
|
end
|
115
97
|
|
@@ -62,32 +62,55 @@ module RGeo
|
|
62
62
|
standard_name_
|
63
63
|
end
|
64
64
|
|
65
|
+
# Returns true if the given node is of spatial type-- that is, if
|
66
|
+
# it is a spatial literal or a reference to a spatial attribute.
|
67
|
+
def node_has_spatial_type?(node_)
|
68
|
+
case node_
|
69
|
+
when ::Arel::Attribute
|
70
|
+
@connection.instance_variable_set(:@_getting_columns, true)
|
71
|
+
begin
|
72
|
+
col_ = @engine.columns_hash[node_.name.to_s]
|
73
|
+
col_ && col_.respond_to?(:spatial?) && col_.spatial?
|
74
|
+
ensure
|
75
|
+
@connection.instance_variable_set(:@_getting_columns, false)
|
76
|
+
end
|
77
|
+
when ::RGeo::Feature::Instance
|
78
|
+
true
|
79
|
+
else
|
80
|
+
false
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Generates SQL for a spatial node.
|
85
|
+
def visit_spatial(node_)
|
86
|
+
case node_
|
87
|
+
when ::String
|
88
|
+
"#{st_func('ST_WKTToSQL')}(#{visit_String(node_)})"
|
89
|
+
when ::RGeo::Feature::Instance
|
90
|
+
visit_RGeo_Feature_Instance(node_)
|
91
|
+
else
|
92
|
+
visit(node_)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
65
96
|
def visit_Arel_Nodes_Equality(node_) # :nodoc:
|
66
97
|
right_ = node_.right
|
67
98
|
left_ = node_.left
|
68
|
-
if
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
when ::String
|
73
|
-
return "#{st_func('ST_Equals')}(#{visit(left_)}, #{st_func('ST_WKTToSQL')}(#{visit(right_)}))"
|
74
|
-
end
|
99
|
+
if !@connection.instance_variable_get(:@_getting_columns) && (node_has_spatial_type?(right_) || node_has_spatial_type?(left_))
|
100
|
+
"#{st_func('ST_Equals')}(#{visit_spatial(left_)}, #{visit_spatial(right_)})"
|
101
|
+
else
|
102
|
+
super
|
75
103
|
end
|
76
|
-
super
|
77
104
|
end
|
78
105
|
|
79
106
|
def visit_Arel_Nodes_NotEqual(node_) # :nodoc:
|
80
107
|
right_ = node_.right
|
81
108
|
left_ = node_.left
|
82
|
-
if
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
when ::String
|
87
|
-
return "NOT #{st_func('ST_Equals')}(#{visit(left_)}, #{st_func('ST_WKTToSQL')}(#{visit(right_)}))"
|
88
|
-
end
|
109
|
+
if !@connection.instance_variable_get(:@_getting_columns) && (node_has_spatial_type?(right_) || node_has_spatial_type?(left_))
|
110
|
+
"NOT #{st_func('ST_Equals')}(#{visit_spatial(left_)}, #{visit_spatial(right_)})"
|
111
|
+
else
|
112
|
+
super
|
89
113
|
end
|
90
|
-
super
|
91
114
|
end
|
92
115
|
|
93
116
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# Common tools for spatial adapters for ActiveRecord
|
4
|
+
#
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
# Copyright 2010 Daniel Azuma
|
7
|
+
#
|
8
|
+
# All rights reserved.
|
9
|
+
#
|
10
|
+
# Redistribution and use in source and binary forms, with or without
|
11
|
+
# modification, are permitted provided that the following conditions are met:
|
12
|
+
#
|
13
|
+
# * Redistributions of source code must retain the above copyright notice,
|
14
|
+
# this list of conditions and the following disclaimer.
|
15
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
16
|
+
# this list of conditions and the following disclaimer in the documentation
|
17
|
+
# and/or other materials provided with the distribution.
|
18
|
+
# * Neither the name of the copyright holder, nor the names of any other
|
19
|
+
# contributors to this software, may be used to endorse or promote products
|
20
|
+
# derived from this software without specific prior written permission.
|
21
|
+
#
|
22
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
23
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
24
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
25
|
+
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
26
|
+
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
27
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
28
|
+
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
29
|
+
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
30
|
+
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
31
|
+
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
32
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
33
|
+
# -----------------------------------------------------------------------------
|
34
|
+
;
|
35
|
+
|
36
|
+
|
37
|
+
module RGeo
|
38
|
+
|
39
|
+
module ActiveRecord
|
40
|
+
|
41
|
+
|
42
|
+
# A set of tools for hacking Rake tasks.
|
43
|
+
|
44
|
+
module TaskHacker
|
45
|
+
|
46
|
+
|
47
|
+
class Action # :nodoc:
|
48
|
+
|
49
|
+
def initialize(env_, pattern_, proc_)
|
50
|
+
@env = env_
|
51
|
+
@pattern = pattern_
|
52
|
+
@proc = proc_
|
53
|
+
end
|
54
|
+
|
55
|
+
def call(task_)
|
56
|
+
config_ = ::ActiveRecord::Base.configurations[@env || ::Rails.env || 'development']
|
57
|
+
if @pattern === config_['adapter']
|
58
|
+
task_.actions.delete_if{ |a_| a_ != self }
|
59
|
+
@proc.call(config_)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def arity
|
64
|
+
1
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
class << self
|
71
|
+
|
72
|
+
|
73
|
+
def modify(name_, env_, pattern_, &block_)
|
74
|
+
::Rake::Task[name_].actions.unshift(Action.new(env_, pattern_, block_))
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Daniel Azuma
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-01-06 00:00:00 -08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -28,8 +28,8 @@ dependencies:
|
|
28
28
|
segments:
|
29
29
|
- 0
|
30
30
|
- 2
|
31
|
-
-
|
32
|
-
version: 0.2.
|
31
|
+
- 4
|
32
|
+
version: 0.2.4
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- lib/rgeo/active_record/ar_modifications.rb
|
62
62
|
- lib/rgeo/active_record/arel_modifications.rb
|
63
63
|
- lib/rgeo/active_record/common.rb
|
64
|
+
- lib/rgeo/active_record/task_hacker.rb
|
64
65
|
- lib/rgeo/active_record.rb
|
65
66
|
- History.rdoc
|
66
67
|
- README.rdoc
|