encoded_id-rails 0.6.0 → 0.6.1

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: 245fb340a94ca73cff62e2e466ee1f6a8f10195b1df94e0c1d37334c66168925
4
+ data.tar.gz: ffdecb93e8b75ddd0e63da9f5c3d686f80e986fb73035c27bb57882c1982723d
5
5
  SHA512:
6
- metadata.gz: 9f176effb4bc926a4aa61dcbb7d0ca0e88b972186438ffe03a96b68d5e78e1eb0b6a485efcad924aff2070097356b8ced016fb1da0253b38f1d9e80eef21e18e
7
- data.tar.gz: 2f318e0a04cbd5a45fc3edca02c1a8e053590b70963f4b851f8aac150ea465018aea6f21d3f5951bf4c8f7e31bd650a05a8a46328c2ce0812e8e26d2d4e92099
6
+ metadata.gz: c1add38768e797d2e57270a600bd84717141edcdd955c4e5b91c38cfc9585f8aa207099d737bae6f68d2f1364aace46877f50ea014ab2063a44fa718a2ace98a
7
+ data.tar.gz: 47629d384bca18518bbf69645c9e0e8c4ddb0fb1bd064fa006593e3d7ac32d78951486ff442ad6b0d7012a4fbdeb8c79268998e518d24a4435caa7dc9226ebeb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.6.1] - 2023-02-09
4
+
5
+ - Fix `#encoded_id` to return nil if `#id` is nil
6
+ - Ensure `encoded_id` memoization is cleared when record is duplicated, or id changes
7
+
3
8
  ## [0.6.0] - 2022-12-21
4
9
 
5
10
  - 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.instance_variable_set(:@encoded_id, nil)
43
+ new_record.instance_variable_set(:@slugged_encoded_id, nil)
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.1"
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.1
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