everywhere 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +79 -0
- data/Rakefile +1 -0
- data/everywhere.gemspec +25 -0
- data/lib/everywhere.rb +2 -0
- data/lib/everywhere/hash_key.rb +59 -0
- data/lib/everywhere/hash_value.rb +53 -0
- data/lib/everywhere/method.rb +21 -0
- data/lib/everywhere/railtie.rb +17 -0
- data/lib/everywhere/symbol.rb +16 -0
- data/lib/everywhere/util.rb +15 -0
- data/lib/everywhere/version.rb +3 -0
- data/spec/hash_key_spec.rb +52 -0
- data/spec/hash_value_spec.rb +52 -0
- data/spec/method_spec.rb +52 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/symbol_spec.rb +52 -0
- metadata +131 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Akira Matsuda
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
= Everywhere
|
2
|
+
|
3
|
+
Hash condition syntax for AR query everywhere!
|
4
|
+
|
5
|
+
|
6
|
+
== Features
|
7
|
+
|
8
|
+
=== where + not
|
9
|
+
|
10
|
+
"+Everywhere+" enables you to construct where + not query such as below using AR Hash query syntax.
|
11
|
+
|
12
|
+
SELECT "users".* FROM "users" WHERE ("users"."name" != 'foo')
|
13
|
+
SELECT "users".* FROM "users" WHERE ("users"."created_at" IS NOT NULL)
|
14
|
+
SELECT "users".* FROM "users" WHERE ("users"."status" NOT IN ('inactive', 'deleted')
|
15
|
+
|
16
|
+
|
17
|
+
== Syntaxes
|
18
|
+
|
19
|
+
"+Everywhere+" supports 4 syntaxes.
|
20
|
+
|
21
|
+
* hash_value
|
22
|
+
Push the value into a Hash indexed by +:not+.
|
23
|
+
Similar to MongoDB. http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24ne
|
24
|
+
|
25
|
+
User.where(:name => {:not => 'foo'})
|
26
|
+
=> SELECT "users".* FROM "users" WHERE ("users"."name" != 'foo')
|
27
|
+
|
28
|
+
* hash_key
|
29
|
+
Put the whole key + value Hash into another Hash indexed by +:not+.
|
30
|
+
|
31
|
+
User.where(:not => {:name => 'foo'})
|
32
|
+
=> SELECT "users".* FROM "users" WHERE ("users"."name" != 'foo')
|
33
|
+
|
34
|
+
* symbol
|
35
|
+
Put +:not+ as the first parameter of +where+ method.
|
36
|
+
|
37
|
+
User.where(:not, :name => 'foo')
|
38
|
+
=> SELECT "users".* FROM "users" WHERE ("users"."name" != 'foo')
|
39
|
+
|
40
|
+
* method
|
41
|
+
Use the special method named +where_not+.
|
42
|
+
|
43
|
+
User.where_not(:not, :name => 'foo')
|
44
|
+
=> SELECT "users".* FROM "users" WHERE ("users"."name" != 'foo')
|
45
|
+
|
46
|
+
|
47
|
+
== Supported versions
|
48
|
+
|
49
|
+
ActiveRecord 3.0.x, 3.1.x, and 3.2 (edge)
|
50
|
+
|
51
|
+
|
52
|
+
== Usage
|
53
|
+
|
54
|
+
Bundle 'everywhere' gem.
|
55
|
+
|
56
|
+
|
57
|
+
== Configuring the syntax
|
58
|
+
|
59
|
+
You can choose one from four syntaxes listed above.
|
60
|
+
For example, if you prefer the symbol syntax, put the following line in your config file.
|
61
|
+
|
62
|
+
config.active_record.where_syntax = :symbol
|
63
|
+
|
64
|
+
The default value is +:hash_value+.
|
65
|
+
|
66
|
+
|
67
|
+
== Todo
|
68
|
+
|
69
|
+
+like+ and +not like+ (if needed)
|
70
|
+
|
71
|
+
|
72
|
+
== Contributing to Everywhere
|
73
|
+
|
74
|
+
* Fork, fix, then send me a pull request.
|
75
|
+
|
76
|
+
|
77
|
+
== Copyright
|
78
|
+
|
79
|
+
Copyright (c) 2011 Akira Matsuda. See MIT-LICENSE for further details.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/everywhere.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "everywhere/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "everywhere"
|
7
|
+
s.version = Everywhere::VERSION
|
8
|
+
s.authors = ["Akira Matsuda"]
|
9
|
+
s.email = ["ronnie@dio.jp"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Hash condition syntax for AR query everywhere!}
|
12
|
+
s.description = %q{Hash condition syntax for AR query everywhere!}
|
13
|
+
|
14
|
+
s.rubyforge_project = "everywhere"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency 'rspec'
|
23
|
+
s.add_development_dependency 'sqlite3'
|
24
|
+
s.add_runtime_dependency 'activerecord'
|
25
|
+
end
|
data/lib/everywhere.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'everywhere/util'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
class PredicateBuilder
|
5
|
+
if ActiveRecord::VERSION::STRING > '3.1'
|
6
|
+
class << self
|
7
|
+
include Everywhere::Util
|
8
|
+
|
9
|
+
def build_from_hash_with_not(engine, attributes, default_table)
|
10
|
+
attributes_with_not = {}
|
11
|
+
attributes.each do |column, value|
|
12
|
+
# {not: {key: value}}
|
13
|
+
if column == :not
|
14
|
+
value.each do |k, v|
|
15
|
+
attributes_with_not["#{k}__not__"] = v
|
16
|
+
end
|
17
|
+
else
|
18
|
+
attributes_with_not[column] = value
|
19
|
+
end
|
20
|
+
end
|
21
|
+
build_from_hash_without_not(engine, attributes_with_not, default_table).map do |rel|
|
22
|
+
if rel.left.name.to_s.ends_with? '__not__'
|
23
|
+
rel.left.name = rel.left.name.to_s.sub(/__not__$/, '').to_sym
|
24
|
+
negate rel
|
25
|
+
else
|
26
|
+
rel
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
alias_method_chain :build_from_hash, :not
|
31
|
+
end
|
32
|
+
else
|
33
|
+
include Everywhere::Util
|
34
|
+
|
35
|
+
def build_from_hash_with_not(attributes, default_table)
|
36
|
+
attributes_with_not = {}
|
37
|
+
attributes.each do |column, value|
|
38
|
+
# {not: {key: value}}
|
39
|
+
if column == :not
|
40
|
+
value.each do |k, v|
|
41
|
+
attributes_with_not["#{k}__not__"] = v
|
42
|
+
end
|
43
|
+
else
|
44
|
+
attributes_with_not[column] = value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
build_from_hash_without_not(attributes_with_not, default_table).map do |rel|
|
48
|
+
if rel.left.name.to_s.ends_with? '__not__'
|
49
|
+
rel.left.name = rel.left.name.to_s.sub(/__not__$/, '').to_sym
|
50
|
+
negate rel
|
51
|
+
else
|
52
|
+
rel
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
alias_method_chain :build_from_hash, :not
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'everywhere/util'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
class PredicateBuilder
|
5
|
+
if ActiveRecord::VERSION::STRING > '3.1'
|
6
|
+
class << self
|
7
|
+
include Everywhere::Util
|
8
|
+
|
9
|
+
def build_from_hash_with_not(engine, attributes, default_table)
|
10
|
+
attributes_with_not = attributes.map do |column, value|
|
11
|
+
# {key: {not: value}}
|
12
|
+
if value.is_a?(Hash) && (value.keys.size == 1) && (value.keys.first == :not)
|
13
|
+
["#{column}__not__", value.values.first]
|
14
|
+
else
|
15
|
+
[column, value]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
build_from_hash_without_not(engine, attributes_with_not, default_table).map do |rel|
|
19
|
+
if rel.left.name.to_s.ends_with? '__not__'
|
20
|
+
rel.left.name = rel.left.name.to_s.sub(/__not__$/, '').to_sym
|
21
|
+
negate rel
|
22
|
+
else
|
23
|
+
rel
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
alias_method_chain :build_from_hash, :not
|
28
|
+
end
|
29
|
+
else
|
30
|
+
include Everywhere::Util
|
31
|
+
|
32
|
+
def build_from_hash_with_not(attributes, default_table)
|
33
|
+
attributes_with_not = attributes.map do |column, value|
|
34
|
+
# {key: {not: value}}
|
35
|
+
if value.is_a?(Hash) && (value.keys.size == 1) && (value.keys.first == :not)
|
36
|
+
["#{column}__not__", value.values.first]
|
37
|
+
else
|
38
|
+
[column, value]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
build_from_hash_without_not(attributes_with_not, default_table).map do |rel|
|
42
|
+
if rel.left.name.to_s.ends_with? '__not__'
|
43
|
+
rel.left.name = rel.left.name.to_s.sub(/__not__$/, '').to_sym
|
44
|
+
negate rel
|
45
|
+
else
|
46
|
+
rel
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
alias_method_chain :build_from_hash, :not
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'everywhere/util'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
class Base
|
5
|
+
class << self
|
6
|
+
delegate :where_not, :to => :scoped
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module QueryMethods
|
11
|
+
include Everywhere::Util
|
12
|
+
|
13
|
+
def where_not(opts, *rest)
|
14
|
+
return self if opts.blank?
|
15
|
+
|
16
|
+
relation = clone
|
17
|
+
relation.where_values += build_where(opts, rest).map {|r| negate r}
|
18
|
+
relation
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
class Base
|
5
|
+
cattr_accessor :where_syntax, :instance_writer => false
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module Everywhere
|
10
|
+
class Railtie < ::Rails::Railtie #:nodoc:
|
11
|
+
initializer 'everywhere' do |app|
|
12
|
+
ActiveSupport.on_load(:active_record) do
|
13
|
+
require "everywhere/#{app.config.active_record.where_syntax || 'hash_value'}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'everywhere/util'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module QueryMethods
|
5
|
+
include Everywhere::Util
|
6
|
+
|
7
|
+
def build_where_with_not(opts, other = [])
|
8
|
+
if opts == :not
|
9
|
+
build_where_without_not(*other).map {|r| negate r}
|
10
|
+
else
|
11
|
+
build_where_without_not(opts, other)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
alias_method_chain :build_where, :not
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Everywhere
|
2
|
+
module Util
|
3
|
+
private
|
4
|
+
def negate(rel)
|
5
|
+
case rel.class.name
|
6
|
+
when 'Arel::Nodes::Equality'
|
7
|
+
Arel::Nodes::NotEqual.new rel.left, rel.right
|
8
|
+
when 'Arel::Nodes::In'
|
9
|
+
Arel::Nodes::NotIn.new rel.left, rel.right
|
10
|
+
else
|
11
|
+
rel.not
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'everywhere/hash_key'
|
3
|
+
|
4
|
+
describe 'normal query' do
|
5
|
+
before do
|
6
|
+
@where = Post.where(:title => 'hello').where_values
|
7
|
+
end
|
8
|
+
subject { @where }
|
9
|
+
it { @where.should have(1).item }
|
10
|
+
subject { @where.first }
|
11
|
+
its(:to_sql) { should == %q["posts"."title" = 'hello'] }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'not eq' do
|
15
|
+
before do
|
16
|
+
@where = Post.where(:not => {:title => 'hello'}).where_values
|
17
|
+
end
|
18
|
+
subject { @where }
|
19
|
+
it { @where.should have(1).item }
|
20
|
+
subject { @where.first }
|
21
|
+
its(:to_sql) { should == %q["posts"."title" != 'hello'] }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'not null' do
|
25
|
+
before do
|
26
|
+
@where = Post.where(:not => {:created_at => nil}).where_values
|
27
|
+
end
|
28
|
+
subject { @where }
|
29
|
+
it { @where.should have(1).item }
|
30
|
+
subject { @where.first }
|
31
|
+
its(:to_sql) { should == %q["posts"."created_at" IS NOT NULL] }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'not in' do
|
35
|
+
before do
|
36
|
+
@where = Post.where(:not => {:title => %w[hello goodbye]}).where_values
|
37
|
+
end
|
38
|
+
subject { @where }
|
39
|
+
it { @where.should have(1).item }
|
40
|
+
subject { @where.first }
|
41
|
+
its(:to_sql) { should == %q["posts"."title" NOT IN ('hello', 'goodbye')] }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'association' do
|
45
|
+
before do
|
46
|
+
@where = Post.joins(:comments).where(:comments => {:not => {:body => 'foo'}}).where_values
|
47
|
+
end
|
48
|
+
subject { @where }
|
49
|
+
it { @where.should have(1).item }
|
50
|
+
subject { @where.first }
|
51
|
+
its(:to_sql) { should == %q["comments"."body" != 'foo'] }
|
52
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'everywhere/hash_value'
|
3
|
+
|
4
|
+
describe 'normal query' do
|
5
|
+
before do
|
6
|
+
@where = Post.where(:title => 'hello').where_values
|
7
|
+
end
|
8
|
+
subject { @where }
|
9
|
+
it { @where.should have(1).item }
|
10
|
+
subject { @where.first }
|
11
|
+
its(:to_sql) { should == %q["posts"."title" = 'hello'] }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'not eq' do
|
15
|
+
before do
|
16
|
+
@where = Post.where(:title => {:not => 'hello'}).where_values
|
17
|
+
end
|
18
|
+
subject { @where }
|
19
|
+
it { @where.should have(1).item }
|
20
|
+
subject { @where.first }
|
21
|
+
its(:to_sql) { should == %q["posts"."title" != 'hello'] }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'not null' do
|
25
|
+
before do
|
26
|
+
@where = Post.where(:created_at => {:not => nil}).where_values
|
27
|
+
end
|
28
|
+
subject { @where }
|
29
|
+
it { @where.should have(1).item }
|
30
|
+
subject { @where.first }
|
31
|
+
its(:to_sql) { should == %q["posts"."created_at" IS NOT NULL] }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'not in' do
|
35
|
+
before do
|
36
|
+
@where = Post.where(:title => {:not => %w[hello goodbye]}).where_values
|
37
|
+
end
|
38
|
+
subject { @where }
|
39
|
+
it { @where.should have(1).item }
|
40
|
+
subject { @where.first }
|
41
|
+
its(:to_sql) { should == %q["posts"."title" NOT IN ('hello', 'goodbye')] }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'association' do
|
45
|
+
before do
|
46
|
+
@where = Post.joins(:comments).where(:comments => {:body => {:not => 'foo'}}).where_values
|
47
|
+
end
|
48
|
+
subject { @where }
|
49
|
+
it { @where.should have(1).item }
|
50
|
+
subject { @where.first }
|
51
|
+
its(:to_sql) { should == %q["comments"."body" != 'foo'] }
|
52
|
+
end
|
data/spec/method_spec.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'everywhere/method'
|
3
|
+
|
4
|
+
describe 'normal query' do
|
5
|
+
before do
|
6
|
+
@where = Post.where(:name => 'hello').where_values
|
7
|
+
end
|
8
|
+
subject { @where }
|
9
|
+
it { @where.should have(1).item }
|
10
|
+
subject { @where.first }
|
11
|
+
its(:to_sql) { should == %q["posts"."name" = 'hello'] }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'not eq' do
|
15
|
+
before do
|
16
|
+
@where = Post.where_not(:name => 'hello').where_values
|
17
|
+
end
|
18
|
+
subject { @where }
|
19
|
+
it { @where.should have(1).item }
|
20
|
+
subject { @where.first }
|
21
|
+
its(:to_sql) { should == %q["posts"."name" != 'hello'] }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'not null' do
|
25
|
+
before do
|
26
|
+
@where = Post.where_not(:created_at => nil).where_values
|
27
|
+
end
|
28
|
+
subject { @where }
|
29
|
+
it { @where.should have(1).item }
|
30
|
+
subject { @where.first }
|
31
|
+
its(:to_sql) { should == %q["posts"."created_at" IS NOT NULL] }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'not in' do
|
35
|
+
before do
|
36
|
+
@where = Post.where_not(:name => %w[hello goodbye]).where_values
|
37
|
+
end
|
38
|
+
subject { @where }
|
39
|
+
it { @where.should have(1).item }
|
40
|
+
subject { @where.first }
|
41
|
+
its(:to_sql) { should == %q["posts"."name" NOT IN ('hello', 'goodbye')] }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'association' do
|
45
|
+
before do
|
46
|
+
@where = Post.joins(:comments).where_not(:comments => {:body => 'foo'}).where_values
|
47
|
+
end
|
48
|
+
subject { @where }
|
49
|
+
it { @where.should have(1).item }
|
50
|
+
subject { @where.first }
|
51
|
+
its(:to_sql) { should == %q["comments"."body" != 'foo'] }
|
52
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'active_record'
|
4
|
+
|
5
|
+
# database
|
6
|
+
ActiveRecord::Base.configurations = {'test' => {:adapter => 'sqlite3', :database => ':memory:'}}
|
7
|
+
ActiveRecord::Base.establish_connection('test')
|
8
|
+
|
9
|
+
# models
|
10
|
+
class Post < ActiveRecord::Base
|
11
|
+
has_many :comments
|
12
|
+
end
|
13
|
+
|
14
|
+
class Comment < ActiveRecord::Base
|
15
|
+
belongs_to :post
|
16
|
+
end
|
17
|
+
|
18
|
+
#migrations
|
19
|
+
class CreateAllTables < ActiveRecord::Migration
|
20
|
+
def self.up
|
21
|
+
create_table(:posts) {|t| t.string :title}
|
22
|
+
create_table(:comments) {|t| t.text :body; t.references :post}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
RSpec.configure do |config|
|
27
|
+
config.before :all do
|
28
|
+
CreateAllTables.up unless ActiveRecord::Base.connection.table_exists? 'posts'
|
29
|
+
end
|
30
|
+
end
|
data/spec/symbol_spec.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'everywhere/symbol'
|
3
|
+
|
4
|
+
describe 'normal query' do
|
5
|
+
before do
|
6
|
+
@where = Post.where(:name => 'hello').where_values
|
7
|
+
end
|
8
|
+
subject { @where }
|
9
|
+
it { @where.should have(1).item }
|
10
|
+
subject { @where.first }
|
11
|
+
its(:to_sql) { should == %q["posts"."name" = 'hello'] }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'not eq' do
|
15
|
+
before do
|
16
|
+
@where = Post.where(:not, :name => 'hello').where_values
|
17
|
+
end
|
18
|
+
subject { @where }
|
19
|
+
it { @where.should have(1).item }
|
20
|
+
subject { @where.first }
|
21
|
+
its(:to_sql) { should == %q["posts"."name" != 'hello'] }
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'not null' do
|
25
|
+
before do
|
26
|
+
@where = Post.where(:not, :created_at => nil).where_values
|
27
|
+
end
|
28
|
+
subject { @where }
|
29
|
+
it { @where.should have(1).item }
|
30
|
+
subject { @where.first }
|
31
|
+
its(:to_sql) { should == %q["posts"."created_at" IS NOT NULL] }
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'not in' do
|
35
|
+
before do
|
36
|
+
@where = Post.where(:not, :name => %w[hello goodbye]).where_values
|
37
|
+
end
|
38
|
+
subject { @where }
|
39
|
+
it { @where.should have(1).item }
|
40
|
+
subject { @where.first }
|
41
|
+
its(:to_sql) { should == %q["posts"."name" NOT IN ('hello', 'goodbye')] }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'association' do
|
45
|
+
before do
|
46
|
+
@where = Post.joins(:comments).where(:not, :comments => {:body => 'foo'}).where_values
|
47
|
+
end
|
48
|
+
subject { @where }
|
49
|
+
it { @where.should have(1).item }
|
50
|
+
subject { @where.first }
|
51
|
+
its(:to_sql) { should == %q["comments"."body" != 'foo'] }
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: everywhere
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Akira Matsuda
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-11-24 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: sqlite3
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: activerecord
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
62
|
+
description: Hash condition syntax for AR query everywhere!
|
63
|
+
email:
|
64
|
+
- ronnie@dio.jp
|
65
|
+
executables: []
|
66
|
+
|
67
|
+
extensions: []
|
68
|
+
|
69
|
+
extra_rdoc_files: []
|
70
|
+
|
71
|
+
files:
|
72
|
+
- .gitignore
|
73
|
+
- .rspec
|
74
|
+
- Gemfile
|
75
|
+
- MIT-LICENSE
|
76
|
+
- README.rdoc
|
77
|
+
- Rakefile
|
78
|
+
- everywhere.gemspec
|
79
|
+
- lib/everywhere.rb
|
80
|
+
- lib/everywhere/hash_key.rb
|
81
|
+
- lib/everywhere/hash_value.rb
|
82
|
+
- lib/everywhere/method.rb
|
83
|
+
- lib/everywhere/railtie.rb
|
84
|
+
- lib/everywhere/symbol.rb
|
85
|
+
- lib/everywhere/util.rb
|
86
|
+
- lib/everywhere/version.rb
|
87
|
+
- spec/hash_key_spec.rb
|
88
|
+
- spec/hash_value_spec.rb
|
89
|
+
- spec/method_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
- spec/symbol_spec.rb
|
92
|
+
homepage: ""
|
93
|
+
licenses: []
|
94
|
+
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
hash: 3
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
version: "0"
|
118
|
+
requirements: []
|
119
|
+
|
120
|
+
rubyforge_project: everywhere
|
121
|
+
rubygems_version: 1.8.11
|
122
|
+
signing_key:
|
123
|
+
specification_version: 3
|
124
|
+
summary: Hash condition syntax for AR query everywhere!
|
125
|
+
test_files:
|
126
|
+
- spec/hash_key_spec.rb
|
127
|
+
- spec/hash_value_spec.rb
|
128
|
+
- spec/method_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
130
|
+
- spec/symbol_spec.rb
|
131
|
+
has_rdoc:
|