Home

Awesome

Jǫrmungandr

Jǫrmungandr is a simple ORM, as in Object Redis Mapper. It enables very flexible creation of Ruby objects backed by a Redis database. It is kind of similar to Struct, but more dynamic. Model classes can be created like so:

Thing = Jormungandr.new

thing = Thing.new

Thereafter, objects essentially are their own little key-value stores, wrapped with some method_missing magic:

thing.foo = "bar"
thing.foo
  => "bar"

Similar magic is used for one-to-many mappings: If a method is called that is a pluralization of the name of a Model subclass (e.g. Thing), it returns all instances of that subclass that reference the object on which the method was called.

p = Person.new
thing1.person = p
thing2.person = p
p.things
  => [thing1, thing2]

Features

Example of usage

$ irb -r ./jormungandr
> Person = Jormungandr.new
=> nil
> p = Person.new
=> #<Person:0x101115740 @id=0> 
> p.name = "Martin"
=> "Martin"
> p.age = 28
=> 28 
> exit
$ irb -r ./jormungandr
> Person.all
=> [#<Person:0x101125dc0 @id=0>] 
> Person.all.first.name
=> "Martin"
> Person.all.first.age
=> 28

Note that the Person class is created only once. In the second irb session, Jǫrmungandr creates it when it finds a reference to it in the database.