Blog ยป Using Hobo Edge on Rails 3
Posted on 06 Mar 2011 01:18
!!!Hobo is not yet compatible with rails 3.2 so be sure to have "gem rails, "=3.1" in your Gemrfile.
I describe here installing Hobo Edge on Rails 3 using rvm. And command prompt shows your current gemset. To keep my existing applicaitons happy, I will also define a gemset for Rails 2 Hobo applications.
rvm
Followed the instructions on http://rvm.beginrescueend.com/ to install rvm
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
Then edited ~/.rvmrc so that on exiting a project directory the environment returns to system defaults.
export rvm_pretty_print_flag=1 export rvm_project_rvmrc_default=1
Intalled ruby with rvm so that I can create project gemsets under it. And of course we need bundler
rvm install 1.8.7 rvm --default use 1.8.7
RVM uses project and/or ruby specific gems:
rvm gemdir
You can hunt code in gems using rvm gemdir. For example find definition of task in rake.
grep -R 'def task' `rvm gemdir` | grep rake
Then proceeded to install gems that I need globally for development
rvm use @global gem install bundler gem install wirble #for irb gem install utility_belt #for_irb gem install jeweler gem install yard
Rails 2
We need to use different gem sets for rails2 and rails3. Having them only in project gemsets are not enough. Then you cannot create projects.
Note that you can always switch to the global gemset: 'rvm use @global' .
Let's create rails2 gemset:
#!/bin/bash source "$HOME/.rvm/scripts/rvm" rvm 1.8.7 rvm @rails2hobo --create echo Gemset: `rvm gemset name` gem install rails --version 2.3.11 gem install sqlite3-ruby --version 1.3.3 gem install will_paginate --version 2.3.11 gem install hobo --version 1.0.2 gem install haml --version 3.0.12 gem install dalli --version 1.0.2 gem install rspec --version 1.3.1 gem install rspec-rails --version 1.3.3 gem install steak --version 0.3.8 gem install capybara --version 0.4.1.2 gem install shoulda --version 2.11.3 gem install mocha --version 0.9.12 gem install factory_girl --version 1.3.3 # Other usual suspects for testing # gem install delorean --version 1.0.0 #Change Time.now in tests # gem install database_cleaner --version 0.6.4 #Remove data # gem install spork --version 0.8.4 #Solid test server # Fixing the gem versions because future versions might be Rails 2 incompatible
Rails 3
Lets create and switch to rails3 gemset and install Rails3 and Hobo
We'll instal Hobo from github. So that we can easily create projects.
#!/bin/bash source "$HOME/.rvm/scripts/rvm" rvm @rails3hobo --create echo Gemset: `rvm gemset name` gem install rails gem install sqlite3-ruby gem install hobo --pre gem install haml gem install dalli gem install rspec-rails gem install steak gem install capybara gem install shoulda gem install mocha gem install factory_girl gem install delorean #Change Time.now in tests gem install database_cleaner #Remove data gem install spork --prerelease #Solid test server
Hobo Rails 3 Reference
Refer to Using Hobo 1.3 to start using Hobo.
Rapid Rails 3 with Hobo.pdf is the Tutorial maintained at LightHouse.
Summary
rvm use system #Use the operating system installation rvm use 1.8.7 #Switching to global gems. Use global gems and use Ruby 1.8.7 rvm use @rails2 #use rails2 with current Ruby rvm use @rails3 #use rails3 with current Ruby rvm use 1.8.7@rails3 #use rails3 with Ruby 1.8.7 rvm gemdir
Dynamic Bash Shell Prompt
Shell prompt can show your current git branch and rvm gemset. It saves your fingers. Use or adapt the prompt ~/.bashrc file below. I kept it short so that you can easily extend your existing .bashrc.
if [[ -n "$PS1" ]] ; then #Remember rmv does not like return # OTHER THINGS THAT YOU WANT TO HAVE function parse_git_branch { git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' } function rvm_gem_set { rvm gemset name | grep -v \/ } function proml { PROMPT_COMMAND='PS1="[$(date +%H:%M)]\ [\u@\h: **/\W] $(rvm_gem_set) $(parse_git_branch) $ "' PS2='> ' PS4='+ ' } proml [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # This loads rvm fi
Bundle
Using gemsets are fine for quickly getting up and running. However, each project should have its gem bundle.
Bundle Rails 2
This is a typical Gemfile for Rails 2 projects:
source "http://rubygems.org/" gem "rails", "=2.3.11" gem "hobo", "=1.0.2" gem "haml", "=3.0.12" gem "will_paginate", ">=2.3.11" gem "dalli" gem "builder" gem "tzinfo" gem "system_timer" gem "sqlite3", :groups => [:test, :development] group :test do gem "factory_girl" gem "shoulda" gem "mocha" gem "rspec", "= 1.3.1", :require => nil gem "rspec-rails", "= 1.3.3", :require => nil gem "steak" gem "capybara" gem "delorean" #Change Time.now in tests gem "database_cleaner" #Remove data gem "spork", "~> 0.9.0.rc4" end gem 'ruby-debug', :groups => [:test, :development]
Adding Bundle to Rails 2
You need to change
- config/boot.rb
- config/environment.rb
- config/preinitializer.rb
config/boot.rb
# ... run method modified and extend_environment method added class Boot def run load_initializer Rails::Initializer.run(:set_load_path) extend_environment end def extend_environment Rails::Initializer.class_eval do old_load = instance_method(:load_gems) define_method(:load_gems) do old_load.bind(self).call Bundler.require :default, RAILS_ENV end end end end # ...
config/environment.rb
#... Rails::Initializer.run do |config| #... require "active_support" #This line is added #...
config/preinitializer.rb
class Pathname def empty? to_s.empty? end end # Fallback on doing the resolve at runtime. require "rubygems" require "bundler" Bundler.setup
Bundle Rails 3
This is a typical Gemfile for Rails 3 projects:
source "http://rubygems.org/" gem "rails" gem "will_paginate" gem "hobo", "~> 1.3.0.pre29" gem "haml" gem "dalli" gem "builder" gem "tzinfo" gem "system_timer" gem "pony" gem "sinatra" gem "vegas" gem "yajl-ruby" gem "redis-namespace" gem "redis" gem "sqlite3", :groups => [:test, :development] group :test do gem "factory_girl" gem "shoulda" gem "mocha" gem "rspec", :require => nil gem "rspec-rails", :require => nil gem "steak" gem "capybara" end gem 'ruby-debug', :groups => [:test, :development]
If you like this page, please spread the word:
You can contact me if you have questions or corrections.