Repository is archived
No commit activity in last 3 years
No release in over 3 years
DataMapper plugin providing an Ambition-like API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

~> 3.0.3
~> 1.2.2
 Project Readme

dm-ambition

DataMapper::Ambition is a plugin that provides an Ambition-like API for accessing DataMapper models.

Build Status

Installation

With Rubygems:

$ gem install dm-ambition
$ irb -rubygems
>> require 'dm-ambition'
=> true

With git and local working copy:

$ git clone git://github.com/dkubb/dm-ambition.git
$ cd dm-ambition
$ rake install
$ irb -rubygems
>> require 'dm-ambition'
=> true

Testing

The simplest way to test is with Bundler since it handles all dependencies:

$ rake local_gemfile
$ BUNDLE_GEMFILE="Gemfile.local" sh -c "bundle && bundle exec rake spec"

Examples

The standard Enumerable methods #select, #detect, #reject, #find_all, and #find may be used with dm-ambition. These methods may be called on Model and Collection objects.

# with == operator
model_or_collection.select { |u| u.name == 'Dan Kubb' }

# with =~ operator
model_or_collection.select { |u| u.name =~ /Dan Kubb/ }

# with > operator
model_or_collection.select { |u| u.id > 1 }

# with >= operator
model_or_collection.select { |u| u.id >= 1 }

# with < operator
model_or_collection.select { |u| u.id < 1 }

# with <= operator
model_or_collection.select { |u| u.id <= 1 }

# with < operator
model_or_collection.select { |u| u.id < 1 }

# with receiver.attribute.nil?
model_or_collection.select { |u| u.id.nil? }

# with nil bind value
model_or_collection.select { |u| u.id == nil }

# with true bind value
model_or_collection.select { |u| u.admin == true }

# with false bind value
model_or_collection.select { |u| u.admin == false }

# with AND conditions
model_or_collection.select { |u| u.id == 1 && u.name == 'Dan Kubb' }

# with negated conditions
model_or_collection.select { |u| !(u.id == 1) }

# with double-negated conditions
model_or_collection.select { |u| !(!(u.id == 1)) }

# with matching from receiver
model_or_collection.select { |u| u == user }

# with matching to receiver
model_or_collection.select { |u| user == u }

# using send on receiver
model_or_collection.select { |u| u.send(:name) == 'Dan Kubb' }

# with Array#include?
model_or_collection.select { |u| user_ids.include?(u.id) }

# with Range#include?
model_or_collection.select { |u| (1..10).include?(u.id) }

# with Hash#key?
model_or_collection.select { |u| { 1 => 'Dan Kubb' }.key?(u.id) }

# with Hash#value?
model_or_collection.select { |u| { 'Dan Kubb' => 1 }.value?(u.id) }

# with receiver and Array#include?
model_or_collection.select { |u| users.include?(u) }

# with receiver and Hash#key?
model_or_collection.select { |u| { user => 'Dan Kubb' }.key?(u) }

# with receiver and Hash#value?
model_or_collection.select { |u| { 'Dan Kubb' => user }.value?(u) }

Copyright

Copyright © 2009-2011 Dan Kubb. See LICENSE for details.