Repository is archived
No commit activity in last 3 years
No release in over 3 years
A DataMapper plugin which adds checksum properties to a Model, referencing other properties.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.0.0
~> 0.6.0

Runtime

~> 1.0
 Project Readme

dm-is-checksumed

Description

A DataMapper plugin which adds checksum properties to a Model, referencing other properties.

Features

  • Uses sha256
  • Allows unique and non-unique checksums.
  • Automatically substitutes in checksums in queries to avoid expensive queries.
  • Works with first_or_create and first_or_new.

Examples

require 'dm-is-checksumed'

class Url

  include DataMapper::Resource

  is :checksumed

  property :id, Serial

  # The property to be checksumed
  property :url, Text

  # Defines the `url_checksum` property, referencing `url`
  checksum :url

end

# Checksums are automatically calculated
url = Url.create(:url => 'http://example.com/extremely/long/url....')
url.url_checksum
# => "b74d7288b86817dea55bd044d3cedc013e83518b461cd6f202be85e33d95715b"

# Checksums are automatically substituted into queries
url = Url.first(:url => 'http://example.com/same/huge/url')
# ~ (0.000116) SELECT "id", "url_checksum" FROM "urls" WHERE "url_checksum" = 'b74d7288b86817dea55bd044d3cedc013e83518b461cd6f202be85e33d95715b' ORDER BY "id" LIMIT 1

# Works with first_or_create and first_or_new
url = Url.first_or_create(:url => 'http://example.com/same/huge/url')
url.url_checksum
# => "b74d7288b86817dea55bd044d3cedc013e83518b461cd6f202be85e33d95715b"

url = Url.first_or_create(:url => 'http://example.com/different/url')
url.url_checksum
# => "09a27797a33153b005871b61675a920fa6bedbb034a3b283bbe5803a1d31ac42"

Requirements

Install

$ gem install dm-is-checksumed

Copyright

Copyright (c) 2011 Hal Brodigan

See {file:LICENSE.txt} for details.