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
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb', line 53 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
64 65 66 67 68 69 |
# File 'lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb', line 64 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
71 72 73 |
# File 'lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb', line 71 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
75 76 77 78 79 80 81 |
# File 'lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb', line 75 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 |