Advanced Rails - Building Industrial-Strength Web Apps in Record Time

(Tuis.) #1

276 | Chapter 9: Incorporating and Extending Rails


This approach leads to very readable code, but it has a couple of drawbacks:



  • All models must be loaded before Og is started, because Og only traverses
    ObjectSpace when it is first loaded.

  • Og’sattr_accessormethod will mark a class as an Og model. However, if the
    attr_accessormethod is not used first thing in a class declaration, the Og meth-
    ods will not be pulled in. Consider this example:
    class Person
    is Og::Model
    has_many :friends, Friend
    end
    Theismethod is a Ruby Facets alias forincludethat more closely reflects the
    semantics of multiple inheritance. Without this declaration or anattr_accessor,
    thehas_many class method would not exist.

  • The process of finding Og models relies onObjectSpace.ObjectSpaceimplemen-
    tation greatly complicates Ruby interpreter implementation; on platforms with
    managed garbage collection such as the .NET CLR or Java, it takes some spe-
    cial—and comparatively slow—implementation techniques. Because of this, it is
    possible that some of the Ruby 1.9 virtual machines may have limited or no sup-
    port forObjectSpace.


We will now see a highly experimental method of using Og with Rails. This method
works around most of the incompatibilities between Nitro and Rails.


Installing Og from source.Unfortunately, the current stable gem version of Og (0.41.0)
does not work with Rails. We will download the latest version of the code with
Darcs and build a gem ourselves.


Darcs is a distributed version control system written in Haskell. It is
available fromhttp://darcs.net/. If you have a working installation of GHC
(the Glasgow Haskell Compiler), you can install Darcs from source. Oth-
erwise, there are Darcs binaries available for many platforms.

First, we get the latest Nitro code using Darcs:


$ darcs get --partial http://repo.nitroproject.org nitroproject
$ cd nitroproject

Next, we find out what version of Ruby Facets this version of Nitro requires and
install it. The dependency is contained within the gem specification for Glue:*


$ grep facets glue/glue.gemspec
s.add_dependency("facets", "= 1.8.54")
$ sudo gem install facets --version =1.8.54


  • Glue is Nitro’s library that ties all of the components together, similar to ActiveSupport and RailTies in Rails.

Free download pdf