Defined Hash

A hash with defined keys

This is somewhat similar to the ‘Dash’ provided by Hashie, but it has hashidator validations baked in, and in addition, supports the idea of optional columns. It also allows for sensible merging of such values. Property definition is based on the hashidator validation syntax.

class Person < DefinedHash
  property :name,       String    # name is a string
  property :emails,     [String]  # Array of strings for email addresses
  property :addresses,  [Address] # Supports nesting of defined hashes
end

It was written with mongodb in mind, as all the existing mappers were massively complex for what I wanted.

Who should use DefinedHash?

  • People who want a simple hash schema with validations

  • People who want something lightweight and fast

Who shouldn’t use DefinedHash?

  • People who want error messages

  • People with a very complex schema

  • People who want an ORM/ODM.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Jonathan Stott. See LICENSE for details.