parentry 0.3.0 → 0.3.1

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: 6196cdde92cc6aa6dd52c59caaeb186f7ba46a09
4
- data.tar.gz: cf93a7d1fd294bf3b26b4a2543ef542118877d94
3
+ metadata.gz: 261e45f2ceb096605d761ed6a774684edc24c53a
4
+ data.tar.gz: 42d22ad8ccc1f2217b67ad6af01fff03dd85a454
5
5
  SHA512:
6
- metadata.gz: c4eda67096b326c045dc040b9e47731c150a208d14e9aac2ae607631d4c6c2939dcf8c8a96477c2d8b035ab71c3cedf4d11ee81c719cc833056bd905f246a50b
7
- data.tar.gz: dae64307dcdf143e62d19a2d3f20cbcc99ade9d8afdd7b64177014a0b0035b265292d179249b97833586d26004ae4c3b6551ee839d3bc43b82076982a505a7c6
6
+ metadata.gz: c63b998524c891a393505a8464b668338f0bd9f06936884315b092a46bc962c7eaf6a28f5d0e548d569fc29c2749e4b33dee99dc30aca10567b4dbdb22f9c320
7
+ data.tar.gz: e20688b736eac361ac213242cdbd1eff5116f316ccb863de1dabdf11878f45c901357a126dcc84e8c037e3913820ef8ed9315a994c10d27c026412e576879779
@@ -23,7 +23,9 @@ module Parentry
23
23
  after_create :commit_parentry
24
24
  before_update :assign_parentry, if: proc { changes[:parent_id].present? }
25
25
  after_update :cascade_parentry, if: proc { changes[parentry_column].present? }
26
- after_save :cache_parentry_depth, if: proc { cache_depth && depth != parentry_depth }
26
+
27
+ before_validation :cache_parentry_depth, if: proc { cache_depth }
28
+ before_save :cache_parentry_depth, if: proc { cache_depth }
27
29
 
28
30
  after_save :touch_ancestors_callback
29
31
  after_touch :touch_ancestors_callback
@@ -18,7 +18,7 @@ module Parentry
18
18
  end
19
19
 
20
20
  def cache_parentry_depth
21
- update_column(:parentry_depth, depth)
21
+ write_attribute(:parentry_depth, depth)
22
22
  end
23
23
 
24
24
  def cascade_parentry
@@ -9,7 +9,7 @@ module Parentry
9
9
  end
10
10
 
11
11
  def root?
12
- root_id == id
12
+ parent_id.nil?
13
13
  end
14
14
 
15
15
  def path_ids
@@ -78,7 +78,8 @@ module Parentry
78
78
  end
79
79
 
80
80
  def depth
81
- path_ids.size - 1 + depth_offset
81
+ return depth_offset if root?
82
+ parent.depth + 1
82
83
  end
83
84
 
84
85
  private
@@ -1,3 +1,3 @@
1
1
  module Parentry
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parentry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamed Asghari