简体   繁体   中英

Understanding the connection between JRuby, Rails, Gem, Rake, and Bundler

So someone at my work created a web application in JRuby a while ago, and I'm tasked with...

  1. Understanding the code
  2. Running the JRuby web application locally
  3. Determining whether to fix it up or rewrite it, add functionality, etc.

I'm completely new to JRuby and am kind of struggling with the basics. I'm staring at the code I pulled, containing the folders app, bin, config, lib, script, test, etc. and also containing a Gemfile, Gemfile.lock, a Rakefile, etc. I have no clue how to run this thing locally...


From what I can tell so far, there are a few interacting systems here. They are: JRuby, Ruby, Java, Rails, Gem, Rake, and Bundler . What I am struggling with is how they all work together.

JRuby - My understanding is that, with JRuby, you develop with the Ruby programming language, and it uses the Java Virtual Machine because of whatever benefits therein that I'm unaware of.

Ruby - Ruby has a framework specifically for building web applications, called Rails, which utilizes an MVC framework for ease in creating web applications. JRuby can work off of straight Ruby or Rails.

Rake - I'm not too sure what Rake is. I think it's basically Make. You call rake on a Rakefile and it can perform whatever tasks you specify.

Gem - I think gems are a way of packaging Ruby web applications (rake and bundler are gems?). I'm pretty baffled by this point. I think gem is a command line tool to package a Ruby web application, at which point you refer to it as a "gem."

Bundler - Very lost by this point. I think you define a Gemfile (unsure how Gemfile.lock is used), and use bundler to bundle all of the gems from this Gemfile together. Then you can just include all of these in your app with "require 'bundler/setup'"... although I think you have to require any gems that you defined in your Gemfile again in the app anyways?

JRuby - MRI Ruby (or C Ruby) is the original implementation of the Ruby language. MRI Ruby was written in C. JRuby is the implementation of Ruby on top of the Java Virtual Machine, and a lot of it is written in Java. I'm fuzzy on a lot of the finer details between JRuby and MRI Ruby, but here's what I know based off of what I've learned using JRuby:

  • JRuby is faster because it's multi-threaded. This means that it can manage multiple requests at once. MRI is not multi-threaded. Therefore, you'll see a lot of benchmarks between JRuby and Ruby, and you'll see that JRuby outperforms Ruby in terms of speed.
  • JRuby doesn't have as good gem support. This means that you'll be missing out on a lot of gems.
  • JRuby only recently got Ruby 2.2 compatibility with the release of JRuby 9.0.0.0. However, there's still a lot of kinks to be worked out with the latest version of Rails, so I would do a lot of research into making sure that there aren't major issues between JRuby 9.0.0.0 and Rails 4.2+.

Rake - you've essentially got this correct.

Gem - They're essentially packages of code you can integrate into your projects and run. This is probably the neatest feature of Ruby. Say you want to use the RSpec testing framework. It's super easy to get running if you include that in your project's Gemfile.

Bundler - Gemfiles are exclusive to Bundler. I like to think of Bundler as a dependency manager for your gems. You can specify what versions of each gem will run in your Gemfile, and when you run a bundle install, Bunder will pull and install the specific versions of each of the gems for you. Each bundle install or bundle update will update your Gemfile.lock, which lists out the versions that your project's gems are "locked" to. Gemfiles are exclusive to Bundler, so you'll also see things like .gemspecs floating around in other Rails engines or Rails apps that you may work on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM