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
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb', line 61 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
72 73 74 75 76 77 |
# File 'lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb', line 72 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
79 80 81 |
# File 'lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb', line 79 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
83 84 85 86 87 88 89 |
# File 'lib/activerecord-postgres-earthdistance/acts_as_geolocated.rb', line 83 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 |