Skip to content

jqr/negative_named_scope

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Negative Named Scope

Tired of writing both the positive and negative versions of a named_scope? Negative Named Scope will automatically generate the NOT’d version of your named scope.

Warning: Ruby may treat !nil == true but SQL treats NOT NULL as NULL, see: en.wikipedia.org/wiki/Null_(SQL)

Example

named_scope :approved, :conditions => { :approved => true }
# => named_scope :not_approved, :conditions => "NOT (approved = 't')"

named_scope :published, :conditions => { :published => true }, :negative => :unpublished
# => named_scope :unpublished, :conditions => "NOT (published = 't')"

named_scope :created_after, lambda { |value| { :conditions => ['created_after', value] } }
# => named_scope :not_created_after, lambda { |value| :conditions => ["NOT (created_after > = ?)", value] }

You can suppress the automatic negative named_scope generation:

named_scope :great, :conditions => { :great => true }, :negative => false

Install

As a Rails plugin:

./script/plugin install git://github.com/jqr/negative_named_scope.git

Prefer gems?

gem sources -a http://gems.github.com
gem install jqr-negative_named_scope
Homepage

github.com/jqr/negative_named_scope

License

Copyright © 2008 Elijah Miller <elijah.miller@gmail.com>, released under the MIT license

About

A Rails plugin to automatically generate the NOT'd version of your named scope.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages