Soar with Merb-Core and Merb-More (0.9) 5

Posted by Justin Reagor Sat, 09 Feb 2008 06:31:00 GMT

I haven’t been around in awhile, frankly because I’ve had my own things to attend to… but I’ve felt somewhat ashamed that I’ve left my kind Kinetic audience a float. So here is another “Up and Running” treat. Cloning Merb-core and -more, from Git[hub] to dummy project.

BTW, it should be any day now for the official 0.9 release. Rumors have it that Ezra will be releasing it at ActsAsConference.

Preperation

Your going to want to remove any old gems in the following list, as you will be installing trunk versions in this tutorial.

merb (< 0.9)
merb_datamapper (< 0.9)
merb_helpers (< 0.9)
datamapper (< 0.3.0)

You can go ahead and gem install the following. I’ve listed the version numbers I use currently.

sqlite3-ruby (1.2.1)
data_objects (0.2.0)
do_sqlite3 (0.2.3)
do_mysql(0.2.2)
rack (0.2.0)

Along with the regular Merb dependencies listed in the API.

# gem install mongrel json json_pure erubis mime-types rspec hpricot mocha rubigen haml markaby mailfactory Ruby2Ruby -y

Thats a lotta gems right? Well, taking a closer look you should have most of these already… and if you don’t you should.

Installing Git

You installed it already, otherwise… EPIC FAIL!

You DO have a Github account

If you have a Github account, you’ll most likely want to fork merb-core and merb-more so you have your own fork’s to mess about with. If you find anything interesting you can always submit a bug/patch and help the wonderful Merb team out! Or start building some new framework forked from Merb. Either way…

To do this, login to Github and…

http://github.com/wycats/merb-core/fork
http://github.com/wycats/merb-more/fork
http://github.com/wycats/merb-plugins/fork

You’ll then want to clone these like the next section…

You DON’T have a Github account

If you don’t have an account yet for Github you’ll still need Git installed like I noted above. From within a fresh directory in Terminal run the following commands.

# git clone git://github.com/wycats/merb-core.git
# git clone git://github.com/wycats/merb-more.git
# git clone git://github.com/wycats/merb-plugins.git

Installing these Git forks/clones

Simply enter the directories “merb-core” and “merb-more” and run…

# sudo rake install

You’ll also want to do this under “merb-plugins/merb_datamapper” and “merb-plugins/merb_helpers”. Including any others in “merb-plugins” you would like installed.

Installing Datamapper Trunk

Currently, Datamapper is still under SVN. I’m positive this will change in the near future. But for now…

# svn co http://datamapper.rubyforge.org/svn/trunk/ data_mapper

Then simply go into the data_mapper/ directory created and do…

# sudo rake install

Merb-gen is your Friend?

I’ve just recently discovered that they’ve changed, yet again, the default way of creating a new Merb project. I guess because “merb -g” or “merb” was getting annoying, so “merb-gen [projectname]” is some how much simpler. You also use this to generate models/controllers/resources/etc… :/

I’m going to take another guess and say this is somehow based on the project directory no longer needing to conform to a certain structure like Rails. I’ve heard this, but I haven’t tested it out for fact… so let me know your experiences.

Either way…

# merb-gen lovely-app

Going into Toshi Station to pick up some power converters

This is where it starts to get exciting. The fruit of our labors dance in unison to form a euphoric aura called “0.9”... not so fast though.

1. If your not already, make sure your in the “lovely-app/” project directory.

2. Open up “config/init.rb” and uncomment…

use_orm :datamapper

Rspec should be your testing framework by default.

3. Back in your shell, run…

# rake --tasks

4. This should auto-generate “config/database.sample.yml

5. Overwrite the entire thing with the following, and save as “config/database.yml”...

---
:development: &build
  :adapter: sqlite3
  :database: db/dev.db

:test:
  <<: *build
  :database: db/test.db

:production:
  :adapter: mysql
  :database: lovely_app
  :username: root
  :password: ""

6. Your going to now want to create those sqlite databases. If not both just db/dev.db.

# mkdir db/
# sqlite3 db/dev.db
SQLite version 3.5.1
Enter ".help" for instructions
sqlite> .databases
seq  name             file                                                      
---  ---------------  ----------------------------------------------------------
0    main             /Users/bionicebonics/lovely-app/db/dev.db                     
sqlite> .quit

You should be able to run a successful “rake—tasks” if you did everything correctly. You may also want to test and see if you can run the daemon, and pull up a browser window. Run “merb” by itself from Merb.root or project root directory.

In short, just start hacking! Reference the API for help, not me.

The Sugar

You should now have a base process for exploring Merb 0.9 development.

The Salt

If for some weird reason your getting errors running “merb”, make sure you removed any old versions of Merb <= 0.5.x.

Also try uninstalling merb-core and reinstalling it from a new Git clone of the main repo. I had to do this for some odd reason whilst running through this tutorial.

Shameless Kinetic/PhillyOnRails

Colin will be giving a talk on Merb at our local PhillyOnRails Users Group, so stay tuned for info on that.

Update

Gotta love Merb integrating Rack/WSGI!

Following a few discussions on the Thin webserver mailing list, I just tried Merb on Thin… this is working out excellent! I’ve also heard that Ezra just got 2200 req/sec using Thin.

If you would like to explore the possibilities of this incredibly fast setup, simply do…

# sudo gem install thin
# cd lovely-app
# merb -a thin

This will load Merb on Thin. If you don’t know about Thin, I’m not going to sit here and explain it. I’m just not like that. You’ll have to FOFY, find-out-for-yourself.

Bad do_mysql-0.2.2 Gem 4

Posted by Justin Reagor Fri, 07 Dec 2007 04:04:00 GMT

If your getting this error whilst attempting to load up DataMapper in Merb (the rake dm:install:mysql portion, or just gem install do_mysql). Here’s how I fixed it…

Started merb_init.rb ...
Loading dependencies...
dyld: NSLinkModule() error
dyld: Library not loaded: /opt/local/lib/mysql5/mysql/libmysqlclient_r.15.dylib
  Referenced from: /usr/local/lib/ruby/gems/1.8/gems/do_mysql-0.2.2/lib/mysql_c.bundle
  Reason: image not found
Trace/BPT trap

Try this…

# sudo -s
# cd /usr/local/lib/ruby/gems/1.8/gems/do_mysql-0.2.2/ext
# make clean
# vim mysql_c.i
[change any bad paths to correct mysql locations in your OS]
# make all
# rm ../lib/mysql_c.bundle
# cp mysql_c.bundle ../lib

DataMapper with MySQL should now work in Merb! Happy hacking once more…

Review: Ruby Performance @ Ruby East

Posted by Justin Reagor Fri, 28 Sep 2007 16:47:00 GMT

Ezra Zygmuntowicz, creator of Merb, gave a eye-opening talk about Ruby performance and why the stigma that “Ruby is slow” led him to prove everyone wrong in creating Merb.

Quick overview (pros):

  • Benchmarking was discussed, using Ruby Benchmark library and the Ruby-Profile gem/lib. I liked how he has a profile method setup in Merb (and can be ported out to any app) to do quick profiling of blocks of code. As well as the significance of profiling/benchmarking while you develop.
  • The idea of “Less meta-programming tricks” and keeping things simple.
  • Benchmarking of options hash as arguments for methods and Symbol.to_proc, amongst others Ezra demonstrated.

Above all, what stuck with me the most was his explanation of why he created Merb, for speed and less framework code. Ezra proclaimed that Rails has been great at extending new ideas into the development community. As well as pushing Ruby into the mainstream.

As far as Merb goes I’ve learned that its great for file uploading and gateway stream buffering. Example: Merb can initiate an authenticated stream with S3, then push the data through Merb to the end client.

Merb is also has a feature called PartControllers. PartControllers are apparently smaller Rails-ish controller classes that do not handle params, sessions or requests and instead provide actions for smaller widgets or controller-in-controller. Example: You would like to have a small RSS Feed reader (PartController) within a view initiated from your StoreController, etc…

To sum it all up, Merb allows you to implement Ruby web applications, generally like Rails, but without being forced idioms and conventions. Not just that, but Merb is completely Rspec’d and provides built-in profiling!!!

BLURP