based_uuid 0.6.2 → 0.6.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5efa8c1cc0d82b116e8e4bfd6a5170bb83fd01258f19eb35b32aa28a0bc39804
4
- data.tar.gz: 15e4f3a03f286ec1bbc40f3fd1da6d19c2d5b0b17db9718762d4a632966484ac
3
+ metadata.gz: eb5193159372ea36936fc28de906883e38489072e9fd8547014c397b10890412
4
+ data.tar.gz: 7b0ea3665a0e98399a8a1ea879b0dc1a485d5a94c4fca0f1aecfb8937801ccc1
5
5
  SHA512:
6
- metadata.gz: a94e6cf70c7cc5954f97c2720032885ad7bee008f30e41dd6af341c67ad04756940d4e5a8d865d33135abf737a0ed4c9170812d7135e711e848e68d23442b9ec
7
- data.tar.gz: f7eba4f45b4deaadd65d4ac731411bc86a15b47197972bb9ee4c2f0f5ede773a99d79a6b3f50a3a30cc5b47c845f564cc89d628e18d9a28fce67b055b0d6b801
6
+ metadata.gz: 3537ddcaf3b73febcf11f5d81d16cfcc6ee61161cd76cd0e1893f7ac959f5ef54321cf50a22b3b6d4de119401527c1a2f8ac69ec63df8014a055a0ae8ca166bf
7
+ data.tar.gz: 401d5c6184d1a07da28da11f884f2e9135afdba551210892cf55dcbf8496728ccb6f5059302a2e9aee9908a590d20fb0abd72483c17862738a4d49d5c9c0a04b
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Build Status](https://github.com/pch/based_uuid/workflows/Tests/badge.svg)](https://github.com/pch/based_uuid/actions)
4
4
 
5
- Generate “double-clickable”, URL-friendly UUIDs with (optional) prefixes:
5
+ Generate “double-clickable”, URL-friendly UUIDs with optional prefixes:
6
6
 
7
7
  ```
8
8
  user_763j02ryxh8dbs56mgcjqrmmgt #=> e61c802c-7bb1-4357-929a-9064af8a521a
@@ -11,7 +11,7 @@ bpo_12dm1qresn83st62reqdw7f7cv #=> 226d037c-3b35-40f3-a30b-0ebb78779d9b
11
11
 
12
12
  This gem encodes UUID primary keys into 26-character lowercase strings using [Crockford’s base32](https://www.crockford.com/base32.html) encoding. The optional prefix helps you identify the model it represents.
13
13
 
14
- BasedUUID assumes that you have a [UUID primary key](https://guides.rubyonrails.org/v5.0/active_record_postgresql.html#uuid) (`id`) in your ActiveRecord model. It doesn’t affect how your primary key UUIDs are stored in the database. Prefixes and base32-encoded strings are only used for presentation.
14
+ By default, BasedUUID assumes that you have a [UUID primary key](https://guides.rubyonrails.org/v5.0/active_record_postgresql.html#uuid) (`id`) in your ActiveRecord model. It doesn’t affect how UUIDs are stored in the database. Prefixes and base32-encoded strings are only used for presentation.
15
15
 
16
16
  ## Installation
17
17
 
@@ -31,8 +31,11 @@ class BlogPost < ApplicationRecord
31
31
  end
32
32
 
33
33
  post = BlogPost.last
34
- post.based_uuid #=> bpo_12dm1qresn83st62reqdw7f7cv
34
+ post.based_uuid #=> bpo_12dm1qresn83st62reqdw7f7cv
35
35
  post.based_uuid(prefix: false) #=> 12dm1qresn83st62reqdw7f7cv
36
+
37
+ post.based_uuid_with_prefix
38
+ post.based_uuid_without_prefix
36
39
  ```
37
40
 
38
41
  ### Lookup
@@ -102,7 +105,7 @@ BasedUUID.encode(uuid: "226d037c-3b35-40f3-a30b-0ebb78779d9b", prefix: :bpo)
102
105
  BasedUUID.decode("bpo_12dm1qresn83st62reqdw7f7cv")
103
106
  ```
104
107
 
105
- * * *
108
+ ---
106
109
 
107
110
  ## Development
108
111
 
@@ -1,5 +1,5 @@
1
1
  module BasedUUID
2
- module Base32UUID
2
+ class Base32UUID
3
3
  CROCKFORDS_ALPHABET = "0123456789abcdefghjkmnpqrstvwxyz".freeze
4
4
  CHARACTER_MAP = CROCKFORDS_ALPHABET.bytes.freeze
5
5
 
@@ -48,11 +48,19 @@ module BasedUUID
48
48
  end
49
49
 
50
50
  def based_uuid(prefix: true)
51
- raise ArgumentError, "UUID is empty" if _uuid_column_value.blank?
51
+ return nil if _uuid_column_value.blank?
52
52
 
53
53
  BasedUUID.encode(uuid: _uuid_column_value, prefix: prefix ? self.class._based_uuid_prefix : nil)
54
54
  end
55
55
 
56
+ def based_uuid_with_prefix
57
+ based_uuid(prefix: true)
58
+ end
59
+
60
+ def based_uuid_without_prefix
61
+ based_uuid(prefix: false)
62
+ end
63
+
56
64
  private
57
65
 
58
66
  def _uuid_column_value
@@ -1,3 +1,3 @@
1
1
  module BasedUUID
2
- VERSION = "0.6.2".freeze
2
+ VERSION = "0.6.4".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: based_uuid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Chmolowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-07 00:00:00.000000000 Z
11
+ date: 2024-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport