parentry 1.5.0 → 1.6.0

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
  SHA256:
3
- metadata.gz: f3feb70016cb4448fb7a633c183e4c28451779e80f4b17d9f41c9b56e8e4e560
4
- data.tar.gz: 54c9e48f984205d2ba80c5bd53d745c19c89bd95529c63b7e2f4f2335ce3b89a
3
+ metadata.gz: 61d7162155374b612b01ec0d2c5519ca49e94e8c793f843b6187148d67dc16d4
4
+ data.tar.gz: b1aea8a7225ff14ad890367d799171927eaaf99e262d3b9b4fcb52171f09d611
5
5
  SHA512:
6
- metadata.gz: ad121d565f69446d95ef7db926461dd0c51c28ef981c95b0b02ed8debb6b27f40f7576773f76e31e35336704d9bb3fa5705461e9ef2bc5e02a66e4f542e8a534
7
- data.tar.gz: 34ed4870c5f7fed79a0558df2e4db01f932690f8e07b935f56c4dfce6343529b6ba2bf69d97a00c039cadc820cd40ae708494bbdf9f8ed6be10c479958852f59
6
+ metadata.gz: e96ac1b93d29040797963e598976d3878b7852bbb564e5d0ebd5d1ec15ab4c0c4362a4c887b750a5d8467d8207e8f376facbe23396b24e1e33c209cc58240848
7
+ data.tar.gz: d6bdd03b87f6e35824e4b0cbb88a68fdaef2b81f9122a69ef211db4b1b064423af8a11017263cf6032c09076e7a5986dc598b6a1cde6d724fe821af86d2637e7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- parentry (1.5.0)
4
+ parentry (1.6.0)
5
5
  activerecord (>= 5.1, < 7.1)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- parentry (1.5.0)
4
+ parentry (1.6.0)
5
5
  activerecord (>= 5.1, < 7.1)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- parentry (1.5.0)
4
+ parentry (1.6.0)
5
5
  activerecord (>= 5.1, < 7.1)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- parentry (1.5.0)
4
+ parentry (1.6.0)
5
5
  activerecord (>= 5.1, < 7.1)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- parentry (1.5.0)
4
+ parentry (1.6.0)
5
5
  activerecord (>= 5.1, < 7.1)
6
6
 
7
7
  GEM
@@ -3,7 +3,7 @@ module Parentry
3
3
  module Array
4
4
  module ClassMethods
5
5
  def parentry_depth_function
6
- Arel.sql("array_length(#{parentry_column}, 1)")
6
+ Arel::Nodes::NamedFunction.new('array_length', [arel_table[parentry_column], 1])
7
7
  end
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module Parentry
3
3
  module Ltree
4
4
  module ClassMethods
5
5
  def parentry_depth_function
6
- Arel.sql("nlevel(#{parentry_column})")
6
+ Arel::Nodes::NamedFunction.new('nlevel', [arel_table[parentry_column]])
7
7
  end
8
8
  end
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module Parentry
2
- VERSION = '1.5.0'.freeze
2
+ VERSION = '1.6.0'.freeze
3
3
  end
data/lib/parentry.rb CHANGED
@@ -39,13 +39,17 @@ module Parentry
39
39
 
40
40
  scope :order_by_parentry, -> { order(parentry_depth_function) }
41
41
 
42
- scope :before_depth, ->(depth) { where("#{parentry_depth_function} - 1 < ?", depth + depth_offset) }
43
- scope :to_depth, ->(depth) { where("#{parentry_depth_function} - 1 <= ?", depth + depth_offset) }
44
- scope :at_depth, ->(depth) { where("#{parentry_depth_function} - 1 = ?", depth + depth_offset) }
45
- scope :from_depth, ->(depth) { where("#{parentry_depth_function} - 1 >= ?", depth + depth_offset) }
46
- scope :after_depth, ->(depth) { where("#{parentry_depth_function} - 1 > ?", depth + depth_offset) }
42
+ {
43
+ before_depth: Arel::Nodes::LessThan,
44
+ to_depth: Arel::Nodes::LessThanOrEqual,
45
+ at_depth: Arel::Nodes::Equality,
46
+ from_depth: Arel::Nodes::GreaterThanOrEqual,
47
+ after_depth: Arel::Nodes::GreaterThan
48
+ }.each do |name, node|
49
+ scope name, ->(depth) { where(node.new(parentry_depth_function, depth + depth_offset + 1)) }
50
+ end
47
51
 
48
- scope :roots, -> { where("#{parentry_depth_function} = 1") }
52
+ scope :roots, -> { where(Arel::Nodes::Equality.new(parentry_depth_function, 1)) }
49
53
  scope :ancestors_of, ->(node) { where(node.ancestor_conditions).where.not(id: node.id) }
50
54
  scope :children_of, ->(node) { where(parent_id: node.id) }
51
55
  scope :descendants_of, ->(node) { subtree_of(node).where.not(id: node.id) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parentry
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamed Asghari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-19 00:00:00.000000000 Z
11
+ date: 2022-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord