Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Ambition inspired API for DataMapper

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 tasks
Octocat-spinner-32 .document
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rvmrc
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 TODO
Octocat-spinner-32 dm-ambition.gemspec
README.md

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.

Something went wrong with that request. Please try again.