Search code examples
ruby-on-railsgmaps4rails

gmaps4rails -- how to check value of process_geocoding?


I'm using gmaps4rails and want to check the current value of "process_geocoding" (i.e., check if it is true or false).

The reason for this is I want to add a crude "rate limiter" (sleep 0.25) when saving a lot of records at once (so that I don't get over_quota errors from Google), but I only want to do this if process_geocoding is currently set to true (and !gmaps, but that part is easy).

I assume this is super simple, but for the life of me can't figure this out.

I tried the obvious:

if Building.acts_as_gmappable :process_geocoding
  do stuff
end

But that didn't work.

Any help would be greatly appreciated.


Solution

  • The author of this gem answered my question over on github:

    https://github.com/apneadiving/Google-Maps-for-Rails/issues/374

    The correct way to do this is to check gmaps4rails_options on the instance not on the Class, i.e.:

    your_object.gmaps4rails_options[:process_geocoding]
    

    So in my case:

    building.gmaps4rails_options[:process_geocoding]
    

    Since the setting is "global", I don't believe it matters which instance you check. Not sure why I can't just call this as a class method, but this works regardless.