where_exists 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/MIT-LICENSE +0 -0
- data/Rakefile +0 -0
- data/lib/where_exists.rb +12 -8
- data/lib/where_exists/version.rb +1 -1
- data/test/belongs_to_polymorphic_test.rb +0 -0
- data/test/belongs_to_test.rb +0 -0
- data/test/documentation_test.rb +0 -0
- data/test/has_and_belongs_to_many.rb +0 -0
- data/test/has_many_polymorphic_test.rb +0 -0
- data/test/has_many_test.rb +16 -0
- data/test/has_many_through_test.rb +0 -0
- data/test/test_helper.rb +0 -0
- metadata +3 -5
- data/test/db/test.db +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 053b8ce3825e7f5eeb8faa98a85d5e2fc92c4edf
|
4
|
+
data.tar.gz: 4aefc7de26143e6b72b62f99113fea19f6737b2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3b5343d68abd33b091752e49c4689215655e515d785052478022bd33f743d621e196c1bbab623a57d67db1e46bcc3ea3a8949b4170955b09674b371f389b5fa
|
7
|
+
data.tar.gz: 166df723c753b0b755eb46b51c9f4acac4f795ac887fb2d1d9ed18ec27ee76b78c783d5f32d8d1fbf29e70ac2a7589b0e4877fd6c02deb1315fddb5925c70226
|
data/MIT-LICENSE
CHANGED
File without changes
|
data/Rakefile
CHANGED
File without changes
|
data/lib/where_exists.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
|
3
3
|
module WhereExists
|
4
|
-
def where_exists(association_name, *where_parameters)
|
5
|
-
where_exists_or_not_exists(true, association_name, where_parameters)
|
4
|
+
def where_exists(association_name, *where_parameters, &block)
|
5
|
+
where_exists_or_not_exists(true, association_name, where_parameters, &block)
|
6
6
|
end
|
7
7
|
|
8
|
-
def where_not_exists(association_name, *where_parameters)
|
9
|
-
where_exists_or_not_exists(false, association_name, where_parameters)
|
8
|
+
def where_not_exists(association_name, *where_parameters, &block)
|
9
|
+
where_exists_or_not_exists(false, association_name, where_parameters, &block)
|
10
10
|
end
|
11
11
|
|
12
12
|
protected
|
13
13
|
|
14
|
-
def where_exists_or_not_exists(does_exist, association_name, where_parameters)
|
15
|
-
queries_sql = build_exists_string(association_name, *where_parameters)
|
14
|
+
def where_exists_or_not_exists(does_exist, association_name, where_parameters, &block)
|
15
|
+
queries_sql = build_exists_string(association_name, *where_parameters, &block)
|
16
16
|
|
17
17
|
if does_exist
|
18
18
|
not_string = ""
|
@@ -23,7 +23,7 @@ module WhereExists
|
|
23
23
|
self.where("#{not_string}(#{queries_sql})")
|
24
24
|
end
|
25
25
|
|
26
|
-
def build_exists_string(association_name, *where_parameters)
|
26
|
+
def build_exists_string(association_name, *where_parameters, &block)
|
27
27
|
association = self.reflect_on_association(association_name)
|
28
28
|
|
29
29
|
unless association
|
@@ -46,7 +46,11 @@ module WhereExists
|
|
46
46
|
end
|
47
47
|
raise ArgumentError.new("where_exists: not supported association – #{inspection}")
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
|
+
queries_sql = queries.map { |query|
|
51
|
+
query = yield query if block_given?
|
52
|
+
"EXISTS (" + query.to_sql + ")"
|
53
|
+
}.join(" OR ")
|
50
54
|
end
|
51
55
|
|
52
56
|
def where_exists_for_belongs_to_query(association, where_parameters)
|
data/lib/where_exists/version.rb
CHANGED
File without changes
|
data/test/belongs_to_test.rb
CHANGED
File without changes
|
data/test/documentation_test.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
data/test/has_many_test.rb
CHANGED
@@ -7,6 +7,7 @@ end
|
|
7
7
|
|
8
8
|
ActiveRecord::Migration.create_table :simple_entity_children, :force => true do |t|
|
9
9
|
t.integer :parent_id
|
10
|
+
t.datetime :my_date
|
10
11
|
t.string :name
|
11
12
|
end
|
12
13
|
|
@@ -87,4 +88,19 @@ class HasManyTest < Minitest::Test
|
|
87
88
|
assert_equal 1, result.length
|
88
89
|
assert_equal result.first.id, blank_entity.id
|
89
90
|
end
|
91
|
+
|
92
|
+
def test_dynamic_scopes
|
93
|
+
child_past = SimpleEntityChild.create! my_date: Time.now - 1.minute
|
94
|
+
child_future = SimpleEntityChild.create! my_date: Time.now + 1.minute
|
95
|
+
|
96
|
+
_blank_entity = SimpleEntity.create!(simple_entity_children: [child_future], my_id: 999)
|
97
|
+
filled_entity = SimpleEntity.create!(simple_entity_children: [child_past], my_id: 500)
|
98
|
+
|
99
|
+
result = SimpleEntity.where_exists(:simple_entity_children) {|scope|
|
100
|
+
scope.where('my_date < ?', Time.now)
|
101
|
+
}
|
102
|
+
|
103
|
+
assert_equal 1, result.length
|
104
|
+
assert_equal result.first.id, filled_entity.id
|
105
|
+
end
|
90
106
|
end
|
File without changes
|
data/test/test_helper.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: where_exists
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugene Zolotarev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -99,7 +99,6 @@ files:
|
|
99
99
|
- lib/where_exists/version.rb
|
100
100
|
- test/belongs_to_polymorphic_test.rb
|
101
101
|
- test/belongs_to_test.rb
|
102
|
-
- test/db/test.db
|
103
102
|
- test/documentation_test.rb
|
104
103
|
- test/has_and_belongs_to_many.rb
|
105
104
|
- test/has_many_polymorphic_test.rb
|
@@ -126,14 +125,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
125
|
version: '0'
|
127
126
|
requirements: []
|
128
127
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.
|
128
|
+
rubygems_version: 2.6.11
|
130
129
|
signing_key:
|
131
130
|
specification_version: 4
|
132
131
|
summary: "#where_exists extension of ActiveRecord"
|
133
132
|
test_files:
|
134
133
|
- test/belongs_to_polymorphic_test.rb
|
135
134
|
- test/belongs_to_test.rb
|
136
|
-
- test/db/test.db
|
137
135
|
- test/documentation_test.rb
|
138
136
|
- test/has_and_belongs_to_many.rb
|
139
137
|
- test/has_many_polymorphic_test.rb
|
data/test/db/test.db
DELETED
Binary file
|