Module: Arel
- Defined in:
- lib/arel/visitors/postgis.rb
Defined Under Namespace
Modules: Attributes, Nodes, Visitors
Class Method Summary collapse
-
.spatial(value) ⇒ Object
Add Arel.spatial() method.
-
.st_make_point(x, y, srid = nil) ⇒ Object
Add Arel.st_make_point() method that properly handles floats for Rails 8.1.
Class Method Details
.spatial(value) ⇒ Object
Add Arel.spatial() method
142 143 144 |
# File 'lib/arel/visitors/postgis.rb', line 142 def self.spatial(value) Arel::Nodes::SpatialValue.new(value) end |
.st_make_point(x, y, srid = nil) ⇒ Object
Add Arel.st_make_point() method that properly handles floats for Rails 8.1
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/arel/visitors/postgis.rb', line 147 def self.st_make_point(x, y, srid = nil) # Wrap floats in SqlLiteral nodes to avoid Rails 8.1 Arel strictness x_node = x.is_a?(Numeric) ? Arel::Nodes::SqlLiteral.new(x.to_s) : x y_node = y.is_a?(Numeric) ? Arel::Nodes::SqlLiteral.new(y.to_s) : y if srid srid_node = srid.is_a?(Numeric) ? Arel::Nodes::SqlLiteral.new(srid.to_s) : srid Arel::Nodes::NamedFunction.new( "ST_SetSRID", [ Arel::Nodes::NamedFunction.new("ST_MakePoint", [ x_node, y_node ]), srid_node ] ) else Arel::Nodes::NamedFunction.new("ST_MakePoint", [ x_node, y_node ]) end end |