Extract ORM specifics

rework of PR #454

a good case <https://github.com/advancedcontrol/doorkeeper-couchbase>
`e.instance_of?(NameError)` also works
@tute what do you think?