everywhere 0 rspec ruby Rubygems

Hash condition syntax for AR query everywhere!

= Everywhere

Hash condition syntax for AR query everywhere!

== Features

=== where + not

”+Everywhere+” enables you to construct where + not query such as below using AR Hash query syntax.

SELECT “users”.* FROM “users” WHERE (“users”.“name” != ‘foo’) SELECT “users”.* FROM “users” WHERE (“users”.“created_at” IS NOT NULL) SELECT “users”.* FROM “users” WHERE (“users”.“status” NOT IN (‘inactive’, ‘deleted’))

=== where + like

Same for where + like.

SELECT “users”.* FROM “users” WHERE (“users”.“name” LIKE ‘Akira%’)

=== where + not like

And where + “not like” as well.

SELECT “users”.* FROM “users” WHERE (“users”.“name” NOT LIKE ‘Matz%’)

== Syntaxes

”+Everywhere+” supports 5 syntaxes. Note that you can use only one syntax at a time, and others will be disabled. The +chain+ syntax will be enabled by default.

  • chain +Model.where+ with no args can be chained with +not+, +like+, and +not_like+ methods. This syntax was proposed by Jeremy Kemper: https://github.com/rails/rails/pull/5950#issuecomment-5591330

    User.where.not(:name => ‘foo’) => SELECT “users”.* FROM “users” WHERE (“users”.“name” != ‘foo’)

  • hash_value Push the value into a Hash indexed by +:not+. Similar to MongoDB. http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24ne

    User.where(:name => {:not => ‘foo’}) => SELECT “users”.* FROM “users” WHERE (“users”.“name” != ‘foo’)

  • hash_key Put the whole key + value Hash into another Hash indexed by +:not+.

    User.where(:not => {:name => ‘foo’}) => SELECT “users”.* FROM “users” WHERE (“users”.“name” != ‘foo’)

  • symbol Put +:not+ as the first parameter of +where+ method.

    User.where(:not, :name => ‘foo’) => SELECT “users”.* FROM “users” WHERE (“users”.“name” != ‘foo’)

  • method Use the special method named +where_not+.

    User.where_not(:name => ‘foo’) => SELECT “users”.* FROM “users” WHERE (“users”.“name” != ‘foo’)

See specs for more details.

== Supported versions

ActiveRecord 3.0.x, 3.1.x, 3.2.x, and 4.0 (edge)

== Usage

Bundle ‘everywhere’ gem.

== Configuring the syntax

You can choose one from four syntaxes listed above. For example, if you prefer the symbol syntax, put the following line in your config file.

config.active_record.where_syntax = :hash_value

The default value is +:chain+.

  • for users of previous versions Note that the default behaviour has been changed since 2.0 release if you’ve not explicitly configured the syntax.

== Running specs

There is spec file for each syntax but there is no Rake task for running all the specs at once, because there’s no way to load these freedom-patches without interfering each other. So, please run the +rspec+ command specifying one spec file.

% bundle e rspec spec/chain_spec.rb

== Contributing to Everywhere

  • Fork, fix, then send me a pull request.

== Copyright

Copyright © 2011 Akira Matsuda. See MIT-LICENSE for further details.

Related Repositories



Backport of Android Transitions API for animations. Animations backported to Android 4.0+. API compatible with Android 2.2+ ...



The Open Source Implementation of Google App Engine -- Take your apps everywhere. ...



A browser extension that encrypts your communications with many websites that offer HTTPS but still allow unencrypted connections. ...



An android library that brings the expandable layout with various animation. You can include optional contents and use everywhere. ...



An open source icon pack made with love by the PrestaShop design team. You can use it everywhere to make your designs and websites look awesome. ...

Top Contributors

amatsuda ursm


-   v2.0.0 zip tar
-   v1.0.1 zip tar
-   v1.0.0 zip tar
-   v0.1.0 zip tar
-   v0.0.1 zip tar