Skip to content

Commit 1369973

Browse files
authored
#7 Add support to custom timestamps
2 parents bae4cf4 + a1c284e commit 1369973

31 files changed

+450
-140
lines changed

.claude/settings.local.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(bundle exec:*)",
5+
"Bash(bundle install:*)"
6+
],
7+
"deny": [],
8+
"ask": []
9+
}
10+
}

.github/workflows/push.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ name: Tests & Linter
22
on: push
33
jobs:
44
test:
5-
env:
6-
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
75
strategy:
86
fail-fast: false
97
matrix:

.rubocop.yml

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
require:
1+
# Last reviewed on July 14th 2025, using RuboCop v1.77.0
2+
3+
plugins:
24
- rubocop-rake
35
- rubocop-rspec
46

57
AllCops:
68
NewCops: enable
7-
TargetRubyVersion: 3.1
9+
TargetRubyVersion: 3.2
810

11+
# As of Ruby 3.0+, # frozen_string_literal: true is no longer necessary in most cases, and in Rails (7.x and upcoming 8), it’s not considered a best practice anymore to manually add it to every file.
912
Style/FrozenStringLiteralComment:
1013
Enabled: true
14+
EnforcedStyle: never
1115

1216
Metrics/MethodLength:
1317
Max: 30
@@ -56,15 +60,19 @@ Layout/EndAlignment:
5660
EnforcedStyleAlignWith: start_of_line
5761

5862
# The default style is `special_inside_parentheses` which looks like:
59-
# in_a_method_call({
60-
# some_key: "value",
61-
# })
63+
#
64+
# this_is_a_method_call({
65+
# some_key: "value",
66+
# })
67+
#
6268
# This would cause an unnecessary huge diff if `in_a_method_call` is renamed,
6369
# because all following lines need to be re-indented. That's why we prefer
6470
# the layout like this:
65-
# in_a_method_call({
66-
# some_key: "value",
67-
# })
71+
#
72+
# this_is_a_method_call({
73+
# some_key: "value",
74+
# })
75+
#
6876
Layout/FirstHashElementIndentation:
6977
EnforcedStyle: consistent
7078

@@ -187,23 +195,63 @@ Style/Documentation:
187195
Style/MethodCallWithArgsParentheses:
188196
Enabled: true
189197
EnforcedStyle: require_parentheses
190-
Exclude:
191-
- "spec/**/*"
198+
AllowParenthesesInMultilineCall: true
199+
AllowedMethods:
200+
- 'attr_accessor'
201+
- 'attr_reader'
202+
- 'command'
203+
- 'desc'
204+
- 'gem'
205+
- 'lane'
206+
- 'platform'
207+
- 'program'
208+
- 'raise'
209+
- 'require_relative'
210+
- 'require'
211+
# rspec tests code below
212+
- 'after'
213+
- 'be'
214+
- 'before'
215+
- 'context'
216+
- 'describe'
217+
- 'it'
218+
- 'not_to'
219+
- 'to'
192220

193221
RSpec/NamedSubject:
222+
Enabled: true
223+
EnforcedStyle: named_only
224+
225+
RSpec/ExampleLength:
194226
Enabled: false
195227

228+
# This cop is not helpful - developers should be able to decide how many memoized helpers are adequate for their tests.
196229
RSpec/MultipleMemoizedHelpers:
197230
Enabled: false
198231

232+
# Multiple expectations in a single example are not necessarily bad, and can be useful to avoid unnecessary duplication and keep tests concise.
199233
RSpec/MultipleExpectations:
200234
Enabled: false
201235

236+
# It catches the false positive of `set_up_`, which is the right spelling for the method's name, so we disable it.
237+
Naming/AccessorMethodName:
238+
Enabled: false
239+
240+
# Checks the indentation of the method name part in method calls that span more than one line, and prefer the style that uses consistent indentation instead of the default (aligned with the first line).
241+
Layout/MultilineMethodCallIndentation:
242+
Enabled: true
243+
EnforcedStyle: indented
244+
245+
# Disallow multiple spaces that aim to align code.
246+
Layout/ExtraSpacing:
247+
Enabled: true
248+
AllowForAlignment: false
249+
202250
RSpec/NestedGroups:
203251
Enabled: true
204252
Max: 4
205253

206254
Style/ClassVars:
207255
Enabled: true
208256
Exclude:
209-
- "lib/vin/request.rb"
257+
- "lib/vin/request.rb"

Gemfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# frozen_string_literal: true
2-
31
source "https://rubygems.org"
42

53
gemspec

Gemfile.lock

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,77 +7,73 @@ PATH
77
GEM
88
remote: https://rubygems.org/
99
specs:
10-
ast (2.4.2)
11-
base64 (0.1.1)
10+
ast (2.4.3)
1211
coderay (1.1.3)
13-
connection_pool (2.4.1)
14-
diff-lcs (1.5.0)
15-
docile (1.4.0)
16-
dotenv (2.8.1)
17-
json (2.6.3)
18-
language_server-protocol (3.17.0.3)
19-
method_source (1.0.0)
20-
parallel (1.23.0)
21-
parser (3.2.2.3)
12+
connection_pool (2.5.3)
13+
diff-lcs (1.6.2)
14+
docile (1.4.1)
15+
dotenv (3.1.8)
16+
json (2.13.2)
17+
language_server-protocol (3.17.0.5)
18+
lint_roller (1.1.0)
19+
method_source (1.1.0)
20+
parallel (1.27.0)
21+
parser (3.3.9.0)
2222
ast (~> 2.4.1)
2323
racc
2424
pastel (0.8.0)
2525
tty-color (~> 0.5)
26-
pry (0.14.2)
26+
prism (1.4.0)
27+
pry (0.15.2)
2728
coderay (~> 1.1)
2829
method_source (~> 1.0)
29-
racc (1.7.1)
30+
racc (1.8.1)
3031
rainbow (3.1.1)
31-
rake (13.0.6)
32-
redis (5.0.7)
33-
redis-client (>= 0.9.0)
34-
redis-client (0.17.0)
32+
rake (13.3.0)
33+
redis (5.4.1)
34+
redis-client (>= 0.22.0)
35+
redis-client (0.25.2)
3536
connection_pool
36-
regexp_parser (2.8.1)
37-
rexml (3.2.6)
38-
rspec (3.12.0)
39-
rspec-core (~> 3.12.0)
40-
rspec-expectations (~> 3.12.0)
41-
rspec-mocks (~> 3.12.0)
42-
rspec-core (3.12.2)
43-
rspec-support (~> 3.12.0)
44-
rspec-expectations (3.12.3)
37+
regexp_parser (2.11.2)
38+
rspec (3.13.1)
39+
rspec-core (~> 3.13.0)
40+
rspec-expectations (~> 3.13.0)
41+
rspec-mocks (~> 3.13.0)
42+
rspec-core (3.13.5)
43+
rspec-support (~> 3.13.0)
44+
rspec-expectations (3.13.5)
4545
diff-lcs (>= 1.2.0, < 2.0)
46-
rspec-support (~> 3.12.0)
47-
rspec-mocks (3.12.6)
46+
rspec-support (~> 3.13.0)
47+
rspec-mocks (3.13.5)
4848
diff-lcs (>= 1.2.0, < 2.0)
49-
rspec-support (~> 3.12.0)
50-
rspec-support (3.12.1)
51-
rubocop (1.56.3)
52-
base64 (~> 0.1.1)
49+
rspec-support (~> 3.13.0)
50+
rspec-support (3.13.5)
51+
rubocop (1.79.2)
5352
json (~> 2.3)
54-
language_server-protocol (>= 3.17.0)
53+
language_server-protocol (~> 3.17.0.2)
54+
lint_roller (~> 1.1.0)
5555
parallel (~> 1.10)
56-
parser (>= 3.2.2.3)
56+
parser (>= 3.3.0.2)
5757
rainbow (>= 2.2.2, < 4.0)
58-
regexp_parser (>= 1.8, < 3.0)
59-
rexml (>= 3.2.5, < 4.0)
60-
rubocop-ast (>= 1.28.1, < 2.0)
58+
regexp_parser (>= 2.9.3, < 3.0)
59+
rubocop-ast (>= 1.46.0, < 2.0)
6160
ruby-progressbar (~> 1.7)
62-
unicode-display_width (>= 2.4.0, < 3.0)
63-
rubocop-ast (1.29.0)
64-
parser (>= 3.2.1.0)
65-
rubocop-capybara (2.19.0)
66-
rubocop (~> 1.41)
67-
rubocop-factory_bot (2.24.0)
68-
rubocop (~> 1.33)
69-
rubocop-rake (0.6.0)
70-
rubocop (~> 1.0)
71-
rubocop-rspec (2.24.1)
72-
rubocop (~> 1.33)
73-
rubocop-capybara (~> 2.17)
74-
rubocop-factory_bot (~> 2.22)
61+
unicode-display_width (>= 2.4.0, < 4.0)
62+
rubocop-ast (1.46.0)
63+
parser (>= 3.3.7.2)
64+
prism (~> 1.4)
65+
rubocop-rake (0.7.1)
66+
lint_roller (~> 1.1)
67+
rubocop (>= 1.72.1)
68+
rubocop-rspec (3.6.0)
69+
lint_roller (~> 1.1)
70+
rubocop (~> 1.72, >= 1.72.1)
7571
ruby-progressbar (1.13.0)
7672
simplecov (0.22.0)
7773
docile (~> 1.1)
7874
simplecov-html (~> 0.11)
7975
simplecov_json_formatter (~> 0.1)
80-
simplecov-html (0.12.3)
76+
simplecov-html (0.13.2)
8177
simplecov_json_formatter (0.1.4)
8278
tty-color (0.6.0)
8379
tty-cursor (0.7.1)
@@ -88,8 +84,10 @@ GEM
8884
tty-cursor (~> 0.7)
8985
tty-screen (~> 0.8)
9086
wisper (~> 2.0)
91-
tty-screen (0.8.1)
92-
unicode-display_width (2.4.2)
87+
tty-screen (0.8.2)
88+
unicode-display_width (3.1.5)
89+
unicode-emoji (~> 4.0, >= 4.0.4)
90+
unicode-emoji (4.0.4)
9391
wisper (2.0.1)
9492

9593
PLATFORMS

Rakefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# frozen_string_literal: true
2-
31
require "bundler/gem_tasks"
42
require "rspec/core/rake_task"
53
require "tty-prompt"

hoov_vin.gemspec

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# frozen_string_literal: true
2-
31
lib = File.expand_path("lib", __dir__)
42
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
53

@@ -16,7 +14,7 @@ Gem::Specification.new do |s|
1614
s.email = "roger@hoov.com.br"
1715
s.homepage = "https://github.com/hoovbr/vin"
1816
s.license = "MIT"
19-
s.required_ruby_version = ">= 3.1"
17+
s.required_ruby_version = ">= 3.2"
2018
s.metadata["homepage_uri"] = s.homepage
2119
s.metadata["source_code_uri"] = "https://github.com/hoovbr/vin"
2220
s.metadata["changelog_uri"] = "https://github.com/hoovbr/vin/blob/main/CHANGELOG.md"

lib/vin.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# frozen_string_literal: true
2-
31
require "redis"
42
require "vin/mixins/redis"
53

@@ -10,17 +8,17 @@ def initialize(config: nil)
108
@config = config || VIN::Config.new
119
end
1210

13-
def generate_id(data_type)
14-
generator.generate_ids(data_type, 1).first
11+
def generate_id(data_type, timestamp: nil)
12+
generator.generate_ids(data_type, 1, timestamp: timestamp).first
1513
end
1614

17-
def generate_ids(data_type, count)
15+
def generate_ids(data_type, count, timestamp: nil)
1816
ids = []
1917
# The Lua script can't always return as many IDs as you may want. So we loop
2018
# until we have the exact amount.
2119
while ids.length < count
2220
initial_id_count = ids.length
23-
ids += generator.generate_ids(data_type, count - ids.length)
21+
ids += generator.generate_ids(data_type, count - ids.length, timestamp: timestamp)
2422
# Ensure the ids array keeps growing as infinite loop insurance
2523
return ids unless ids.length > initial_id_count
2624
end

lib/vin/config.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# frozen_string_literal: true
2-
31
class VIN
42
class Config
53
# Expressed in milliseconds.
@@ -85,9 +83,11 @@ def fetch_allowed_range!
8583
ENV.fetch("VIN_LOGICAL_SHARD_ID_RANGE_MIN", 0).to_i,
8684
ENV.fetch("VIN_LOGICAL_SHARD_ID_RANGE_MAX", 0).to_i,
8785
)
86+
# rubocop:disable Style/BitwisePredicate
8887
unless (logical_shard_id_allowed_range.to_a & range.to_a) == range.to_a
8988
raise(ArgumentError, "VIN_LOGICAL_SHARD_ID_RANGE_MIN and VIN_LOGICAL_SHARD_ID_RANGE_MAX env vars compose a range outside the allowed range of #{logical_shard_id_allowed_range} defined by the number of bits in VIN_LOGICAL_SHARD_ID_BITS env var.")
9089
end
90+
# rubocop:enable Style/BitwisePredicate
9191
range
9292
end
9393
end

0 commit comments

Comments
 (0)