The geocoder: one system, every address
Demo::Geocoder gives each Address a
Geolocation in the same slot. It reads the
addresses table, so sellers' and customers' addresses are
handled in one pass, and it never names User or
Company.
Demo::Gazetteer), nudged per address. No service
is called, and the points are not real locations.
Map · 3 located addresses
Geolocation.where(entity: Company.all): the component
table has no idea what owns a row, so the type comes from the owner's scope.
Places on the map
- Cambridge and London 2 companies
- New York 1 company
Addresses · 3
An address is waiting
when its pair is missing or older than the address. Edit an address on a
person's page, come back, and run the
geocoder again: only that address is redone. Orders and invoices keep
address snapshots with no Geolocation declared, so they are
not paired and never geocoded.
| Owner | Slot | Address | Geolocation | State |
|---|---|---|---|---|
| Company Analytical Engines Ltd | (default) |
1 Marylebone Rd, London, NW1 5LR, GB | 51.49915, -0.12319 | Located |
| Company Nanosecond Supply Co. | (default) |
900 Broadway, New York, NY, 10003, US | 40.72216, -74.00630 | Located |
| Company Turing Press | (default) |
24 Kings Parade, Cambridge, CB2 1SP, GB | 52.20605, 0.12579 | Located |
Declared, not configured
Pairing is two declarations in the same slot. The geocoder asks each owner's class whether it declares the pair, so a new entity type joins in without a change to the system.
class User < ApplicationEntity
component Address, prefix: :shipping
component Geolocation, prefix: :shipping
component Address, prefix: :billing
component Geolocation, prefix: :billing
end
class Company < ApplicationEntity
component Address
component Geolocation
end
Still one migration
The geolocations table was created by
rails g ecs_rails:install along with the rest of the
catalogue. Adding the geocoder needed no new table and no migration.
db/migrate holds:
20260904080008_ecs_rails_install.rb
Read the geocoder's source on GitHub.