Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Basic identity map for Ohm.

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.md

Ohm::IdentityMap

Provides a basic identity map for Ohm.

Usage

require "ohm/identity_map"

# By default, no identity map is used.

Post[1].object_id == Post[1].object_id
# => false

# Enable the identity map for the duration of a block.

Ohm::Model.identity_map do
  Post[1].object_id == Post[1].object_id
end
# => true

Web

It's easy to create a Rack middleware to enable the identity map for the duration of the request/response cycle. (Such middleware may be included in this library in the future, once we test this behavior in production.)

class OhmIdentityMapMiddleware
  def initialize(app)
    @app = app
  end

  def call(env)
    Ohm::Model.identity_map { @app.call(env) }
  end
end

# config.ru or any Rack::Builder
use OhmIdentityMapMiddleware

Known issues

Currently not handling updates and deletes.

License

See UNLICENSE. With love, from Educabilia.

Something went wrong with that request. Please try again.