snowflaked 0.1.4-arm-linux → 0.2.0-arm-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: 02505dc9096e0536b671ea27d47019678c91b8bb1a7ac41e571bb846c68e0108
4
- data.tar.gz: 59e5c3bb9f89acb5e8eb4357349e664c956acdf4f43e559a3319b942f8d816e2
3
+ metadata.gz: f29453adb3b5beb29e002cd5471ffa8dd00c11ba2bf3ae1160045fe4234445d8
4
+ data.tar.gz: eab2733f6bbde075997970e72ed644580ddd208dc9a00d2f522489c98a048ab0
5
5
  SHA512:
6
- metadata.gz: 589c7986aa58bba1ddc7c56e3336a4ba591d3e42aa579318381dca3a1dcfc89317f91d62a2e5e9c364e68988f8294de4ff42d362619933d10404944e518f6594
7
- data.tar.gz: 277759aeef5df7954f5394b6d12e1b48b1074c1d2e63243bf7a1f3e856eb10484b548cabd4e630cadd07b7f53d8dd6552b047803ee2300e5647cde27126eec1a
6
+ metadata.gz: 2cbcc046f261d2802a8b5a4c980d5be51a12f2ae8acb232c40365d20b073645ceb5801660380b6e66ac4d7e6ad0a0fdf58e26b0e631478db8133504debcb6305
7
+ data.tar.gz: f2dc3cdfe2063ac7b0a5add70488c79dce1b8a33f611bbc6b8e9f9ed0aa016cf1a208ccb5b0d9a276c4c8fe67eeb9a095dab8761fbca3ee1dba4318e64d2c54b
data/README.md CHANGED
@@ -145,7 +145,7 @@ Snowflaked.machine_id(id)
145
145
 
146
146
  ## Benchmarks
147
147
 
148
- See [BENCHMARKS.md](benchmarks/BENCHMARKS.md) for more details.
148
+ See [BENCHMARKS.md](benchmarks/README.md) for more details.
149
149
 
150
150
  tl;dr: Snowflake IDs have a negligible performance impact compared to database-backed IDs.
151
151
 
Binary file
Binary file
Binary file
Binary file
@@ -6,7 +6,7 @@ module Snowflaked
6
6
 
7
7
  included do
8
8
  class_attribute :_snowflake_attributes, instance_writer: false, default: [:id]
9
- after_initialize :_generate_snowflake_ids, if: :new_record?
9
+ before_validation :_generate_snowflake_ids, on: :create
10
10
  end
11
11
 
12
12
  class_methods do
@@ -20,11 +20,7 @@ module Snowflaked
20
20
  def _snowflake_columns_from_comments
21
21
  return @_snowflake_columns_from_comments if defined?(@_snowflake_columns_from_comments)
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
23
+ @_snowflake_columns_from_comments = table_exists? ? columns.filter_map { |col| col.name.to_sym if col.comment == Snowflaked::SchemaDefinitions::COMMENT } : []
28
24
  end
29
25
 
30
26
  def _snowflake_attributes_with_columns
@@ -35,10 +31,10 @@ module Snowflaked
35
31
  private
36
32
 
37
33
  def _generate_snowflake_ids
38
- attributes_to_generate = self.class._snowflake_attributes_with_columns
39
- return if attributes_to_generate.empty?
34
+ attributes = self.class._snowflake_attributes_with_columns
35
+ return if attributes.empty?
40
36
 
41
- attributes_to_generate.each do |attribute|
37
+ attributes.each do |attribute|
42
38
  next if self[attribute].present?
43
39
 
44
40
  self[attribute] = Snowflaked.id
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snowflaked
4
- VERSION = "0.1.4"
4
+ VERSION = "0.2.0"
5
5
  end
data/lib/snowflaked.rb CHANGED
@@ -29,8 +29,7 @@ module Snowflaked
29
29
  end
30
30
 
31
31
  def machine_id_value
32
- id = @machine_id || default_machine_id
33
- id % (MAX_MACHINE_ID + 1)
32
+ (@machine_id || default_machine_id) % (MAX_MACHINE_ID + 1)
34
33
  end
35
34
 
36
35
  def epoch_ms
@@ -46,8 +45,7 @@ module Snowflaked
46
45
  end
47
46
 
48
47
  def env_machine_id
49
- id = ENV["SNOWFLAKED_MACHINE_ID"] || ENV.fetch("MACHINE_ID", nil)
50
- id&.to_i
48
+ (ENV["SNOWFLAKED_MACHINE_ID"] || ENV.fetch("MACHINE_ID", nil))&.to_i
51
49
  end
52
50
 
53
51
  def hostname_pid_hash
@@ -68,8 +66,8 @@ module Snowflaked
68
66
  end
69
67
 
70
68
  def id
71
- ensure_initialized!
72
- Native.generate
69
+ config = configuration
70
+ Native.generate(config.machine_id_value, config.epoch_ms)
73
71
  end
74
72
 
75
73
  def parse(id)
@@ -78,16 +76,17 @@ module Snowflaked
78
76
  end
79
77
 
80
78
  def timestamp(id)
81
- time_ms = Native.timestamp_ms(id)
82
- Time.at(time_ms / 1000, (time_ms % 1000) * 1000, :usec)
79
+ ensure_initialized!
80
+ seconds, milliseconds = Native.timestamp_ms(id).divmod(1000)
81
+ Time.at(seconds, milliseconds * 1000, :usec)
83
82
  end
84
83
 
85
84
  def machine_id(id)
86
- ensure_initialized!
87
85
  Native.machine_id(id)
88
86
  end
89
87
 
90
88
  def timestamp_ms(id)
89
+ ensure_initialized!
91
90
  Native.timestamp_ms(id)
92
91
  end
93
92
 
@@ -100,8 +99,7 @@ module Snowflaked
100
99
  def ensure_initialized!
101
100
  return if Native.initialized?
102
101
 
103
- config = configuration
104
- Native.init_generator(config.machine_id_value, config.epoch_ms)
102
+ Native.init_generator(configuration.machine_id_value, configuration.epoch_ms)
105
103
  end
106
104
  end
107
105
  end
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
4
+ version: 0.2.0
5
5
  platform: arm-linux
6
6
  authors:
7
7
  - Luiz Eduardo Kowalski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-01-14 00:00:00.000000000 Z
11
+ date: 2026-02-27 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.