Skip to content

holgerw/rom

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ruby Object Mapper

Ruby Object Mapper is an implementation of the Data Mapper pattern in Ruby language. It consists of multiple lously coupled pieces and uses a powerful relational algebra library called axiom.

This is a meta-project grouping pieces of ROM's default stack:

Getting started

gem install rom axiom-memory-adapter

1. Set up environment and define schema

  require 'rom'
  require 'axiom-memory-adapter'

  env = ROM::Environment.setup(memory: 'memory://test')

  env.schema do
    base_relation :users do
      repository :memory

      attribute :id,   Integer
      attribute :name, String

      key :id
    end
  end

2. Set up mapping

  class User
    attr_reader :id, :name

    def initialize(attributes)
      @id, @name = attributes.values_at(:id, :name)
    end
  end

  env.mapping do
    users do
      map :id, :name
      model User
    end
  end

3. Work with Plain Old Ruby Objects

  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

Community

Authors

Licence

See LICENSE file.