snowflaked 0.1.2-arm64-darwin → 0.1.4-arm64-darwin
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 +4 -4
- data/README.md +18 -1
- data/lib/snowflaked/3.2/snowflaked.bundle +0 -0
- data/lib/snowflaked/3.3/snowflaked.bundle +0 -0
- data/lib/snowflaked/3.4/snowflaked.bundle +0 -0
- data/lib/snowflaked/4.0/snowflaked.bundle +0 -0
- data/lib/snowflaked/model_extensions.rb +15 -5
- data/lib/snowflaked/version.rb +1 -1
- data/lib/snowflaked.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ceac20762522ab00158a0c87b6d2d10e01812cd4d6a30eb5ba01a2e0c91f7075
|
|
4
|
+
data.tar.gz: b7d4dd18078f5cb38b2125db47098a545183f13b4d4e2c90d17e37ab40ff8e94
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 94d6ab9a85a3f1342a87e11ce6a837758d37f4f103d605be6ad938eca1ead7a5532164609ad359a259b94ce06e1919e77678c05a12bd2baada192f328b4ac8a9
|
|
7
|
+
data.tar.gz: d565dc8d14b4630fe95a437cfbe7c9a446a4daf3eee8d1edfbdc50d61c2faa8eeb6301999b9fb2a6682f73dad0e680001bcf5aaa7ea397bd741825e9c454b25b
|
data/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://rubygems.org/gems/snowflaked)
|
|
6
6
|
[](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]
|
|
9
|
-
|
|
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
|
|
21
|
+
return @_snowflake_columns_from_comments if defined?(@_snowflake_columns_from_comments)
|
|
21
22
|
|
|
22
|
-
|
|
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.
|
|
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?
|
data/lib/snowflaked/version.rb
CHANGED
data/lib/snowflaked.rb
CHANGED
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.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: arm64-darwin
|
|
6
6
|
authors:
|
|
7
7
|
- Luiz Eduardo Kowalski
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-01-
|
|
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.
|