Skip to content

Latest commit

 

History

History
84 lines (60 loc) · 1.73 KB

File metadata and controls

84 lines (60 loc) · 1.73 KB

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.