module Decidim::Geocodable

This concern overrides some of the Active Record functionality injected by the Geocoder gem in order to pass the geocoding searches through Decidim's own API which configures the geocoder correctly for each search. This is used when the `model.geocode` and `model.reverse_geocode` methods are called for the Active Record models.

NOTE: This module is automatically loaded for all active record models in

the "decidim.geocoding_extensions" initializer. It does not need to be
included separately into any models.

Public Instance Methods

do_lookup(_reverse = false) click to toggle source

rubocop:disable Style/OptionalBooleanParameter

Calls superclass method
# File lib/decidim/geocodable.rb, line 37
def do_lookup(_reverse = false)
  RecordGeocoder.with_record(self) do
    super
  end
end
geocoded_and_valid?() click to toggle source
# File lib/decidim/geocodable.rb, line 30
def geocoded_and_valid?
  geocoded? && to_coordinates.none?(&:nan?)
end
geocoder_init(options) click to toggle source

Avoid double loading Geocoder::Store::ActiveRecord since it's already loaded by this concern (below in the included block).

# File lib/decidim/geocodable.rb, line 21
def geocoder_init(options)
  @geocoder_options = {} unless defined?(@geocoder_options)
  @geocoder_options.merge! options
end