identifiable 0.1.0 → 0.2.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: 490257eea4bca942162766045db54e9cac0b3cdbedcea08a418e3b659cc209ec
4
- data.tar.gz: e3cfa1004c351eac0170b1740e291b9f3a878c72a450b9cc7c787ae999b33d83
3
+ metadata.gz: f13f950aecd88db7423e77dda8c4bb98b9ec3513fc1b6e2e636fa18abc9f5459
4
+ data.tar.gz: 54e93ff16ebc2fb3a8f2d6668777da9c5e62595aea7c2913b3ba20a9b8f36d47
5
5
  SHA512:
6
- metadata.gz: e54d72207095067e3b7fea091a5bb41665525d43c5ececa51c228f5ee824d1fc7f55c5c2ca5aac177504456508b60bef7a7d61a27757cc3a801be269cc2b4f0c
7
- data.tar.gz: e685fb908d6122fc2e4ce52cb0957bfb50c813705a9acecfe64ddb5ec7fea09dbbddacb346ec70d83de2c4b73107189edc53b5ae0554d58cafc68eed24189da3
6
+ metadata.gz: db32c493be43afad1d670af0c3474bb2e50eca36b66c3e215ae84645295e9da41d12ad8b438408d406c12fe17509e2ed56f3335cb265c674379a2bd71f6f4ec2
7
+ data.tar.gz: 0fc43e2b34c4659bc910367da1eb87f41caba8d28c6a1e9ccd93783402b00fe459717685f9cf2ee9f3ac51f31f60e07a536e2996609b01f85fe508dcd3ca12df
@@ -5,7 +5,7 @@ jobs:
5
5
  name: 'Test Suite'
6
6
  strategy:
7
7
  matrix:
8
- ruby: [2.5, 2.6, 2.7]
8
+ ruby: [2.7.6, 3.0.4, 3.1.2]
9
9
  runs-on: ubuntu-latest
10
10
  steps:
11
11
  - uses: actions/checkout@v2
@@ -26,11 +26,11 @@ jobs:
26
26
  - uses: actions/checkout@v2
27
27
  - uses: ruby/setup-ruby@v1
28
28
  with:
29
- ruby-version: 2.7.2
29
+ ruby-version: 2.7.0
30
30
  - uses: actions/cache@v1
31
31
  with:
32
32
  path: vendor/bundle
33
- key: bundle-2.7.2-${{ hashFiles('**/*.gemspec') }}
34
- restore-keys: bundle-2.7.2
33
+ key: bundle-2.7.0-${{ hashFiles('**/*.gemspec') }}
34
+ restore-keys: bundle-2.7.0
35
35
  - run: bundle install --jobs 4 --retry 3 --path vendor/bundle
36
36
  - run: bundle exec rubocop
data/.rubocop.yml CHANGED
@@ -1,6 +1,9 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
3
 
4
+ Gemspec/RequiredRubyVersion:
5
+ Enabled: false
6
+
4
7
  Style/Documentation:
5
8
  Enabled: false
6
9
 
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 2.7.1
1
+ ruby 2.7.0
data/Gemfile.lock CHANGED
@@ -1,67 +1,64 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- identifiable (0.1.0)
5
- activerecord (> 4.2)
4
+ identifiable (0.2.0)
5
+ activerecord (> 5.2)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (6.0.3.4)
11
- activesupport (= 6.0.3.4)
12
- activerecord (6.0.3.4)
13
- activemodel (= 6.0.3.4)
14
- activesupport (= 6.0.3.4)
15
- activesupport (6.0.3.4)
10
+ activemodel (7.0.3.1)
11
+ activesupport (= 7.0.3.1)
12
+ activerecord (7.0.3.1)
13
+ activemodel (= 7.0.3.1)
14
+ activesupport (= 7.0.3.1)
15
+ activesupport (7.0.3.1)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
- i18n (>= 0.7, < 2)
18
- minitest (~> 5.1)
19
- tzinfo (~> 1.1)
20
- zeitwerk (~> 2.2, >= 2.2.2)
21
- ast (2.4.1)
22
- concurrent-ruby (1.1.7)
23
- diff-lcs (1.4.4)
24
- i18n (1.8.5)
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ tzinfo (~> 2.0)
20
+ ast (2.4.2)
21
+ concurrent-ruby (1.1.10)
22
+ diff-lcs (1.5.0)
23
+ i18n (1.11.0)
25
24
  concurrent-ruby (~> 1.0)
26
- minitest (5.14.2)
27
- parallel (1.20.0)
28
- parser (2.7.2.0)
25
+ minitest (5.16.2)
26
+ parallel (1.22.1)
27
+ parser (3.1.2.0)
29
28
  ast (~> 2.4.1)
30
- rainbow (3.0.0)
29
+ rainbow (3.1.1)
31
30
  rake (12.3.3)
32
- regexp_parser (1.8.2)
33
- rexml (3.2.4)
34
- rspec (3.10.0)
35
- rspec-core (~> 3.10.0)
36
- rspec-expectations (~> 3.10.0)
37
- rspec-mocks (~> 3.10.0)
38
- rspec-core (3.10.0)
39
- rspec-support (~> 3.10.0)
40
- rspec-expectations (3.10.0)
31
+ regexp_parser (2.3.0)
32
+ rexml (3.2.5)
33
+ rspec (3.11.0)
34
+ rspec-core (~> 3.11.0)
35
+ rspec-expectations (~> 3.11.0)
36
+ rspec-mocks (~> 3.11.0)
37
+ rspec-core (3.11.0)
38
+ rspec-support (~> 3.11.0)
39
+ rspec-expectations (3.11.0)
41
40
  diff-lcs (>= 1.2.0, < 2.0)
42
- rspec-support (~> 3.10.0)
43
- rspec-mocks (3.10.0)
41
+ rspec-support (~> 3.11.0)
42
+ rspec-mocks (3.11.1)
44
43
  diff-lcs (>= 1.2.0, < 2.0)
45
- rspec-support (~> 3.10.0)
46
- rspec-support (3.10.0)
47
- rubocop (1.3.0)
44
+ rspec-support (~> 3.11.0)
45
+ rspec-support (3.11.0)
46
+ rubocop (1.28.1)
48
47
  parallel (~> 1.10)
49
- parser (>= 2.7.1.5)
48
+ parser (>= 3.1.0.0)
50
49
  rainbow (>= 2.2.2, < 4.0)
51
- regexp_parser (>= 1.8)
50
+ regexp_parser (>= 1.8, < 3.0)
52
51
  rexml
53
- rubocop-ast (>= 1.1.1)
52
+ rubocop-ast (>= 1.17.0, < 2.0)
54
53
  ruby-progressbar (~> 1.7)
55
- unicode-display_width (>= 1.4.0, < 2.0)
56
- rubocop-ast (1.1.1)
57
- parser (>= 2.7.1.5)
58
- ruby-progressbar (1.10.1)
54
+ unicode-display_width (>= 1.4.0, < 3.0)
55
+ rubocop-ast (1.17.0)
56
+ parser (>= 3.1.1.0)
57
+ ruby-progressbar (1.11.0)
59
58
  sqlite3 (1.4.2)
60
- thread_safe (0.3.6)
61
- tzinfo (1.2.7)
62
- thread_safe (~> 0.1)
63
- unicode-display_width (1.7.0)
64
- zeitwerk (2.4.0)
59
+ tzinfo (2.0.4)
60
+ concurrent-ruby (~> 1.0)
61
+ unicode-display_width (2.1.0)
65
62
 
66
63
  PLATFORMS
67
64
  ruby
@@ -74,4 +71,4 @@ DEPENDENCIES
74
71
  sqlite3
75
72
 
76
73
  BUNDLED WITH
77
- 2.1.4
74
+ 2.1.2
data/README.md CHANGED
@@ -13,10 +13,10 @@ Identifiable makes it really simple to generate and use random public-facing IDs
13
13
 
14
14
  ```ruby
15
15
  # Before:
16
- orders_url(id: @order.id) # → https://example.app/orders/14
16
+ orders_url(@order) # → https://example.app/orders/14
17
17
 
18
18
  # After:
19
- orders_url(id: @order.public_id) # → https://example.app/orders/87133275
19
+ orders_url(@order) # → https://example.app/orders/87133275
20
20
  ```
21
21
 
22
22
  ## Installation
@@ -72,7 +72,7 @@ While Identifiable strives to have useful defaults, you may want to customize yo
72
72
 
73
73
  ### Different public ID styles
74
74
 
75
- By default, Identifiable will generate numeric public IDs, with each character between 0 and 9, but it can also generate alphanumeric public IDs and UUID public ids. To chose your public ID style, simply pass it in as a parameter to `identifiable` on your model.
75
+ By default, Identifiable will generate numeric public IDs, with each character between 0 and 9, but it can also generate alphanumeric public IDs and UUID public IDs. To choose your public ID style, simply pass it in as a parameter to `identifiable` on your model.
76
76
 
77
77
  ```ruby
78
78
  class Order < ApplicationRecord
@@ -112,14 +112,17 @@ end
112
112
 
113
113
  The `length` parameter is ignored if you're using `style: :uuid`, because UUIDs already have a fixed length. The `length` parameter also needs be an Integer, and can't be less than `4` or greater than `128`. If any of these constraints are broken, Identifiable will raise an error letting you know.
114
114
 
115
+ ## Alternatives
116
+
117
+ I built Identifiable because I never could quite get the other gems that do similar things quite the way that I liked them. You might have the same experience with Identifiable, so if you try Identifiable and find that it's not quite to your tastes, try out some of these alternatives:
118
+
119
+ * [**Hashid Rails**](https://github.com/jcypret/hashid-rails) uses [hashids](http://hashids.org/ruby) to seamlessly create hex strings for your primary keys. It's nice because it doesn't require an extra column in your database, but it's limited in what it can do.
120
+ * [**Public UID**](https://github.com/equivalent/public_uid) is a real power-users public ID gem, and until I made this it was the main way I would build public ID features into the apps I was working on, but I found it too heavy for what I wanted 90% of the time, which is why Identifiable is customizable, but not _too_ customizable. If you find Identifiable isn't customizable or powerful enough for your needs, give Public UID a go!
121
+
115
122
  ## Contributing
116
123
 
117
- Bug reports and pull requests are welcome on [GitHub](https://github.com/tpritc/identifiable). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/tpritc/identifiable/blob/main/CODE_OF_CONDUCT.md).
124
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/tpritc/identifiable). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/tpritc/identifiable/blob/main/CODE_OF_CONDUCT.md) while interacting in the project's codebases, issue trackers, chat rooms, and mailing lists.
118
125
 
119
126
  ## License
120
127
 
121
128
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). If you or your organization need a custom, commercial license for any reason, [send me an email](mailto:hi@tpritc.com) and I'll be happy to set something up for you.
122
-
123
- ## Code of Conduct
124
-
125
- Everyone interacting in the Identifiable project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/tpritc/identifiable/blob/main/CODE_OF_CONDUCT.md).
data/identifiable.gemspec CHANGED
@@ -6,12 +6,12 @@ Gem::Specification.new do |spec|
6
6
  spec.version = Identifiable::VERSION
7
7
  spec.name = 'identifiable'
8
8
  spec.authors = ['Tom Pritchard']
9
- spec.email = ['hi@tpritc.com']
9
+ spec.email = ['tom@tpritc.com']
10
10
 
11
11
  spec.summary = 'A quick and easy way to add random, customizable, public-facing IDs to your models.'
12
12
  spec.homepage = 'https://github.com/tpritc/identifiable'
13
13
  spec.license = 'MIT'
14
- spec.required_ruby_version = '>= 2.5.0'
14
+ spec.required_ruby_version = '>= 2.7.0'
15
15
 
16
16
  # Specify which files should be added to the gem when it is released.
17
17
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -22,9 +22,10 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_dependency 'activerecord', '> 4.2'
25
+ spec.add_dependency 'activerecord', '> 5.2'
26
26
  spec.add_development_dependency 'rake', '~> 12.0'
27
27
  spec.add_development_dependency 'rspec', '~> 3.0'
28
28
  spec.add_development_dependency 'rubocop', '~> 1.3'
29
29
  spec.add_development_dependency 'sqlite3'
30
+ spec.metadata['rubygems_mfa_required'] = 'true'
30
31
  end
@@ -25,7 +25,7 @@ module Identifiable
25
25
  end
26
26
 
27
27
  def find_by_public_id(public_id)
28
- where(Hash[identifiable_column, public_id]).first
28
+ where({ identifiable_column => public_id }).first
29
29
  end
30
30
 
31
31
  def find_by_public_id!(public_id)
@@ -54,11 +54,17 @@ module Identifiable
54
54
  # The column parameter must be in the model's table, so check that the
55
55
  # column corresponds to a column in the model's table, and raise an error
56
56
  # if it is not.
57
+ #
58
+ # We suppress ActiveRecord::StatmentInvalid errors just in case the table
59
+ # does not exist yet.
60
+ # rubocop:disable Lint/SuppressedException
57
61
  def _identifiable_validate_column_must_be_in_the_table
58
62
  return if column_names.include? @identifiable_column.to_s
59
63
 
60
64
  raise Identifiable::Errors::ColumnMustExistInTheTableError.new(@identifiable_column, valid_columns: column_names)
65
+ rescue ActiveRecord::StatementInvalid
61
66
  end
67
+ # rubocop:enable Lint/SuppressedException
62
68
 
63
69
  # We can only use valid styles, so check that the style parameter is a
64
70
  # valid style, and raise an error if it is not.
@@ -114,5 +120,19 @@ module Identifiable
114
120
  # If we got this far, we've got a new valid public ID, time to set it!
115
121
  self[self.class.identifiable_column] = new_public_id
116
122
  end
123
+
124
+ # By overriding ActiveRecord's `#to_key`, this means that Rails' helpers,
125
+ # such as `dom_id` will use the public ID instead of the regular ID when
126
+ # identifying the record.
127
+ def to_key
128
+ [self[self.class.identifiable_column]]
129
+ end
130
+
131
+ # By overriding ActiveRecord's `#to_param`, this means that Rails' helpers,
132
+ # such as the `link_to` helpers will default to using the public ID
133
+ # instead of the regular ID when identifying the record.
134
+ def to_param
135
+ self[self.class.identifiable_column]
136
+ end
117
137
  end
118
138
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Identifiable
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: identifiable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Pritchard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-15 00:00:00.000000000 Z
11
+ date: 2022-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
19
+ version: '5.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: '5.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -82,7 +82,7 @@ dependencies:
82
82
  version: '0'
83
83
  description:
84
84
  email:
85
- - hi@tpritc.com
85
+ - tom@tpritc.com
86
86
  executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
@@ -112,7 +112,8 @@ files:
112
112
  homepage: https://github.com/tpritc/identifiable
113
113
  licenses:
114
114
  - MIT
115
- metadata: {}
115
+ metadata:
116
+ rubygems_mfa_required: 'true'
116
117
  post_install_message:
117
118
  rdoc_options: []
118
119
  require_paths:
@@ -121,7 +122,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
122
  requirements:
122
123
  - - ">="
123
124
  - !ruby/object:Gem::Version
124
- version: 2.5.0
125
+ version: 2.7.0
125
126
  required_rubygems_version: !ruby/object:Gem::Requirement
126
127
  requirements:
127
128
  - - ">="