You're receiving this email because you're an Engine Yard customer or you signed-up for the Engine Yard newsletter on our website.
You can unsubscribe immediately. Having trouble viewing this email? Read this on the web.

Engine Yard Newsletter logo

Engine Yard Newsletter

April 6, 2010 — Published by Engine Yard

Welcome to the Engine Yard Newsletter.

Here, you'll find valuable information about Engine Yard Cloud and cloud computing, Ruby and Rails tips, news and events, important security updates, top Engine Yard blog posts, and more.

Watch a live demo of Engine Yard Cloud and see how easy it is to deploy an application on the Cloud!

In This Issue:

  1. Inside Rails: What Carl Lerche Likes About Rails 3
  2. Evan's Ruby Tips: Fun With The Standard Library
  3. Engine Yard Customers Get Discounts On New Relic RPM Products!
  4. JRuby in Practice: JRuby Helps 8th Light Create Quality Software
  5. Top Posts From The Engine Yard Blog
  6. News From The Cloud: Cloud Beta Program, Ruby 1.8.7, Rails 3 and more!
  7. Events @ Engine Yard

Inside Rails: What Carl Lerche Likes About Rails 3

Yehuda Katz and Carl Lerche, Rails experts and core team members, present expert advice and insight on the Rails platform and Rails development.

With the Rails 3 release approaching fast, the feature set is basically set. We're currently in a beta cycle, with gems released to the public for feedback. Any changes at this point will be mostly driven by community feedback. So much was actually accomplished—let's look at three things I'm particularly happy about.

1. Lots of deleted code

I think one of the biggest successes is the actual state of the Rails codebase. Rails has been around for about 6 years now, and legacy accumulates. One of the ongoing efforts has been just to cleanup the code. An interesting metric is comparing the actual library code in the 2.3 branch against master. Even after adding many new features, and a new top level framework (ActiveModel), the total amount of code has remained about the same! That's because a lot of Rails has been DRYed up, reorganized and made more modular, effectively deleting a lot of code. This makes it easier for someone going through the library to understand what's going on. As someone who spends most of their day in the code base, this makes me very happy.

2. Extensibility

The promise of extensibility was one of the biggest draws to Merb, and I believe that Rails 3 is even more extensible. I like hacking and customizing my framework when I'm working on an app, and I'm sure that there are a lot of other developers like me out there. For example, I really like the DSL that Sinatra provides to define routes—it's really nice for throwing some stuff together quickly. So, I decided to write a Rails 3 plugin to give me the ability to use the same DSL in controllers, and it only took 33 lines of Ruby. Other people have told me that they've had similar experiences when updating plugins to the latest Rails.

3. Arel

In the olden days, ActiveRecord created it's SQL queries via a lot of string manipulation. As it turns out, there is a much better way to do this. Nick Kallen spiked out Arel, a relational algebra library, and now it's ActiveRecord's backbone. It's a much better abstraction that allows complicated queries to be represented in Ruby and then converted to SQL. As the work continues on this front, eventually ActiveRecord should be able to accept arbitrary relational data stores, not just SQL databases, as backends. I've always wanted to be able to do User.has_many :tweets, and have the actual join between the DB and the twitter API handled for me. This isn't far on the horizon (anybody want to attempt a plugin?) thanks to the work done on Arel and its integration into ActiveRecord.

I'm sure most of you have heard the main features of Rails 3 mentioned a lot before as there already is much excitement around it. I hope that you've found my personal favorites interesting. There is still a bunch of work to be done before the official Rails 3 release is out, and a lot of that is on the community trying it out. So, grab the beta, give it a spin, and give us your feedback.

 

Evan's Ruby Tips: Fun With The Standard Library

Evan Phoenix, Rubinius creator and Ruby expert, presents tips and tricks to help you improve your knowledge of Ruby.

Ruby comes with a vast standard library of code to use straight out of the box. In this tip, we're going to cover some of the rarely used highlights (and lowlights) in the library.

un.rb:

un.rb is a cute little script designed to be run like "ruby -run" (see the joke? By being named un, you can load it as -run). It provides a simple interface to FileUtils, which is another standard lib gem that provides a vast array of methods for working with files. un.rb appears to be designed to be used by programmers when they don't want to depend on the standard OS commands. For example, to copy a file you can use "ruby -run -e cp -- filea fileb" instead of "cp". Check out the top of un.rb for the list of all supported commands.

abbrev.rb:

abbrev.rb provides some methods for generating unique abbreviations for a list of strings. This is a good example of a small, simple algorithm provided by the standard lib rather than a big library. As the rdoc points out, it's easy to use too:

Abbrev.abbrev(['car', 'con']) => {"co"=>"con", "con"=>"con", "ca"=>"car", "car"=>"car"}

find.rb:

Another file oriented library, find.rb provides Find.find which is a method that automatically traverses down directories like the unix 'find' command. On each entry, it yields to the passed block. Find.find is another good example of a simple algorithm wrapped up so that you don't have to reimplement it.

e2mmap.rb:

I've provided e2mmap.rb on here primarily as an archeological find. As you can see from the header of the file, it was written for ruby 1.1 originally and for the most part hasn't been changed since then. It's largely abandoned now because the functionality it provides wasn't needed given how Ruby's exception system evolved. It sits today as an example of what not to do—setting the current exception ($!) directly, for instance.

English.rb:

English.rb is a hold-over from the days when Ruby and Perl were much closer together. Perl provides an English file, which gives the magical globals easier to understand names, so Ruby ended up providing the same thing. For example, after requiring English.rb, you can access the current exception as $ERROR_INFO rather than $!, or the current process id number as $PID rather than $$.

shellwords.rb:

Another algorithm library, this provides Shellwords.split, a method that can parse a String like a unix shell would. For instance:

Shellwords.split("hello 'ruby tipsters'") => ["hello", "ruby tipsters"]

You'll see it respects the embedded quotes just as a unix shell would. It also provides Shellwords.escape, which will escape a string so that it can be passed to a shell without being mangled:

Shellwords.escape("path with weird' stuff") => "path\\ with\\ weird\\'\\ stuff"

It's a little strange to see with the extra escaping that inspect adds, so here's what it would look like printed out:

path\ with\ weird\'\ stuff

So there you go, some interesting and useful libraries for you to use in your code without having to reimplement.

See you next time!
 

Engine Yard Customers Get Discounts On New Relic RPM Products!

Did you know that Engine Yard and New Relic have partnered to make New Relic RPM available to you at discounted prices, and in some cases at zero cost?

New Relic RPM is a SaaS application performance management solution that enables you to monitor, troubleshoot and tune production Ruby on Rails web applications. RPM comes in three subscription levels, Bronze, Silver and Gold, to meet the needs of any organization. Here's how to get started:

* If you are an Engine Yard Cloud customer, you can sign up for any RPM subscription level at a discounted price. Just contact New Relic sales (sales@newrelic.com) to find out more. Current Engine Yard and New Relic customers moving to Engine Yard Cloud require a new RPM License. Please contact our sales group and we'll get you up and running.

* Engine Yard Private Cloud customers are eligible for access to a New Relic RPM Bronze-level subscription at no charge. Sign up now directly through New Relic. (https://rpm.newrelic.com/signup/19?partnership_id=1

* And if you are an Engine Yard Private Cloud Fractional or Dedicated Cluster customer, you get RPM Silver at no charge. Just sign up for an RPM Bronze account (https://rpm.newrelic.com/signup/19?partnership_id=1) and contact your Engine Yard Sales Representative to be upgraded.

JRuby in Practice: JRuby Helps 8th Light Create Quality Software

This guest article was written by Doug Bradbury and Colin Jones, Software Craftsmen at 8th Light Inc.

"It's kind of a Frankenstein." We've used this phrase more than a few times to describe the architecture and technology used to design a product that was recently released after almost a year of development by the software craftsmen of 8th Light. The product is a multi-platform, PC management application for library computer labs written primarily in Ruby, run on the JVM with JRuby. The user interface is written in erb-templated HTML and Javascript, and is displayed in an embedded web browser. JNA (Java Native Access) is used to call operating system specific functions that enable an insane amount of control over the desktop. The various JRuby components communicate with each other over DRb.

But the most amazing thing about this project is that we are using JRuby to deliver a portable, rich desktop app using the best of web technologies. We chose JRuby because it increased portability and performance and reduced development time.

At 8th Light we had tried before to build products for our clients using Ruby, but we always hit a dead end when it came to deployment. For our clients who provide software products instead of software services, the applications must install easily and completely on the end customers machines while still protecting the intellectual property of our client. We tried very hard to make technologies like RubyScript2exe work, but in the end a packing and unpacking solution was too slow and still left our client's source code open for the reading on the installed computer.

As we began the project about a year ago, we discovered that JRuby had reached the point where it could be a viable platform for us to be able to build products that our client's customers could easily deploy in their own environments. Our solution was to bundle all of our JRuby code into jars after it had been encrypted. By patching into the JRuby load service we were able to decrypt the source on the fly and leave the code bundled and encrypted on the disk at all times.

JRuby allows us dirt simple access to Java's huge collection of libraries, along with plenty of custom Java libraries our client had already written. We also go back the other way, implementing Java interfaces in JRuby and using those objects in Java code. This fluidity allows us to always pick the best tool for the job. Early in the project, this also helped to sell the technology to our client. They were wary of a new language that none of their in-house developers knew, but we were able to reassure them that they could easily drop back into Java at any time.

At one point in the project, the client's development team jumped on the project to add a new configuration interface to the server side of the application. The team wanted to use a set of Java tools that they were already familiar with, but needed to make calls into the JRuby side of the application to get and set the configuration values. We built a new Java interface for them and implemented it in JRuby—then from our Ruby initialization code, called a static Java function back on the Main class, passing in the configuration object. This allowed the client's team to initialize their java objects with the instance of our JRuby class that we had provided.

//The Java Interface
public interface ConfigurationStore
{
 void put(Map<String, String> pairs);
 void put(String key, String value);
 String get(String name);
}
#The Ruby Implementation
class ConfigurationStore
 include Java::package.ConfigurationStore
  def get(key)
  .....
  end
#Notice how we were able to implement the function overloading present in the interface by
#using a variable arguments in one ruby method.
 def put(*args)
  if args.size == 2
   ....
  elsif args.size == 1
   .....
  else
   raise ArgumentError.new("put() takes a Hash (or a Java Map) or a key and value pair")
  end
 end
end

We wanted to be extra sure that the class we were writting in Ruby would work from Java before we handed it over, so in addition to the rspecs we wrote to test the Ruby class, we also wanted to write a JUnit Test. Normally, we inject a JRuby object into Java by calling a Java function from a JRuby method and passing along the JRuby object that is to be used. In this case we wanted to actually instantiate the Ruby object in the setup of a JUnit test. We dug around in the JRuby APIs and were able to leverage the fact that the RubyRuntimeAdapter returns the last thing evaluated. We were able to use the toJava() method on the IRubyObject returned from eval and cast the result into the interface class. Then we were free to write JUnit tests exercising the functionality of the JRuby class.

// instantiating a Ruby object in Java
RubyInstanceConfig config = new RubyInstanceConfig();
Ruby runtime = JavaEmbedUtils.initialize(new ArrayList(), config);
RubyRuntimeAdapter evaler = JavaEmbedUtils.newRuntimeAdapter();
IRubyObject result = evaler.eval(runtime, "require 'configuration_store';" +
"config_store = ConfigurationStore.new");
store = (ConfigurationStore) result.toJava(ConfigurationStore.class);

We do a lot of things at 8th Light to ensure that we can deliver very high quality code to our clients as fast as is responsible. One of the most important things we do is work in highly productive languages. JRuby enables us to write most of the complicated business logic of our application in the highly productive Ruby language and still provide a viable deployment scheme that allows our clients to successfully sell their product to their customers.

 

Top Posts From The Engine Yard Blog

Ruby Scales, AND It's Fast - If You Do It Right

Author Kirk Haines writes, "Some Ruby implementations may be "slow", but even then, architecture wins. On a low level, you can write some surprisingly fast software with Ruby if you keep your scope focused, and on a high level, a few simple architectural choices can help make even a slow application appear fast to your users." Read the full post here.

Rails and Merb Merge: Rack (Part 6 of 6)

In the final post of his can't-miss 6 part series, Yehuda Katz discusses how Rails 3 uses Rack to make sharing web apps even easier! Read it here, or start from the beginning with his first post in the series: Rails and Merb Merge: The Anniversary.

Making Ruby Fast: The Rubinius JIT

Evan Phoenix takes the lid off of the Rubinius JIT compiler, exposing the process it uses to transform source code into machine code. If you're a Rubyist (or even if you aren't), be sure to check it out!

News From The Cloud: Cloud Beta Program, Ruby 1.8.7, Rails 3 and more!

We are excited to announce a new Beta Program for Engine Yard Cloud. This is an opt-in program for users to use beta-only features before we open them up for everyone. If you like staying on the cutting edge, have a favorite feature that you just have to try today, or would like to help us by providing feedback on upcoming features, this is the program for you.

What features are you making available in the beta program?

We have an exciting lineup ahead, but for today we’d like to announce a couple of features that we know a lot of you are waiting for.

The first one is support for Ruby 1.8.7. You can now update individual environments to use either Ruby 1.8.6 or 1.8.7. To do so, simple go to the edit environment page for an existing application and change the Ruby version there, or create a new environment. As part of this change, we have also isolated the system Ruby used to run the Engine Yard management stack from the version that your applications would use. This change has resulted in greater stability on the platform, and will also allow us to add newer Ruby versions easily to the platform.

As a result of this, we are now also ready for Rails 3 when it releases. If you like to stay on the bleeding edge and do not require support for non-production applications, you can use the Rails 3 pre-release gems today (just make sure to switch your environment to use Ruby 1.8.7).

How does the Beta Program work?

Its simple – just email beta@engineyard.com with your Engine Yard Cloud login email address. We will be rolling out access to Ruby 1.8.7 over the coming few days to all beta customers who sign up.

Thanks for helping us test out our newest set of features, and watch this space for more product-related announcements soon!

Events @ Engine Yard

After a whirlwind March, we're ramping up for another busy month. Take a look at what we've got coming up in April. If you're planning on attending any of these events, be sure to get in touch. We'd love for you to join us!

Emerging Technologies for the Enterprise
April 8-9
Philadelphia, PA

The 5th annual Emerging Technologies for the Enterprise event will take place April 8 and 9 in Philadelphia, Pennsylvania. We've participated several times now and always look forward to this well planned event. Two Engine Yard speakers are on the roster this year. This event usually sells out so if you'd like to attend, register soon!

RubyNation
April 9-10
Reston, VA

The 3rd annual RubyNation will take place April 9 and 10 just outside DC in Reston, Virginia. We always enjoy this fantastic regional event and have two Engine Yard speakers lined up. Nick Sieger of the JRuby team will be presenting "Rails: The Killer Java Web Stack." Corey Donohoe will also be speaking -- don't miss his "Mocks Aren't Stubs, and Fakes Are Better" presentation on the importance of testing and fakes. Keep an eye on the Ruby Nation website for up-to--date schedule details.

Palmetto Open Source Software Conference (POSSCON)
April 15-17
Columbia, SC

The 3rd annual Palmetto Open Source Software Conference is taking place April 15 through 17 in Columbia, South Carolina. We're excited to be participating for the first time. This unique event targets developers, educators, and business executives -- with plenty of sessions and workshops tailored for each. Rails Core Team Member Yehuda Katz will be presenting on the core principles of Rails, and how to apply them to your own open source project. He'll also be leading a two hour Rails 3 tutorial. Check out the event site for schedule details to be posted shortly.

Cloud Computing Conference & Expo
April 19-21
New York, NY

The Cloud Expo and Conference is taking place April 19-21 at the Javits Convention Center in New York. This event has steadily grown in size and scope since its inception.

Our CTO and Founder, Tom Mornini, will be joining our friends at Terremark, participating as a part of the Performance, Standards, Storage & Hosting track. The presentation will delve into the architecture and benefits of a Rails-based Platform-as-a-Service.

The San Francisco Ruby Group
April 21
San Francisco, CA

We'll be hosting the April meeting for the first time out of Engine Yard HQ. Swing by to check out some interesting presentations on Tropo and an intro to Behavior Driven Development with RSpec and Cucumber.

The Silicon Valley Ruby User Group
April 22
Moffett Field, CA

Join Rails Core Team Member Carl Lerche for an introduction to Rails 3. Following Carl's presentation, there will be a Rails 3 for Newbies Code Clinic. This is the perfect opportunity for you to roll up your sleeves and dig in with a number of experts on hand to help answer questions.

 

But wait, there's more.

Randall Thomas will be continuing his user group tour, visiting with folks and giving a presentation on machine learning and data mining, incorporating Ruby based examples and Engine Yard Cloud. After hitting up groups in Boulder, Vancouver and Seattle last month, Randall is looking forward to also visiting:

The Portland Ruby Brigade (PDX.rb)
April 6
Portland, OR

The Los Angeles Ruby Group (LARuby)
April 8
Los Angeles, CA

We hope you can make it out to an event in your area. If you've got any questions, be sure to drop our events team a line at events@engineyard.com.

Forward to a friend!     |     Change my preferences      |     Unsubscribe