LG-9449: Configure ArcGIS token job to respect mock geocoder setting#8702
LG-9449: Configure ArcGIS token job to respect mock geocoder setting#8702
Conversation
| class GeocoderFactory | ||
| def create | ||
| if IdentityConfig.store.arcgis_mock_fallback | ||
| ArcgisApi::Mock::Geocoder.new | ||
| else | ||
| ArcgisApi::Geocoder.new | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
proposal:
- call this a Router to match our
DocAuthRouter - make it a module, or at least ditch the instance method, there's nothing really to instantiate here because there's no state?
| class GeocoderFactory | |
| def create | |
| if IdentityConfig.store.arcgis_mock_fallback | |
| ArcgisApi::Mock::Geocoder.new | |
| else | |
| ArcgisApi::Geocoder.new | |
| end | |
| end | |
| end | |
| module GeocoderRouter | |
| module_function | |
| def geocoder | |
| if IdentityConfig.store.arcgis_mock_fallback | |
| ArcgisApi::Mock::Geocoder.new | |
| else | |
| ArcgisApi::Geocoder.new | |
| end | |
| end | |
| end |
so callsites would look like:
ArcgisApi::GeocoderRouter.geocoderThere was a problem hiding this comment.
Everything looks good in here. I like this suggestion.
There was a problem hiding this comment.
This is a factory pattern, so using Factory in the name makes more sense and is more informative to developers who aren't as familiar with this specific codebase. The Router naming is confusing because that is normally associated with routing web requests to a controller.
There was a problem hiding this comment.
I thought about making this a module, but based on my prior experience using an instance tends to be more useful and reusable. The decision does seem a little arbitrary without more established conventions around IoC though.
| sp: nil, | ||
| ).and_return(analytics) | ||
| allow(ArcgisApi::Geocoder).to receive(:new).and_return(geocoder) | ||
| allow(ArcgisApi::GeocoderFactory).to receive(:new).and_return(geocoder_factory) |
There was a problem hiding this comment.
bonus to switching to a class/module method: we don't need to stub :new (which is one of my biggest pet peeves)
🎫 Ticket
🛠 Summary of changes
📜 Testing Plan
Provide a checklist of steps to confirm the changes.