Class: Arel::Visitors::Mysql2Rgeo
- Inherits:
-
MySQLSuperclass
- Object
- Arel::Visitors::Mysql2Rgeo
- Includes:
- BindVisitor, RGeo::ActiveRecord::SpatialToSql
- Defined in:
- lib/active_record/connection_adapters/mysql2rgeo/arel_tosql.rb
Overview
:nodoc:
Constant Summary collapse
- FUNC_MAP =
{ "st_wkttosql" => "ST_GeomFromText", "st_wkbtosql" => "ST_GeomFromWKB", "st_length" => "ST_Length" }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #st_func(standard_name) ⇒ Object
- #visit_in_spatial_context(node, collector) ⇒ Object
- #visit_RGeo_ActiveRecord_SpatialNamedFunction(node, collector) ⇒ Object
- #visit_String(node, collector) ⇒ Object
Class Method Details
.parse_node(node) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/active_record/connection_adapters/mysql2rgeo/arel_tosql.rb', line 60 def self.parse_node(node) value, srid = nil, 0 if node =~ /.*;.*$/i params = Regexp.last_match(0).split(";") if params.first =~ /(srid|SRID)=\d*/ srid = params.first.split("=").last.to_i else value = params.first end if params.last =~ /(srid|SRID)=\d*/ srid = params.last.split("=").last.to_i else value = params.last end else value = node end [value, srid] end |
Instance Method Details
#st_func(standard_name) ⇒ Object
25 26 27 |
# File 'lib/active_record/connection_adapters/mysql2rgeo/arel_tosql.rb', line 25 def st_func(standard_name) FUNC_MAP[standard_name.downcase] || standard_name end |
#visit_in_spatial_context(node, collector) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/active_record/connection_adapters/mysql2rgeo/arel_tosql.rb', line 42 def visit_in_spatial_context(node, collector) case node when String node, srid = Mysql2Rgeo.parse_node(node) collector << if srid == 0 "#{st_func('ST_WKTToSQL')}(#{quote(node)})" else "#{st_func('ST_WKTToSQL')}(#{quote(node)}, #{srid})" end when RGeo::Feature::Instance collector << visit_RGeo_Feature_Instance(node, collector) when RGeo::Cartesian::BoundingBox collector << visit_RGeo_Cartesian_BoundingBox(node, collector) else visit(node, collector) end end |
#visit_RGeo_ActiveRecord_SpatialNamedFunction(node, collector) ⇒ Object
38 39 40 |
# File 'lib/active_record/connection_adapters/mysql2rgeo/arel_tosql.rb', line 38 def visit_RGeo_ActiveRecord_SpatialNamedFunction(node, collector) aggregate(st_func(node.name), node, collector) end |
#visit_String(node, collector) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/active_record/connection_adapters/mysql2rgeo/arel_tosql.rb', line 29 def visit_String(node, collector) node, srid = Mysql2Rgeo.parse_node(node) collector << if srid == 0 "#{st_func('ST_WKTToSQL')}(#{quote(node)})" else "#{st_func('ST_WKTToSQL')}(#{quote(node)}, #{srid})" end end |