module ActiveRecordPostgresEarthdistance::Utils

Public Class Methods

earth_distance(through_table_klass, lat, lng, aliaz = nil) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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