Skip to main content

Mobomo webinars-now on demand! | learn more.

In April, I announced GemNotifier, a new Intridea SparkTime project. GemNotifier is a web app I created to send notifications to users when the gems they subscribe to are updated.

Open Source Announcement

Today, I'm excited to announce that we are open sourcing GemNotifier. At Intridea, we have a long history of support for open source development, and we make every effort to open source tools and projects that can be of use to the greater development community.

The code for GemNotifier is hosted at Github. Anyone who might be interested in contributing to the project can fork it from Github and make pull requests. You can also submit any issues you encounter, using Github Issues.

Improvements

Before open sourcing GemNotifier, I took the feedback I received from users and made some key changes to the UI and overall functionality. The most requested feature was to be able to subscribe with Gemfile, which I added recently. GemNotifier also now has 100% test coverage and uses SASS.

What is GemNotifier?

If you missed the detailed post about GemNotifier in April, you can read it here. But for a quick rundown:

GemNotifier is a notification service that updates users when the gems they have subscribed to are updated. Rubyists can subscribe to their favorite gems (now using their Gemfile!) and they will get timely email notifications when those gems are updated. The service helps to keep you informed of changes and updates to the gems your projects are dependent on.

I'm looking forward to more feedback on the app from the community, so please share your thoughts below!

Categories
Author

A few years ago, I found RefactorMyCode.com by accident while searching for programming tips. I registered on the site right away because I liked the way it fostered sharing code with other programmers. It was a strong community that I wanted to be a part of.

Three months ago when I began my career at Intridea, I was prompted to select a SparkTime Project to work on in my spare time. At Intridea we are encouraged to work on interesting projects as often as we can. The SparkTime initiative allows us to organize our efforts and team up to accomplish things more efficiently. I was surprised when I found that RefactorMyCode was on the SparkTime list, so I signed up happily to help out.

About RefactorMyCode

One of my colleagues, Jon, talked about the RefactorMyCode project two months ago in a blog post. It was originally running on Rails 2.0.2, which was really out of date. Thus, I decided to upgrade it to Rails 3.0 before open-sourcing it.

What's new with RefactorMyCode in last few months?

RefactorMyCode.com

Upgrading from Rails 2.0.2 to Rails 3.0 has been time consuming since there is a two year gap between the two versions. The main difficulties have been to fix routes and ajax related issues. In this situation the rails_upgrade plugin has really helped out.

In our case, it helped to cancel some of the ajax requests and refactor them as direct requests for more flexibility. We removed the old will_paginate and used kaminari as the new pagination solution. Similar updates included upgrading to acts-as-taggable-on and syntax highlight functions with coderay.

We also refactored the existing authentication solution with omniauth, so the new Rails 3 version will allow you to login to RefactorMyCode via more third party services, such as Github, Twitter and LinkedIn etc.

Is It Ready for open source?

The answer is, YES! Or, yes, almost!

However, I am still adding RSpec test code to the Rails 3 version and I am also on the hunt for a better (pure Ruby) syntax highlighting solution. So far it seems that Albino will end up working well for this. The project will be open sourced very soon (in the next 1-2 weeks), and we'll make an announcement about that here on our blog and our Twitter account. We are looking forward to involving the community in this project!

Categories
Author

It's been close to a year since Rails 3 came out and I've had the pleasure of working on several Rails 3 projects since its release. Some existing gems became irrelevant with the release of Rails 3, while others lived. Additionally, we've seen many new gems come to life. I'd like to share a stack of gems that I've been using this year. Hopefully they will give people a bit of help while developing a new Rails 3 app.

Most of these gems have good documentation on their project wiki (every great gem should be well documented, right?), so I won't go into great detail about the mechanics. Instead, my aim is to introduce you to some of the gems I find most useful and separate them into meaningful categories, as a sort of reference guide.

Here we go:

» Authentication

The above two are really amazing gems for speeding up your authentication. Yes, I love both of them in different cases: ideally, OmniAuth is better for applications which want to support multi-provider external authentication, which is why I've just added OmniAuth into the RefactorMyCode Rails 3 branch to take advantage of its auth benefits. Devise is totally powerful enough for the classic authentication case. However, if you have too much business logic inside your login/registration/auth flow, you definitely need to make your own authentication.

» Access Control

Ryan is a star in the Rails world, so naturally his CanCan gem is really popular, but with good reason: it does really powerful authorization. However, declarative_authorization is also a good option. In fact, Ryan mentioned CanCan was inspired by declarative_authorization.

» Views/Page and Admin Scaffold

From a front-end perspective, I suggest you might want to try the above gems to speed up and simplify your UI design process. For example, rails_admin gives you a nice interface to manage your application's data.

» Quick SNS

These gems will allow you to prototype the basic functionality of your application quickly without having to worry about creating everything from scratch - so you can focus more attention on the meat of your application instead of the nuts and bolts.

» Form and Related Tools

Most of the above gems are famous through RailsCasts. There are two pairs of options here: simple_form and formtastic or paperclip and carrierwave. I like all these solutions, and you should pick the one that fits your project. If you want to know the differences between each pair, get more details on their wiki :) tiny_mce is an HUGE gem for rich editing; I list it here to remind you that it exists, but I recommend you get the WYSWYG via a JS lib like CLEditor - it works gracefully.

» Search Solutions

In regards to search in Rails, I bet there are some strong opinions out there. I want to split these gems into two types: Object-based searching and Full-Text searching. I highly recommend you use meta_search and/or meta_where for object-based searching because it can convert your form params directly to a search solution which is super convenient. Full-Test searching depends on your use-case, but all these three gems (thinking-sphinx, acts_as_indexed, sunspot) are great.

» Pagination

Yeah, you can use will_paginate in Rails 3, but I will suggest you should give kaminari a try, that's really cool.

» Background Work

These are two projects that accomplish basically the same thing. There is a post that introduces resque clearly here. In the post, the Github staff mentions their brief history of doing background jobs and they do a good job at highlighting the differences between the two.

» Status Machine

I like to use workflow a bit more than state_machine, since it's more natural to me. You definitely need one status machine to control your stable flow stuff, such as a registration flow status or a wizard-like features.

» Rack API framework

This gem is for adding REST-like APIs to your Rails/Sinatra application. Michael gave an awesome presentation at RubyConf2010 on Grape; I recommend watching it to see the greatness of Grape for yourself. I believe you will fall in love with it.

» Memcached Client

These two gems are actually mainly written by one same author Mike Perham. He mentioned that Dalli is a high performance pure Ruby client for accessing memcached servers. It works with memcached 1.4+ only as it uses the newer binary protocol. It should be considered a replacement for the memcache-client gem. The API tries to be mostly compatible with memcache-client with the goal being to make it a drop-in replacement for Rails.

» Deployment and Monitoring

I am not a system administrator, so I can't speak with any authority on this. That said, I do find these three gems come in handy with deployments and monitoring.

» Cron job and Backup as a Pro

These two gems are my favorites! Before I knew about these, I had to write complex and stupid scripts to do backups that I was not familiar with. Cron job is also a pain if you are not a system administrator. Now time changes and you, as a Ruby programmer, can do the cron job and backup in the Ruby way, surely as a PRO. :)

» Testing Gracefully

Testing is always important, and with the popularity of testing practices like TDD and BDD you have to own your super gun to play. These gems can help you out, although I didn't cover all the different levels of testing with these gems. But I will say, rspec is my favorite framework for testing, and factory_girl and faker are good supports. Anyway, test by your own way.

» Toolkit

There are many handy gems which will give you convenience and power. Take the above four as examples: "Ruby-Debug" lets you easily check your running application's context at specific program points; "Hirb" displays your AR items conveniently in a table view in console; "Cheat" brings tons of other gems' manuals into your terminal window for easy reference and; "Rails-Settings-Cached" is for global configurations in Rails 3 applications. Yeah, throwing the brick out is to meet your GEMS.

How to find great gems?

First, you need to follow Ryan's railscasts; he is good at introducing new stuff via video. Second, you can go through the GemFile of a great open source project that you love - this is definitely the best way to come across valuable gems. Third, just subscribe to github ruby trends to know what's going on in Ruby/Rails community. There are also some other good sites, like rubygems and railsplugins, where you can find useful gems with some poking around.

I originally shared this topic with all of the Intridea East Team members during our weekly Friday Tea-hour. You can find the PPT here. I wanted to share the list with more people, so I turned to our blog for that purpose. I'm sure I missed many valuable gems, so please share your thoughts in the comments!

Categories
Author

Today I'm introducing GemNotifier.org, a web app I built to deliver timely notifications about your favorite gem updates. It's a SparkTime project at Intridea and it's something I've been working on for the last month.

Why Build GemNotifier?

Simple, really; because there is a demand for it. Both for myself, and for other devs:

What Does it Do?

It's a very simple and useful concept. Rubyists can subscribe to their favorite gems and they will get email notifications when those gems are updated.

Get Started

Start using GemNotifier today. The setup process is straightforward:

  • Sign in with Github Oauth
  • Search for your favorite gems and click subscribe. You'll be notified when things change!

SparkTime

You'll be hearing a lot more about SparkTime on our blog in the coming months, so I'll give you the rundown now! SparkTime is a new initiative at Intridea designed to get us working passionately on side projects that we might not get the chance to do otherwise. Although many of us already make time to contribute to open source, work on side projects, or improve existing code bases, we realized that our talent could be better utilized if we got organized. From this, SparkTime was born. Every Intridean signs up for a project they feel passionate about, using SparkBin to keep track of our ideas. We use Presently to talk about our projects and as a means of collaboration among SparkTime teammates. There are a lot of interesting projects going on and we look forward to sharing more of them with you soon! Follow us on Twitter to get updates about our progress.

We're Doing Fun Stuff

We work hard at Intridea - but we love what we do and we have a lot of fun doing it. If you're interested in being a part of our great team check out our openings; we're a growing company of diverse, talented and energetic engineers, designers and entrepreneurs. We offer compelling benefits and a unique culture that values the individual contributions that make Intridea such a great place to work.

Categories
Author

When bundler first came out, I really wanted to like it. It promised a clean way to declare dependencies for your application in a single and definitive place, regardless of what kind of box your app was running on. Unfortunately, bundler has not lived up to the hype, and I've had plenty of headaches from bundler problems. Read on for a list of tips I've pulled together to save you some headache.

Ensure your local bundler is the same version as your server

Different versions of bundler may act differently:

bundle --version  # on your local machine and your server sudo gem install bundler --version="0.9.26" 

Explicitly specify gem versions

Did you know in HTTParty 0.4.5, there is no 'parsed_response' method on a response object? Well, neither did I when it worked fine on my local laptop (0.6.1), but not on the server (0.4.5)

gem "httparty"  # bad times if your system gem is out of date... gem "httparty", "~> 0.6.1"  # better, but... gem "httparty", "0.6.1"     # ...why not just specify the version everyone should use? 

Check that you are actually using gems installed by bundler

Once in a while, bundler will report success on install, but you'll get the wrong gems loaded in your load path. Grep your load path to double check libraries you're having trouble with:

# in script/console >> $:.grep /http/ => ["/Users/jch/.bundle/ruby/1.8/gems/httparty-0.6.1/lib"] 

Gemfile conditionals

bundler allows you to specify groups so only gems you need in one environment are loaded:

# we don't call the group :test because we don't want them auto-required group :test do   gem 'database_cleaner', '~> 0.5.0'   gem 'rspec'   gem 'rspec-rails', '~> 1.3.2', :require => 'spec/rails' end 

All gems you specify in your Gemfile WILL be installed regardless of what RAILS_ENV you're currently on. There's a very deceptively named option called --without that does not work as you would expect:

# weird, but this will install gems in group test bundle install --without=test 

This can turn out to be a disaster if your linux production environment tries to install a OSX specific gem with native extensions that you use for development. An ugly fix in the meantime is to add conditionals that look for an environment variable:

if ['test', 'cucumber'].include?(ENV['RAILS_ENV'])   group :test do     # your gems   end end 

Update your capistrano

Don't forget to bundle when you deploy:

after  "deploy:update_code", "deploy:bundle" namespace :deploy do   desc "Freeze dependencies"   task :bundle, :roles => :app do     run "cd #{release_path} && bundle install --relock --without=test"   end end 

NameErrors and autoloading issues

For some gems, bundler will not autoload properly. If you start getting NameErrors or LoadErrors for a gem, read this issue. The fix is to skip the require in your Gemfile and manually do the require in your environment.rb:

# Gemfile gem 'misbehaving_gem', :require_as => []  # environment.rb Rails::Initializer.run do |config|   # ...   config.gem 'misbehaving_gem'   # ... end 

Nuke .bundle

When all else fails, and you've pulled out what precious little hair you have left:

rm -rf RAILS_ROOT/.bundle      # removes gems for this project rm -rf ~/.bundle               # removes cached gems for your current user rm -rf RAILS_ROOT/Gemfile.lock # lets you do a fresh 'bundle install'  # do a fresh bundle install bundle install 

Other

Bundler is in its infancy, and it continues to get better with each release, so many of these issues might not exist in the near future. In the meantime, I hope this list will save you some time with bundler related headaches. Let me know in the comments if you've encountered other tips for resolving these problems.

Categories
Author

One of my earliest gems was Mash, a useful tool for creating mocking objects as a Hash. One of the most common problems people had with Mash was a simple one: it conflicted with another class of the same name in extlib! To address this problem as well as give the project some room to grow, Mash is now part of a new toolkit called Hashie. Hashie is available now via Gemcutter and the source, as always, is available on GitHub. To install:

gem install hashie

Hello, Hashie

Hashie is, right now, simply the former Mash code along with a new extended Hash called a Dash. A Dash is a “discrete hash” that has pre-defined properties. It can be used as a dead-simple data object when even something like DataMapper is too heavy, but a Struct is too light (Dash gives you the ability to set per-property defaults as well as initialize from an attributes Hash). For example:

class Person < Hashie::Dash   property :name   property :email   property :occupation, :default => 'Rubyist' end  p = Person.new p.name # => nil p.occupation # => 'Rubyist' p.email = 'abc@def.com' p.email # => 'abc@def.com' p['awesome'] # => NoMethodError  p = Person.new(:name => "Awesome Guy") p.name # => "Awesome Guy" p.occupation # => "Rubyist"

The other advantage Hashie has over Mash is that it’s built from the ground up to avoid conflicts. Instead of adding stringify_keys methods to the Hash class, it’s instead added to a Hashie::Hash subclass. You can, however, get Hashie’s few Hash extensions in the Hash class by including the HashExtensions:

Hash.send :include, Hashie::HashExtensions

Hopefully the move will make it easier for everyone to use it in their projects without fear of running into conflicts, and hopefully you’ll also find the Dash useful. Over time the functionality of Hashie may grow to encompass additional simple and useful extensions of Hash. So install Hashie, your friendly neighborhood Hash toolkit, today!

Categories
Author

There are a number of times when I need something like an OpenStruct with a little more power. Often times this is for API-esque calls that don’t merit a full on ActiveResource. I wrote a small class for use with my ruby-github library and wanted to make it a separate gem because I think it’s pretty useful to have around.

Usage

Basically a Mash is a Hash that acts a little more like a full-fledged object when it comes to the keyed values. Using Ruby’s method punctuation idioms, you can easily create pseudo-objects that store information in a clean, easy way. At a basic level this just means writing and reading arbitrary attributes, like so:

author = Mash.new author.name # => nil author.name = "Michael Bleigh" author.name # => "Michael Bleigh" author.email = "michael@intridea.com" author.inspect # => <Mock name="Michael Bleigh" email="michael@intridea.com">

So far that’s pretty much how an OpenStruct behaves. And, like an OpenStruct, you can pass in a hash and it will convert it. Unlike an OpenStruct, however, Mash will recursively descend, converting Hashes into Mashes so you can assign multiple levels from a single source hash. Take this as an example:

hash = { :author => {:name => "Michael Bleigh", :email => "michael@intridea.com"},        :gems => [{:name => "ruby-github", :id => 1}, {:name => "mash", :id => 2}]}  mash = Mash.new(hash) mash.author.name # => "Michael Bleigh" mash.gems.first.name # => "ruby-github"

This can be really useful if you have just parsed out XML or JSON into a hash and just want to dump it into a richer format. It’s just that easy! You can use the ? operator at the end to check for whether or not an attribute has already been assigned:

mash = Mash.new mash.name? # => false mash.name = "Michael Bleigh" mash.name? # => true

A final, and a little more difficult to understand, method modifier is a bang (!) at the end of the method. This essentially forces the Mash to initialize that value as a Mash if it isn’t already initialized (it will return the existing value if one does exist). Using this method, you can set ‘deep’ values without the hassle of going through many lines of code. Example:

mash = Mash.new mash.author!.name = "Michael Bleigh" mash.author.info!.url = "http://www.mbleigh.com/" mash.inspect # => <Mash author=<Mash name="Michael Bleigh" info=<Mash url="http://www.mbleigh.com/">>> mash.author.info.url # => "http://www.mbleigh.com/"

One final useful way to use the Mash library is by extending it! Subclassing Mash can give you some nice easy ways to create simple record-like objects:

class Person < Mash   def full_name     "#{first_name}#{" " if first_name? && last_name?}#{last_name}"   end end  bob = Person.new(:first_name => "Bob", :last_name => "Bobson") bob.full_name # => "Michael Bleigh"

For advanced usage that I’m not quite ready to tackle in a blog post, you can override assignment methods (such as name= and this behavior will be picked up even when the Mash is being initialized by cloning a Hash.

Installation

It’s available as a gem on Rubyforge, so your easiest method will be:

sudo gem install mash

If you prefer to clone the GitHub source directly:

git clone git://github.com/mbleigh/mash.git

This is all very simple but also very powerful. I have a number of projects that will be getting some Mashes now that I’ve written the library, and maybe you’ll find a use for it as well.

Categories
Author
1
Subscribe to Gems