Ruby Object Mapper is an implementation of the Data Mapper pattern in Ruby language. It consists of multiple loosely coupled pieces and uses a powerful relational algebra library called axiom.
Currently the setup is a bit verbose. Automatization will come in the future once the API becomes stable.
gem install rom axiom-memory-adapter
require 'rom'
require 'axiom-memory-adapter'
class User
attr_reader :id, :name
def initialize(attributes)
@id, @name = attributes.values_at(:id, :name)
end
end
env = ROM::Environment.setup(memory: 'memory://test') do
schema do
base_relation :users do
repository :memory
attribute :id, Integer
attribute :name, String
key :id
end
end
mapping do
relation(:users) do
map :id, :name
model User
end
end
end
env.session do |session|
user = session[:users].new(id: 1, name: 'Jane')
session[:users].save(user)
session.flush
end
jane = env[:users].restrict(name: 'Jane').one
- (we are trying it out as a potential IRC channel replacement)
- #rom-rb channel on freenode
- Ruby Object Mapper mailing list
See LICENSE
file.