snowflaked 0.1.3 → 0.1.4

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: 2d0d8f2af68a50e38cc1aa32c1adc0641fbcdb2d0f01d0bc6e942520da33089f
4
- data.tar.gz: 47f1b23d9a38e2f60ab43f7059c8efd27b783012fbdc8f510ed220b221e3200d
3
+ metadata.gz: 4a6f86e1432fc8b11f282674da8568ffecb835bb5aba3d5c52c124acb4a55ace
4
+ data.tar.gz: 2d13a338cceed05710c0afa3e56896d8199d90b1934ac259e256bed49ba8c3cf
5
5
  SHA512:
6
- metadata.gz: '0278267978cd6a55be0f569659f36ff841c874cbeb2e813cc7f88c1789cf6d8b7ef21886d0bffe1f3268b9c34e1dede2b2eea75ba77468760acbf956d069d57f'
7
- data.tar.gz: 8f2dc54ef2896404ee4698644844ca2611ccb7b6339735ffeb0a7e2dc38854b1df73035c9e7f66a92202c6b5001760b814907303007db2c327dd32195b1d917f
6
+ metadata.gz: 54d45cfb0b0f503e8cc839ac7530439582e08ee11a98e3ec8a79bd9cc3bb0539cd8a0096e2d6618a9015c712bc02e8423ee18dc3d325eb695bdb4e413ad998dd
7
+ data.tar.gz: 4f291445d0e558e1e856f146d5972d52ac068ee907cb20aa4a2ea8d9eb0be818c3d4b53738e0b3ade960662aa8a5f05e6e616f210e0c7a3de7c37d089cbe9454
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Downloads](https://img.shields.io/gem/dt/snowflaked.svg)](https://rubygems.org/gems/snowflaked)
6
6
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.txt)
7
7
 
8
- A high-performance, thread-safe Snowflake ID generator for Ruby, powered by Rust.
8
+ A database-agnostic, high-performance, thread-safe Snowflake ID generator for Ruby, powered by Rust.
9
9
 
10
10
  Snowflake IDs are 64-bit unique identifiers that encode a timestamp, machine ID, and sequence number. They're time-sortable (IDs created later are always larger), making them ideal for distributed systems where you need unique IDs without coordination between machines. Unlike UUIDs, Snowflake IDs are smaller, sortable, and index-friendly for databases.
11
11
 
@@ -143,6 +143,12 @@ Snowflaked.machine_id(id)
143
143
  # => 42
144
144
  ```
145
145
 
146
+ ## Benchmarks
147
+
148
+ See [BENCHMARKS.md](benchmarks/BENCHMARKS.md) for more details.
149
+
150
+ tl;dr: Snowflake IDs have a negligible performance impact compared to database-backed IDs.
151
+
146
152
  ## Requirements
147
153
 
148
154
  - Ruby >= 3.2
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "snowflaked"
3
- version = "0.1.3"
3
+ version = "0.1.4"
4
4
  edition = "2021"
5
5
  publish = false
6
6
 
@@ -6,7 +6,7 @@ module Snowflaked
6
6
 
7
7
  included do
8
8
  class_attribute :_snowflake_attributes, instance_writer: false, default: [:id]
9
- before_validation :_generate_snowflake_ids, on: :create
9
+ after_initialize :_generate_snowflake_ids, if: :new_record?
10
10
  end
11
11
 
12
12
  class_methods do
@@ -14,6 +14,7 @@ module Snowflaked
14
14
  attrs = attributes.map(&:to_sym)
15
15
  attrs |= [:id] if id
16
16
  self._snowflake_attributes = attrs
17
+ @_snowflake_attributes_with_columns = nil
17
18
  end
18
19
 
19
20
  def _snowflake_columns_from_comments
@@ -25,12 +26,17 @@ module Snowflaked
25
26
  []
26
27
  end
27
28
  end
29
+
30
+ def _snowflake_attributes_with_columns
31
+ @_snowflake_attributes_with_columns ||= (_snowflake_attributes | _snowflake_columns_from_comments)
32
+ end
28
33
  end
29
34
 
30
35
  private
31
36
 
32
37
  def _generate_snowflake_ids
33
- attributes_to_generate = self.class._snowflake_attributes | self.class._snowflake_columns_from_comments
38
+ attributes_to_generate = self.class._snowflake_attributes_with_columns
39
+ return if attributes_to_generate.empty?
34
40
 
35
41
  attributes_to_generate.each do |attribute|
36
42
  next if self[attribute].present?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snowflaked
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snowflaked
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luiz Eduardo Kowalski