Project

topmodel

0.0
No commit activity in last 3 years
No release in over 3 years
TopModel is a Rails 4 compatible In-Memory Object-Relational mapper using ActiveModel
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 3.0.0
 Project Readme

##TopModel TopModel is a Rails 4 compatible in-memory database with O/R mapping based on ActiveModel. It is originally developed by Alex Maccaw (maccman) and named "supermodel". Unfortunately the development of supermodel has stopped and actually it is incompatible with Rails 4. So TopModel fixes this and is updated to be compatible with Rails 4.

Primarily developed for Bowline applications. http://github.com/maccman/bowline

##Supports:

  • Serialisation
  • Validations
  • Callbacks
  • Dirty (Changes)
  • Ruby Marshalling to disk
  • Redis

##Examples:

require "topmodel"
class Test < TopModel::Base
end

t = Test.new
t.name = "foo"
t.save #=> true

Test.all
Test.first
Test.last
Test.find_by_name('foo)

You can use a random ID rather than the object ID:

class Test < TopModel::Base
  include TopModel::RandomID
end

t = Test.create(:name => "test")
t.id #=> "7ee935377bb4aecc54ad4f9126"

You can marshal objects to disk on startup/shutdown

class Test < TopModel::Base
  include TopModel::Marshal::Model
end

TopModel::Marshal.path = "dump.db"
TopModel::Marshal.load

at_exit {
  TopModel::Marshal.dump
}

You can use Redis, you need the Redis gem installed:

require "redis"
class Test < TopModel::Base
  include TopModel::Redis::Model
  attributes :name
  indexes :name
end

Test.find_or_create_by_name("foo")

;-)