Code Monkey home page Code Monkey logo

Comments (15)

alexevanczuk avatar alexevanczuk commented on August 30, 2024 2

Nice! I was just working on this now. I was working on adding an active_record_adapters module and was planning on having an adapter for active record 4 and active record 5. I'll leave my thoughts on one vs the other in that PR though!

from sorbet-rails.

alexevanczuk avatar alexevanczuk commented on August 30, 2024 1

Sure -- happy to submit a PR. About to head out for the day, but I'll see if I can send something over later tonight.

from sorbet-rails.

jasnow avatar jasnow commented on August 30, 2024 1

Check out slide 22 of this "RubyKaigi2019 Ruby 3 Progress Report" slide deck regard merged bundler into rubygems:
https://docs.google.com/presentation/d/1z_5JT0-MJySGn6UGrtdafK1oj9kGSO5sGlTtEQJz0JU/edit#slide=id.g55232ea080_0_59

from sorbet-rails.

hdoan741 avatar hdoan741 commented on August 30, 2024

Oh. It's a version thingy. We've supported 5.1.7 and 5.2.3 currently.
It looks like an easy fix in model_rbi_formatter -- 4.2.10 probably don't support through_reflection?.
Please feel free to add support for 4.2.10 following the same pattern it's added for 5.1.7.

We're drafting a Contribution guide but feel free to message me if you run into any issue testing.

from sorbet-rails.

hdoan741 avatar hdoan741 commented on August 30, 2024

I just checked. Rails 4.2 doesn't have through_reflection? but it does have a through_reflection object. The fix might be as simple as falling back to through_reflection.present? if through_reflection? doesn't exist

See
https://www.rubydoc.info/gems/activerecord/4.2.4/ActiveRecord/Reflection/HasManyReflection

from sorbet-rails.

alexevanczuk avatar alexevanczuk commented on August 30, 2024

I've patched model_rbi_formatter.rb locally in the following way to get this working. Here is an rbi formatter diff that appears to be working for activerecord 4.2.

<     reflection.through_reflection? ?
---
>     reflection.through_reflection ?
278c278
<     cast_type = ActiveRecord::Base.connection.lookup_cast_type_from_column(column_def)
---
>     cast_type = column_def.cast_type
303c303
<     when ActiveRecord::Enum::EnumType, ActiveRecord::Type::Binary, ActiveRecord::Type::String, ActiveRecord::Type::Text
---
>     when ActiveRecord::Type::Binary, ActiveRecord::Type::String, ActiveRecord::Type::Text

The changes are:

  1. through_reflection instead of through_reflection?.
  2. Getting the cast_type is just column_def.cast_type
  3. There is no EnumType in 4.2

from sorbet-rails.

hdoan741 avatar hdoan741 commented on August 30, 2024

Thanks @alexevanczuk. Awesome job! Would you like to submit a PR? We're working on adding spec for 4.2 soon!

from sorbet-rails.

alexevanczuk avatar alexevanczuk commented on August 30, 2024

@manhhung741
I've begun looking into this, and I've found the following things:

  1. I'm having difficulties pushing a branch. is there something that needs to be set up on your side or do you know if this is on my side?
~/workspace/sorbet-rails - (ae-support-rails-4.2 !) $ git push
remote: Permission to chanzuckerberg/sorbet-rails.git denied to AlexEvanczuk.
fatal: unable to access 'https://github.com/chanzuckerberg/sorbet-rails.git/': The requested URL returned error: 403
  1. I'm starting this by working on getting tests supported with Rails 4.2. However, Rails 4.2 requires bundler < 2, and the current lockfile is generated using Bundler 2. I think maybe this library could switch to using https://github.com/thoughtbot/appraisal, which was specifically made for this purpose. It allows for testing against multiple Gemfiles and has support for Travis.

I think getting the Rails 4.2 tests setup would be a nice thing to have prior to doing this. I'd sequence it as follows:

  1. Transfer existing tests and test set up to use Appraisal
  2. Add 4.2 tests, skipping tests that fail
  3. Fix the failing tests using a cleaner version of the diff above, possibly through the use of adapters, or maybe just starting simpler/more explicit by pulling the different parts into a method that is conditional on Rails version.

I'd be happy to help with this, but it will take longer than tonight for me to do this, and I'm heading on vacation for 10 days starting tomorrow night. That being said, still happy to help look into this when I'm back from vacation!

from sorbet-rails.

hdoan741 avatar hdoan741 commented on August 30, 2024

Ah, you'd have to

  1. Fork the repo
  2. Make a commit
  3. Push to your repo
  4. Make a pull request

I think getting the Rails 4.2 tests setup would be a nice thing to have prior to doing this

I'm trying to set up tests for Rails 4.2 but it's not trivial. I should have it working soon -- or tomorrow. If you can get sorbet-rails work with your 4.2 rails app following the CONTRIBUTE guide, it'd be enough to send out a PR. Once the test suite for 4.2 is set up, we can test & merge the PR.

from sorbet-rails.

hdoan741 avatar hdoan741 commented on August 30, 2024

Appraisal looks promising. I'll look into it too.

from sorbet-rails.

hdoan741 avatar hdoan741 commented on August 30, 2024

Also, enjoy your vacation @alexevanczuk

@aethos does @alexevanczuk patch work for you?

from sorbet-rails.

hdoan741 avatar hdoan741 commented on August 30, 2024

Checkout #48 I actually did it. It was crazy to set up spec for 4.2. Thanks to Alex's patch, I didn't have to look too hard into fixing the bugs with 4.2

from sorbet-rails.

hdoan741 avatar hdoan741 commented on August 30, 2024

Cool. Thank you :-) Please do send it our way. Your adapter maybe useful for handling multiple versions of ActiveRecords in the future.

The issue with setting up 4.2 is mainly in the fact that it needs bundler 1.x whereas some other version only want 2.0. And Travis doesn't like that either.

from sorbet-rails.

hdoan741 avatar hdoan741 commented on August 30, 2024

I've merged #48. This issue should be fixed and the gem now support Rails 4.2!

from sorbet-rails.

hdoan741 avatar hdoan741 commented on August 30, 2024

Check out slide 22 of this "RubyKaigi2019 Ruby 3 Progress Report" slide deck regard merged bundler into rubygems:
https://docs.google.com/presentation/d/1z_5JT0-MJySGn6UGrtdafK1oj9kGSO5sGlTtEQJz0JU/edit#slide=id.g55232ea080_0_59

Thanks @jasnow! That's super exciting!

from sorbet-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.