encoded_id-rails 0.6.0 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of encoded_id-rails might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 599b4c236c59881b00eefbe0feaf4fa6f1a04015573ba5d807f041ba2932e602
4
- data.tar.gz: ff6ee760d956606accfb98a75be00cf04a545695e0dcce56e9eb271b1d824fee
3
+ metadata.gz: f6c56ae6571c9793eb8b20d4cb2d9bfbbc3e1ebf1c313b774c42640ea68d6584
4
+ data.tar.gz: 58b5fbf9eb0e79fc152f23a2055f7c9ec2131dd5000342f0fe3d2e40f796f712
5
5
  SHA512:
6
- metadata.gz: 9f176effb4bc926a4aa61dcbb7d0ca0e88b972186438ffe03a96b68d5e78e1eb0b6a485efcad924aff2070097356b8ced016fb1da0253b38f1d9e80eef21e18e
7
- data.tar.gz: 2f318e0a04cbd5a45fc3edca02c1a8e053590b70963f4b851f8aac150ea465018aea6f21d3f5951bf4c8f7e31bd650a05a8a46328c2ce0812e8e26d2d4e92099
6
+ metadata.gz: cf5668fbf5100a23b4b4019392ac2f1a0325af3288427c96909183fa3e3a2111689d3f349d187b88ecd456e02a4796256c8d3f81e288dd65464e5ba623e83a48
7
+ data.tar.gz: b6191f0ee41f5732e0706b20b44ce74627d1ff9a5683447b57abe8ffe0ea351d9bee39df4e1b4f755654722547b814d572689c2d1cdf73b22a697962a5eac2d0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.6.2] - 2023-02-09
4
+
5
+ - Fix `encoded_id` memoization clearing when record is duplicated
6
+
7
+ ## [0.6.1] - 2023-02-09
8
+
9
+ - Fix `#encoded_id` to return nil if `#id` is nil
10
+ - Ensure `encoded_id` memoization is cleared when record is duplicated, or id changes
11
+
3
12
  ## [0.6.0] - 2022-12-21
4
13
 
5
14
  - Rename mixin to `Model`
@@ -13,11 +13,15 @@ module EncodedId
13
13
  end
14
14
 
15
15
  def encoded_id
16
- @encoded_id ||= self.class.encode_encoded_id(id)
16
+ return unless id
17
+ return @encoded_id if defined?(@encoded_id) && !id_changed?
18
+ @encoded_id = self.class.encode_encoded_id(id)
17
19
  end
18
20
 
19
21
  def slugged_encoded_id(with: :name_for_encoded_id_slug)
20
- @slugged_encoded_id ||= EncodedId::Rails::SluggedId.new(
22
+ return unless id
23
+ return @slugged_encoded_id if defined?(@slugged_encoded_id) && !id_changed?
24
+ @slugged_encoded_id = EncodedId::Rails::SluggedId.new(
21
25
  self,
22
26
  slug_method: with,
23
27
  id_method: :encoded_id,
@@ -31,6 +35,14 @@ module EncodedId
31
35
  raise StandardError, "Class must have a `name`, cannot create a slug" if !class_name || class_name.blank?
32
36
  class_name.underscore
33
37
  end
38
+
39
+ # When duplicating an ActiveRecord object, we want to reset the memoized encoded_id
40
+ def dup
41
+ super.tap do |new_record|
42
+ new_record.send(:remove_instance_variable, :@encoded_id) if new_record.instance_variable_defined?(:@encoded_id)
43
+ new_record.send(:remove_instance_variable, :@slugged_encoded_id) if new_record.instance_variable_defined?(:@slugged_encoded_id)
44
+ end
45
+ end
34
46
  end
35
47
  end
36
48
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module EncodedId
4
4
  module Rails
5
- VERSION = "0.6.0"
5
+ VERSION = "0.6.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: encoded_id-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Ierodiaconou
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-21 00:00:00.000000000 Z
11
+ date: 2023-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport