Use different ruby version in one project in rails - ruby

I am building rails application using rails 3.2.13 and ruby 2.0.0
I have to use this http://www.pdftron.com/pdfnet/samplecode.html library which support only ruby 1.9.2 , i tried it for ruby 2.0.0 but had no luck. It is working fine with ruby 1.9.3.
I don't want to downgrade to ruby 1.9.3, so is there any way so that I can use this library without downgrading , maybe using Rails Engine or building another Rails::API app in ruby 1.9.3 .
Any help or suggestion ?

If you build a totally different application and then make HTTP API calls from one to the other, you could have the two applications running on different ruby versions. But it would be more performant if you didn't have to go over the network, and of course the cost of maintaining and running 2 applications is more than one.

I managed to Solve this problem by using Java library of PdfNet along with RJB.

Related

How to check for API compatibility between Ruby versions?

Our team maintains a ruby script that must support any ruby >= 1.9.3 (yes, that's a pretty old ruby version but this is something outside our control at the moment). Recently, we added a change that included the verification of a regexp using match? and everything was going well until one of the users reported that the script was exploding for ruby 2.3 with the message:
undefined method `match?' for #<Regexp:0x000000018471e0> (NoMethodError)
Turns out this happens because the match? method is available in ruby >= 2.4.
We have been running ruby -c script.rb with multiple versions of ruby (1.9.3, 2.0.0, 2.1.10, 2.3.7, 2.5.1, 2.6.3, 2.7.4) as part of our test suite and this didn't show up as a syntax error and I suspect it's because the actual syntax is "correct" but the method is simply not available in some versions of ruby. We also tried rubocop, hoping that it could detect these incompatibility issues but it doesn't report any error either.
So, my question is, what's the best way to check for this API compatibility issues between multiple ruby versions?
Running ruby -c with the oldest Ruby you support is a good start, as it will detect if you are trying to use a newer syntax.
For using methods that are new:
Run your tests suite in both the oldest and newest Ruby versions you want to support.
Consider using my backports gem to make it possible to use newer API even on old Rubies. For example, it includes Regexp.match? among the hundreds of backports...
Do you have an automated test suite? If so, you can set up your CI to test against multiple Ruby versions, e.g.:
https://github.com/actions/setup-ruby#usage
(Edit: I see you did mention a test suite, so it sounds like you have a gap in the test coverage, or you're not running the tests against each Ruby version?).

Ruby : What changes needed to make test-unit-1.2.3 working with Ruby-2.4.1

I am new to Ruby Development. Now i am working on ruby test-framework code which was working fine with Ruby-1.8.7
Now i want to upgrade ruby for this framework. I have found that test-unit-1.2.3 is included in Ruby-1.8.7 so i have installed it separately with Ruby-2.4.1.
Currently i am facing method missing issue ["register_autorunner"] with this combination. Because these method have not been used in ruby-1.8.7
Can anyone please tell me other changes needed to make this combination [Ruby-2.4.1 , test-unit-1.2.3] working.
Thanks in advance
You should update to TestUnit 3.x, which will have a higher chance of working with Ruby 2.x. Then you need to figure out the changes between Ruby 1.8.7 and Ruby 2.4.1, and how to fix your existing code, which is most likely broken, even after you have fixed/updated your unit test configuration.
Also, consider a switch to Minitest or Rspec, as they are a lot more popular today, so it will be easier to find examples and supporting tools for them. Minitest is also the default test framework used by Ruby on Rails currently.
References:
https://www.jetbrains.com/research/devecosystem-2017/ruby/
http://guides.rubyonrails.org/v5.1/testing.html

Issues after upgrading Ruby & Rails

I upgraded my Ruby to 2.1.2 & I upgraded Rails to 4.1.2.
I currently have 2 issues that I can't seem to get passed and they may be interconnected.
First, I get this error: Could not find attr_encrypted-1.3.2 in any of the sources when CLEARLY when I run bundle install it says Using attr_encrypted (1.3.2).
Second, before this, I noticed that when I do rails c the version of Ruby is 2.0.0, but ruby --version outputs ruby 2.1.2p95 and rvm lists shows that I am using Ruby 2.1.2. Frustrating, and I think these issues may be interconnected.
bundle install does not fix it. Deleting my Gemfile.lock does not fix it.
Bet its spring again, caching your app.
spring stop
Edit 1
Spring is a rails application preloader. It caches the app, making running rails commands, task, tests etc. faster by saving rails load time. It's default since rails 4.1. Check your bin folder. There will be binstubs within. Open bin/rails and you'll see it loading spring which does the caching magic.
In 99% of the time rails will pick up your code changes. But this won't be the case on changing startup code like gem loading.

How to keep two different versions of Ruby on the same machine without conflict?

I have installed Ruby 2.0.0 and Ruby 1.9.3-p392. But lots of gems, like nokogiri and selenium-webdriver, are not compatible with 2.0, thus I am bound to keep 1.9.3 on my Windows machine. Now the problem is 2.0.0 get rides on 1.9.3. Thus I am not able to run the code which is using the aforementioned gems from my editor Sublime Text 2.
Thus any idea how to keep them both on the same machine without any conflict?
I got couple of sources to do so:
Ruby version manager
Setting the default ruby with Pik

Rails 2.x launcher script was found instead of Rails 3.x one a lot in RubyMine

keep getting this message in rubyMine
I think the solution here should solve your problem:
Rails 2.x app on RubyMine 3.1
You probably have the rails 2.x gem attached to your RubyMine settings. Go to File > Settings and take a look at Ruby SDK and Gems. Make sure you have rails 3.x selected, and not something else.

Resources