0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
dm-is-indexed overloads the Model[] method, and allows querying Resources using their indexed 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-indexed

Description

dm-is-indexed overloads the Model[] method, and allows querying Resources using their indexed properties.

Examples

require 'dm-is-indexed'

class Atom

  include DataMapper::Resource

  is :indexed

  property :id, Serial

  property :symbol, String, :unique => true

  property :name, String, :unique => true

  property :atomic_weight, Float, :index => true

end

Traditional Array style access is preserved:

Atom[0]
# => #<Atom: @id=1 @symbol="He" @name="Helium" @atomic_weight=4.002602>

Atom[0,1]
# => [#<Atom: @id=1 @symbol="He" @name="Helium" @atomic_weight=4.002602>,
      #<Atom: @id=2 @symbol="Ne" @name="Neon" @atomic_weight=20.1797>]

Query Resources based on their unique indexed properties:

Atom["Kr"]
# => #<Atom: @id=4 @symbol="Kr" @name="Krpton" @atomic_weight=83.798>

Atom["Krpton"]
# => #<Atom: @id=4 @symbol="Kr" @name="Krpton" @atomic_weight=83.798>

Atom[83.798]
# => #<Atom: @id=4 @symbol="Kr" @name="Krpton" @atomic_weight=83.798>

Requirements

Install

$ gem install dm-is-indexed

Copyright

Copyright (c) 2011 Hal Brodigan

See {file:LICENSE.txt} for details.