snowflaked 0.1.2-aarch64-linux → 0.1.4-aarch64-linux

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: 75cbb2a00b48882b805caf24b928190d9e3fc814bf34e7efc0284975278d92d3
4
- data.tar.gz: 90b1780dbadd717618235648424082d3fa8af19a1d1d729613d082f24d3fc241
3
+ metadata.gz: bcb218e7e9987a188b3cf6d5dff9db035f9fb2b9ea131e0ffeff2962fb78be59
4
+ data.tar.gz: 33612f2fad093b2acb683e1c093c8f90eadb3bb70edbb988a57b6fbd5773e5a6
5
5
  SHA512:
6
- metadata.gz: 3dd253994c2010c0280288b87fea5e2341e764364365e3151713d6b7642bde7de4da3e3aef28822d38095442bf664b71142d8b743e8136aaf53cebe9c874050a
7
- data.tar.gz: c89a0a6e3f55c0f45c037e9cd683fdff2d9103cf4b55ab120dd1f691685e3a110da416769158767990d98d310c7a539a1e4836f338f9584b06b18c03c8c73820
6
+ metadata.gz: 3dbe672efc98b46b82b71eb51631144c3a05cd20fe2a499a1fdd11d4441ff632c7541ccd5fd82ad9a6c657b666ea6eb81f0323fd7dbd20181fdb014e6693b24b
7
+ data.tar.gz: 3e4f1e6d9a10a74962ae4877807fa519d45a17ee77359400741463aab452886ab3e06693f35362fdb3033ef208129b974e7a4bbc09fc302e78b5967f2fc45917
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
 
@@ -87,6 +87,13 @@ Snowflaked.configure do |config|
87
87
  end
88
88
  ```
89
89
 
90
+ ### Machine ID
91
+
92
+ > [!TIP]
93
+ > For multi-process servers like Puma, it is recommended to **not** configure `machine_id` explicitly. The gem automatically calculates a unique machine ID using `(hostname.hash ^ pid) % 1024`, which ensures each forked worker process gets a different ID and avoids duplicate Snowflake IDs.
94
+
95
+ If you must set `machine_id` explicitly, use environment variables that differ per worker process.
96
+
90
97
  ### Machine ID Resolution
91
98
 
92
99
  If `machine_id` is not explicitly configured, it resolves in this order:
@@ -136,6 +143,12 @@ Snowflaked.machine_id(id)
136
143
  # => 42
137
144
  ```
138
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
+
139
152
  ## Requirements
140
153
 
141
154
  - Ruby >= 3.2
@@ -151,6 +164,10 @@ bundle install
151
164
  bundle exec rake
152
165
  ```
153
166
 
167
+ ## Acknowledgments
168
+
169
+ - [snowflaked-rs](https://github.com/MrGunflame/snowflaked-rs) - the Rust implementation of Snowflake IDs
170
+
154
171
  ## License
155
172
 
156
173
  MIT
Binary file
Binary file
Binary file
Binary file
@@ -5,8 +5,8 @@ module Snowflaked
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  included do
8
- class_attribute :_snowflake_attributes, instance_writer: false, default: [:id] # rubocop:disable ThreadSafety/ClassAndModuleAttributes -- false positive
9
- before_validation :_generate_snowflake_ids, on: :create
8
+ class_attribute :_snowflake_attributes, instance_writer: false, default: [:id]
9
+ after_initialize :_generate_snowflake_ids, if: :new_record?
10
10
  end
11
11
 
12
12
  class_methods do
@@ -14,19 +14,29 @@ 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
20
- return [] unless table_exists?
21
+ return @_snowflake_columns_from_comments if defined?(@_snowflake_columns_from_comments)
21
22
 
22
- columns.filter_map { |col| col.name.to_sym if col.comment == Snowflaked::SchemaDefinitions::COMMENT }
23
+ @_snowflake_columns_from_comments = if table_exists?
24
+ columns.filter_map { |col| col.name.to_sym if col.comment == Snowflaked::SchemaDefinitions::COMMENT }
25
+ else
26
+ []
27
+ end
28
+ end
29
+
30
+ def _snowflake_attributes_with_columns
31
+ @_snowflake_attributes_with_columns ||= (_snowflake_attributes | _snowflake_columns_from_comments)
23
32
  end
24
33
  end
25
34
 
26
35
  private
27
36
 
28
37
  def _generate_snowflake_ids
29
- 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?
30
40
 
31
41
  attributes_to_generate.each do |attribute|
32
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.2"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/snowflaked.rb CHANGED
@@ -57,7 +57,7 @@ module Snowflaked
57
57
 
58
58
  class << self
59
59
  def configuration
60
- @configuration ||= Configuration.new # rubocop:disable ThreadSafety/ClassInstanceVariable -- not changed after initialization
60
+ @configuration ||= Configuration.new
61
61
  end
62
62
 
63
63
  def configure
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snowflaked
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Luiz Eduardo Kowalski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-01-10 00:00:00.000000000 Z
11
+ date: 2026-01-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Ruby gem for generating Twitter Snowflake IDs using a high-performance
14
14
  Rust backend. Thread-safe with configurable machine ID and custom epoch support.