where_exists 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 6f1f20fb282b67f60382f0d48c47f506623c3941e6d003b07b217eaa42291b9d
4
- data.tar.gz: a4d5235b9373ad42c223eb439a611da125cc35ab7107ff6cf0b4c045bbd4f29e
2
+ SHA1:
3
+ metadata.gz: 053b8ce3825e7f5eeb8faa98a85d5e2fc92c4edf
4
+ data.tar.gz: 4aefc7de26143e6b72b62f99113fea19f6737b2e
5
5
  SHA512:
6
- metadata.gz: dbffcaf8b56b8aaf0c4c6e18586e41fba2ece5a4373f5adb6f0d5e42aee574eaf8d2c1cfd60842fd07d8a633c14f597bc65a0ae78742fb8b03f75f5a8226a94b
7
- data.tar.gz: 178fa0742ea16a40d0809d344cc42750a39157e24e2e4df40bb34148967d53b035248a093d4e82e890e219577fd618916fade84b56239d41da656623c63a3b3a
6
+ metadata.gz: e3b5343d68abd33b091752e49c4689215655e515d785052478022bd33f743d621e196c1bbab623a57d67db1e46bcc3ea3a8949b4170955b09674b371f389b5fa
7
+ data.tar.gz: 166df723c753b0b755eb46b51c9f4acac4f795ac887fb2d1d9ed18ec27ee76b78c783d5f32d8d1fbf29e70ac2a7589b0e4877fd6c02deb1315fddb5925c70226
File without changes
data/Rakefile CHANGED
File without changes
@@ -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
- queries_sql = queries.map { |query| "EXISTS (" + query.to_sql + ")" }.join(" OR ")
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)
@@ -1,3 +1,3 @@
1
1
  module WhereExists
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -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
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.2
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-05 00:00:00.000000000 Z
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.7.7
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
Binary file