MagLev/maglev — pull request #309 by knub (2013-05-03 18:07:22+00:00)
Title: Stefan/persisting only maglevrecord

##### Problem

When persisting Rails and its modules, you end up persisting almost the whole standard library. This causes a lot of problems.

##### Consequences
--> We do not want any Rails module to be persisted.
--> We still want to use (= include or extend) Rails modules.

**Idea 1**
When calling maglev_persistable you pass a block, which determines (true/false) for each included module whether it should be persisted.
False means, that we do not store persistent superclass pointers to the module´s virtual class.
So in another gem, the module is not included anymore (it is transient).

**Idea 2**
Still we want our included modules in another gem.
Instead of include you can say redo_include, which causes the given module to be reincluded if it is not included already.
```Redo_include``` stores the fact, that this module should be included in the persistent namespace. It does not store the module itself (would be a ```TranscationError``` again), but only the module´s name.

##### Example model showing the combination of both ideas:
```ruby
class BookModel
redo_include ActiveModel::Validations # this cannot be persisted, is reloaded in another gem
include MaglevRecord::Persistence # this shall be persisted
end

# passing an optional block, which answers true for MaglevRecord::Persistence (-->to be persisted) and false for ActiveModel::Validations (--> not to be persisted).
BookModel.maglev_persistable(true) do |mod|
mod == MaglevRecord::Persistence
end
Maglev.commit_transaction
```

The next time, we open a connection to the stone, the model does not have ```ActiveModel::Validations``` included.
But by looking in the persistence namespace we find, that a module named ```"ActiveModel::Validations"``` should be reincluded. We resolve the constant, and can reinclude the module (which must be loaded again before).
This is done by a call to **redo_include_and_extend**:
```ruby
BookModel.included_modules # => [MaglevRecord::Persistence]
BookModel.redo_include_and_extend
BookModel.included_modules # => [MaglevRecord::Persistence, ActiveModel::Validations]
```

##### Advantage
The domain logic and the maglevrecord code can be persisted completely.
The maglevrecord and model files to be loaded only the first time. Afterwards they are committed, and do not lead to be reloaded (quicker bootup time, no need to ship domain logic files). See it in action at https://github.com/knub/maglevrecord/blob/develop/lib/maglev_record.rb#L11-37

Comments and questions welcome.