[MacRuby-devel] ControlTower in MacRuby

Nick Ludlam nick at recoil.org
Wed Jul 21 11:44:47 PDT 2010


On 21 Jul 2010, at 15:31, Alexander von Below wrote:

> Hello,
> 
> I apologize for the repost, but I have not found help anywhere else...
> 
> My goal is to run a ControlTower instance (1) in MacRuby within a Cocoa app, i.e. using -[MacRuby evaluateFileAtPath:]
> 
> First question: Is this possible at all?
> 
> Second question:
> 
> I understand that my control script is the body to:
> 
> app = Rack::Builder.new { ... config ... }.to_app
> 
> but I have not figured out how to make an .rb file that will run a control tower instance. 
> 
> Any help is appreciated!

Hi Alexander,
I've got a MacRuby app happily running very happily with Control Tower. First I cloned the code from github, and built and installed the macgem package. Then I also installed rack with

sudo macgem install rack

in order to get some of Rack's built in server functionality. Then a short script would look like:


require 'rubygems'
require 'control_tower'
require 'rack/utils'

server_options = { :port => 3001, :host => '0.0.0.0', :concurrent => false }

app = Rack::Builder.new do
  map "/" do run Rack::File.new("/Users/nick/Sites/") end
end.to_app

@s = ControlTower::Server.new(app, server_options)
if @s
  puts 'Starting control tower webserver'
  @s.start
else
  puts "ERROR: Couldnt build server"
end

This would run a server on port 3001, and expose the files found in your ~/Sites/ directory as top level files

eg. ~/Sites/index.html becomes http://localhost:3001/index.html

Of course you'd need to replace 'nick' with your user homedir name.


Nick



More information about the MacRuby-devel mailing list