dkubb / dm-ambition

Ambition inspired API for DataMapper

This URL has Read+Write access

name age message
file .document Mon Dec 14 19:15:35 -0800 2009 Updated to work with Jeweler * Removed files n... [Dan Kubb]
file .gitignore Mon Dec 14 19:15:35 -0800 2009 Updated to work with Jeweler * Removed files n... [Dan Kubb]
file LICENSE Tue Feb 10 01:36:51 -0800 2009 Update Copyright year [Dan Kubb]
file Manifest.txt Sat Feb 07 18:21:36 -0800 2009 Bumped version to 0.10.0 * Compatible with dm-... [Dan Kubb]
file README.rdoc Mon Dec 14 19:15:35 -0800 2009 Updated to work with Jeweler * Removed files n... [Dan Kubb]
file Rakefile Mon Dec 14 19:16:26 -0800 2009 Removed rubyforge release task [Dan Kubb]
file TODO Sat Feb 07 14:58:15 -0800 2009 Initial commit [Dan Kubb]
file dm-ambition.gemspec Mon Dec 14 19:19:45 -0800 2009 Regenerated gemspec for version 0.10.2 [Dan Kubb]
directory lib/ Mon Dec 14 19:15:35 -0800 2009 Updated to work with Jeweler * Removed files n... [Dan Kubb]
directory spec/ Mon Dec 14 19:15:35 -0800 2009 Updated to work with Jeweler * Removed files n... [Dan Kubb]
directory tasks/ Mon Dec 14 19:15:35 -0800 2009 Updated to work with Jeweler * Removed files n... [Dan Kubb]
README.rdoc

dm-ambition

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

Installation

With Rubygems:

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

With git and local working copy:

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

Examples

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

License

Copyright © 2009 Dan Kubb

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.