bmg 0.18.11 → 0.18.12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eda140880e29f5e083ad334176579ed2dfad9090
4
- data.tar.gz: 444a8cc5f96b80ba3bbf6d807be1438c2d26abd7
3
+ metadata.gz: f6017c8a4f02206eac582bbd66801976c7beeba0
4
+ data.tar.gz: 5e22c7739d0a16d79ec8a0871dfc9e4a60a4bd9d
5
5
  SHA512:
6
- metadata.gz: 96ecc393e90d3ae413655d70c4b1676fa2f9831e519ef61cbd25139b873efcd75a825745cce0597e083fc59bc331b08d30b5717b1e5b42adacb5297147a044bd
7
- data.tar.gz: dc687db5b22f9f3fc53b2ccf0916722065ca7d25b8ad04b0a042c6d79fd66f40c22f2d05461da8019db8b70f54c4c104658f3dce3862f9a37b2af44c6ee25d61
6
+ metadata.gz: 6eb6a6e24b42e3b3651ea5f73d7481f3c7f22289bd8b450ec5cf5a4ab1ab07e9e63ad47c017ac3dd5d57a0c856e9c5834e2c26e4be6f7a56ece54b1045234fa4
7
+ data.tar.gz: 0b40fd858dbae47f1069ef1caef71357f9313a3ca0912f288f366ac65b3e32e8068cd0de4206d4822431f2156c680f5a71b18ac8dc0aee112314deb5a3435a5b
@@ -32,7 +32,8 @@ module Bmg
32
32
  def each(&bl)
33
33
  return to_enum unless block_given?
34
34
  page_size = options[:page_size]
35
- @operand.to_a
35
+ @operand
36
+ .to_a
36
37
  .sort(&comparator)
37
38
  .drop(page_size * (page_index-1))
38
39
  .take(page_size)
@@ -46,7 +47,7 @@ module Bmg
46
47
  protected ### inspect
47
48
 
48
49
  def comparator
49
- Ordering.new(@ordering).comparator
50
+ @comparator ||= Ordering.new(@ordering).comparator
50
51
  end
51
52
 
52
53
  def args
@@ -24,13 +24,27 @@ module Bmg
24
24
  protected :type=
25
25
 
26
26
  def each(&bl)
27
- spy.call(self) if bl
28
- operand.each(&bl)
27
+ return enum_for(:each) unless bl
28
+
29
+ if spy.respond_to?(:measure)
30
+ spy.measure(self) do
31
+ operand.each(&bl)
32
+ end
33
+ else
34
+ spy.call(self)
35
+ operand.each(&bl)
36
+ end
29
37
  end
30
38
 
31
39
  def count
32
- spy.call(self) if bl
33
- operand.count
40
+ if spy.respond_to?(:measure)
41
+ spy.measure(self) do
42
+ operand.count
43
+ end
44
+ else
45
+ spy.call(self)
46
+ operand.count
47
+ end
34
48
  end
35
49
 
36
50
  def to_ast
@@ -11,13 +11,26 @@ module Bmg
11
11
  end
12
12
 
13
13
  def comparator
14
- @comparator ||= ->(t1, t2) {
15
- attrs.each do |(attr,direction)|
16
- c = t1[attr] <=> t2[attr]
17
- return (direction == :desc ? -c : c) unless c==0
14
+ @comparator ||= ->(t1, t2) { compare_attrs(t1, t2) }
15
+ end
16
+
17
+ def compare_attrs(t1, t2)
18
+ attrs.each do |(attr,direction)|
19
+ a1, a2 = t1[attr], t2[attr]
20
+ if a1.nil? && a2.nil?
21
+ 0
22
+ elsif a1.nil?
23
+ return direction == :desc ? -1 : 1
24
+ elsif a2.nil?
25
+ return direction == :desc ? 1 : -1
26
+ elsif a1.respond_to?(:<=>)
27
+ c = a1 <=> a2
28
+ unless c.nil? || c==0
29
+ return direction == :desc ? -c : c
30
+ end
18
31
  end
19
- 0
20
- }
32
+ end
33
+ 0
21
34
  end
22
35
 
23
36
  end # class Ordering
data/lib/bmg/version.rb CHANGED
@@ -2,7 +2,7 @@ module Bmg
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 18
5
- TINY = 11
5
+ TINY = 12
6
6
  end
7
7
  VERSION = "#{Version::MAJOR}.#{Version::MINOR}.#{Version::TINY}"
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bmg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.11
4
+ version: 0.18.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernard Lambeau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-11 00:00:00.000000000 Z
11
+ date: 2022-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: predicate