Skip to content

Change city_lookup to load all configured cities#68

Open
duduribeiro wants to merge 1 commit intothecodecrate:mainfrom
duduribeiro:fix-lookup-cities
Open

Change city_lookup to load all configured cities#68
duduribeiro wants to merge 1 commit intothecodecrate:mainfrom
duduribeiro:fix-lookup-cities

Conversation

@duduribeiro
Copy link

@duduribeiro duduribeiro commented Nov 24, 2023

Closes #67
There is a problem with city_lookup. It only loads the cities for the first statue you called cities on. This is because cities memoizes all the cities for the country, but city_lookup only loads the cities for the state, and doesn't get called again for the other states.

Ex:

having the following db/cities-lookup.yml:

BR:
  GO:
    "Mutunópolis": "Mutunópolis"

If I load first cities for other state, it does not include this missing city:

bin/rails c
CS.cities(:sp, :br) # loading another state first
CS.cities(:go, :br).include?("Mutunópolis")

=> false

returned false but it should be true.

If I load this state first, it works correctly

bin/rails c
CS.cities(:go, :br).include?("Mutunópolis")

=> true

This commit changes city_lookup to load all the cities for the country.

Closes thecodecrate#67
There is a problem with city_lookup. It only loads the cities for the
first statue you called `cities` on. This is because `cities` memoizes
all the cities for the country, but `city_lookup` only loads the cities
for the state, and doesn't get called again for the other states.

Ex:

having the following `db/cities-lookup.yml`:

```yaml
BR:
  GO:
    "Mutunópolis": "Mutunópolis"
```

If I load first cities for other state, it does not include this missing
city:

```shell
bin/rails c
CS.cities(:sp, :br) # loading another state first
CS.cities(:go, :br).include?("Mutunópolis")

```

returned false but it should be true.

If I load this state first, it works correctly

```shell
bin/rails c
CS.cities(:go, :br).include?("Mutunópolis")

```

This commit changes `city_lookup` to load all the cities for the country.
@viviancan
Copy link

@duduribeiro Hello 👋 Any updates on this^? We are facing a similar issue when trying to add cities using the cities-lookup file. I have successfully renamed a country and state using the country and state lookup files but have not been able to add a city. Thx!

@duduribeiro
Copy link
Author

hey @viviancan 👋

I'm not a maintainer of the repo, so I can't merge.

What you can do is use this commit (like I'm doing in my app).

You can add this on your Gemfile

gem "city-state", github: "duduribeiro/city-state", branch: "fix-lookup-cities"

and check if it works on your case. It worked for me

@viviancan
Copy link

hey @viviancan 👋

I'm not a maintainer of the repo, so I can't merge.

What you can do is use this commit (like I'm doing in my app).

You can add this on your Gemfile

gem "city-state", github: "duduribeiro/city-state", branch: "fix-lookup-cities"

and check if it works on your case. It worked for me

@duduribeiro Thank you for the tip 😄 Hopefully there will be some feedback on this issue soon!

duduribeiro added a commit to duduribeiro/civitas that referenced this pull request Feb 19, 2025
City-state has two problemas that is prohibiting using the gem on most
recente ruby versions:
- thecodecrate#68
- thecodecrate#66

This commit applies these fixes
@duduribeiro
Copy link
Author

hey @viviancan 👋
I'm not a maintainer of the repo, so I can't merge.
What you can do is use this commit (like I'm doing in my app).
You can add this on your Gemfile

gem "city-state", github: "duduribeiro/city-state", branch: "fix-lookup-cities"

and check if it works on your case. It worked for me

@duduribeiro Thank you for the tip 😄 Hopefully there will be some feedback on this issue soon!

Hey @viviancan 👋

I tried to reach @loureirorg about these but without success. I created a new gem https://github.com/duduribeiro/civitas https://rubygems.org/gems/civitas which contains these fixes and I will try to apply future fixes as well, since I use these gem. It is an easy drop-in replacement for city-state (just replace city-state to civitas in Gemfile). I know this is not the best scenario but it is how I followed to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding a missing city is not working properly

2 participants