Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Ruby
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.document
.gitignore
.rspec
.yardopts
ChangeLog.md
Gemfile
LICENSE.txt
README.md
Rakefile
dm-is-indexed.gemspec
gemspec.yml

README.md

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.

Something went wrong with that request. Please try again.