Trying out Hobo (with some hiccups)

So I tried Hobo for the first time today. I really like it. It will definitely help when I am creating things that need value added quickly. I look forward to using it more.

The documentation is a work in progress, but is already good enough to learn Hobo. With the release of Hobo 0.7.2 and Rails 2.0.2, some of the documentation is lagging, but if you are already versed in Ruby / Rails, you will figure it out quickly.

I wanted to fill everyone in on an issue I ran into. When I tried to create the Hobo application, it started to fail when creating the user model, which stopped the process, so many other things did not occur. It turns out that the default database on Rails 2.0.2 is SQLLite. I did not have the adapter installed which was the root of the problems. So you could install the adapter and fix the issues.

I opted to modify the hobo command file so it would accept the -d,—database switches that the rails command accepts. This will allow you to set you default database to whatever you like. Thus, the hobo command works again without installing SQLLite adapter.

Simply replace all the code in your hobo file with this code (if you are on Hobo 0.7.2). I found my file at: C:\ruby\lib\ruby\gems\1.8\gems\hobo-0.7.2\bin\hobo.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env ruby

require 'fileutils'
Signal.trap("INT") { puts; exit }

hobo_src = File.join(File.dirname(__FILE__), "../hobo_files/plugin")

USAGE = "USAGE: hobo [ --user-model <model-name-or-false> ] [ --svn ] [--db] [-d or --database <database type>] [--hobo-src <path to hobo src>] <app-path>"

HOBO_REPO = "svn://hobocentral.net/hobo/trunk/hobo"


### Nasty stuff needed for Windows :-( ###
require 'rbconfig'

if Config::CONFIG["arch"] =~ /win32/
  require "win32/registry"
  def system(command)
    win = Win32API.new("crtdll", "system", ['P'], 'L').Call(command)
  end
end
### end nasty stuff ###


def command(*s)
  ok = system(s.join(' '))
  exit(1) unless ok
end

if ARGV.length == 0 || ARGV.include?("--help")
  puts USAGE
  exit 1
end

app_path = ARGV.pop

user_model = "user"
hobo_svn = create_db = false

until ARGV.empty?
  case ARGV.shift
  when "--user-model"
    arg = ARGV.shift
    user_model = arg == "false" ? nil : arg
  when "--svn"
    hobo_svn = true
  when "-d", "--database"
   arg = ARGV.shift
    change_db = arg == nil ? false : true
   default_db = arg unless !change_db
  when "--db"
    create_db = true
  when "--hobo-src"
    hobo_src = "../" + ARGV.shift
  else
    puts USAGE
    exit 1
  end
end

puts "\nGenerating Rails App...\n"
if change_db == true
   puts "\n***Default database type is: #{default_db}...\n"
   system("rails -d #{default_db} #{app_path}")
else
   system("rails #{app_path}")
end


Dir.chdir(app_path) do
  gen = "ruby #{File.join('script', 'generate')}"
  plugin = "ruby #{File.join('script', 'plugin')}"

  FileUtils.touch("public/stylesheets/application.css")

  puts "\nInstalling classic_pagination\n"
  command(plugin, "install svn://errtheblog.com/svn/plugins/classic_pagination")
 
  if hobo_svn
    puts "\nInstalling Hobo plugin via svn checkout...\n"
    command("svn co #{HOBO_REPO} vendor/plugins/hobo")
  else
    puts "\nInstalling Hobo plugin...\n"
    FileUtils.cp_r hobo_src, "vendor/plugins/hobo"
  end

  puts "\nInitialising Hobo...\n" 
  command(gen, "hobo --add-routes")

  puts "\nInstalling Hobo Rapid and default theme...\n"
  command("#{gen} hobo_rapid --import-tags")

  if user_model
    puts "\nCreating #{user_model} model and controller...\n"
    command("#{gen} hobo_user_model #{user_model}")
    command("#{gen} hobo_user_controller #{user_model}")
  end
 
  puts "\nCreating standard pages...\n"
  command("#{gen} hobo_front_controller front --delete-index --add-routes")
 
  if create_db
    puts "\nCreating databases"
    command("rake db:create:all")
  end
end 

If you need to change yours manually, I just added to the usage string, one case to the case statement to handle the new switches and an if statement to testing if a different default database was specified.

Enjoy!

1 Response to “Trying out Hobo (with some hiccups)”

  1. Chris Says:

    Thanks for this fix! So easy, yet so maddening when it wasn’t there.

Leave a Reply