Module: ActiveRecordPostgresEarthdistance::Utils
- Defined in:
- lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb
Class Method Summary collapse
- .earth_distance(through_table_klass, lat, lng, aliaz = nil) ⇒ Object
- .ll_to_earth_columns(klass) ⇒ Object
- .ll_to_earth_coords(lat, lng) ⇒ Object
- .quote_value(value) ⇒ Object
Class Method Details
.earth_distance(through_table_klass, lat, lng, aliaz = nil) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb', line 64 def self.earth_distance(through_table_klass, lat, lng, aliaz = nil) Arel::Nodes::NamedFunction.new( "earth_distance", [ ll_to_earth_columns(through_table_klass), ll_to_earth_coords(lat, lng) ], aliaz ) end |
.ll_to_earth_columns(klass) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb', line 75 def self.ll_to_earth_columns(klass) Arel::Nodes::NamedFunction.new( "ll_to_earth", [klass.arel_table[klass.latitude_column], klass.arel_table[klass.longitude_column]] ) end |
.ll_to_earth_coords(lat, lng) ⇒ Object
82 83 84 |
# File 'lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb', line 82 def self.ll_to_earth_coords(lat, lng) Arel::Nodes::NamedFunction.new("ll_to_earth", [quote_value(lat), quote_value(lng)]) end |
.quote_value(value) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb', line 86 def self.quote_value(value) if Arel::Nodes.respond_to?(:build_quoted) # for arel >= 6.0.0 Arel::Nodes.build_quoted(value) else value end end |