Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"permissions": {
"allow": [
"Bash(bundle exec:*)",
"Bash(bundle install:*)"
],
"deny": [],
"ask": []
}
}
2 changes: 0 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Tests & Linter
on: push
jobs:
test:
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
strategy:
fail-fast: false
matrix:
Expand Down
70 changes: 59 additions & 11 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
require:
# Last reviewed on July 14th 2025, using RuboCop v1.77.0

plugins:
- rubocop-rake
- rubocop-rspec

AllCops:
NewCops: enable
TargetRubyVersion: 3.1
TargetRubyVersion: 3.2

# 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.
Style/FrozenStringLiteralComment:
Enabled: true
EnforcedStyle: never

Metrics/MethodLength:
Max: 30
Expand Down Expand Up @@ -56,15 +60,19 @@ Layout/EndAlignment:
EnforcedStyleAlignWith: start_of_line

# The default style is `special_inside_parentheses` which looks like:
# in_a_method_call({
# some_key: "value",
# })
#
# this_is_a_method_call({
# some_key: "value",
# })
#
# This would cause an unnecessary huge diff if `in_a_method_call` is renamed,
# because all following lines need to be re-indented. That's why we prefer
# the layout like this:
# in_a_method_call({
# some_key: "value",
# })
#
# this_is_a_method_call({
# some_key: "value",
# })
#
Layout/FirstHashElementIndentation:
EnforcedStyle: consistent

Expand Down Expand Up @@ -187,23 +195,63 @@ Style/Documentation:
Style/MethodCallWithArgsParentheses:
Enabled: true
EnforcedStyle: require_parentheses
Exclude:
- "spec/**/*"
AllowParenthesesInMultilineCall: true
AllowedMethods:
- 'attr_accessor'
- 'attr_reader'
- 'command'
- 'desc'
- 'gem'
- 'lane'
- 'platform'
- 'program'
- 'raise'
- 'require_relative'
- 'require'
# rspec tests code below
- 'after'
- 'be'
- 'before'
- 'context'
- 'describe'
- 'it'
- 'not_to'
- 'to'

RSpec/NamedSubject:
Enabled: true
EnforcedStyle: named_only

RSpec/ExampleLength:
Enabled: false

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

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

# It catches the false positive of `set_up_`, which is the right spelling for the method's name, so we disable it.
Naming/AccessorMethodName:
Enabled: false

# 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).
Layout/MultilineMethodCallIndentation:
Enabled: true
EnforcedStyle: indented

# Disallow multiple spaces that aim to align code.
Layout/ExtraSpacing:
Enabled: true
AllowForAlignment: false

RSpec/NestedGroups:
Enabled: true
Max: 4

Style/ClassVars:
Enabled: true
Exclude:
- "lib/vin/request.rb"
- "lib/vin/request.rb"
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

source "https://rubygems.org"

gemspec
Expand Down
104 changes: 51 additions & 53 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,73 @@ PATH
GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
base64 (0.1.1)
ast (2.4.3)
coderay (1.1.3)
connection_pool (2.4.1)
diff-lcs (1.5.0)
docile (1.4.0)
dotenv (2.8.1)
json (2.6.3)
language_server-protocol (3.17.0.3)
method_source (1.0.0)
parallel (1.23.0)
parser (3.2.2.3)
connection_pool (2.5.3)
diff-lcs (1.6.2)
docile (1.4.1)
dotenv (3.1.8)
json (2.13.2)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
method_source (1.1.0)
parallel (1.27.0)
parser (3.3.9.0)
ast (~> 2.4.1)
racc
pastel (0.8.0)
tty-color (~> 0.5)
pry (0.14.2)
prism (1.4.0)
pry (0.15.2)
coderay (~> 1.1)
method_source (~> 1.0)
racc (1.7.1)
racc (1.8.1)
rainbow (3.1.1)
rake (13.0.6)
redis (5.0.7)
redis-client (>= 0.9.0)
redis-client (0.17.0)
rake (13.3.0)
redis (5.4.1)
redis-client (>= 0.22.0)
redis-client (0.25.2)
connection_pool
regexp_parser (2.8.1)
rexml (3.2.6)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
regexp_parser (2.11.2)
rspec (3.13.1)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.5)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
rubocop (1.56.3)
base64 (~> 0.1.1)
rspec-support (~> 3.13.0)
rspec-support (3.13.5)
rubocop (1.79.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.2.2.3)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.46.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.19.0)
rubocop (~> 1.41)
rubocop-factory_bot (2.24.0)
rubocop (~> 1.33)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.24.1)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.46.0)
parser (>= 3.3.7.2)
prism (~> 1.4)
rubocop-rake (0.7.1)
lint_roller (~> 1.1)
rubocop (>= 1.72.1)
rubocop-rspec (3.6.0)
lint_roller (~> 1.1)
rubocop (~> 1.72, >= 1.72.1)
ruby-progressbar (1.13.0)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov-html (0.13.2)
simplecov_json_formatter (0.1.4)
tty-color (0.6.0)
tty-cursor (0.7.1)
Expand All @@ -88,8 +84,10 @@ GEM
tty-cursor (~> 0.7)
tty-screen (~> 0.8)
wisper (~> 2.0)
tty-screen (0.8.1)
unicode-display_width (2.4.2)
tty-screen (0.8.2)
unicode-display_width (3.1.5)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
wisper (2.0.1)

PLATFORMS
Expand Down
2 changes: 0 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "tty-prompt"
Expand Down
4 changes: 1 addition & 3 deletions hoov_vin.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Expand All @@ -16,7 +14,7 @@ Gem::Specification.new do |s|
s.email = "roger@hoov.com.br"
s.homepage = "https://github.com/hoovbr/vin"
s.license = "MIT"
s.required_ruby_version = ">= 3.1"
s.required_ruby_version = ">= 3.2"
s.metadata["homepage_uri"] = s.homepage
s.metadata["source_code_uri"] = "https://github.com/hoovbr/vin"
s.metadata["changelog_uri"] = "https://github.com/hoovbr/vin/blob/main/CHANGELOG.md"
Expand Down
10 changes: 4 additions & 6 deletions lib/vin.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

require "redis"
require "vin/mixins/redis"

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

def generate_id(data_type)
generator.generate_ids(data_type, 1).first
def generate_id(data_type, timestamp: nil)
generator.generate_ids(data_type, 1, timestamp: timestamp).first
end

def generate_ids(data_type, count)
def generate_ids(data_type, count, timestamp: nil)
ids = []
# The Lua script can't always return as many IDs as you may want. So we loop
# until we have the exact amount.
while ids.length < count
initial_id_count = ids.length
ids += generator.generate_ids(data_type, count - ids.length)
ids += generator.generate_ids(data_type, count - ids.length, timestamp: timestamp)
# Ensure the ids array keeps growing as infinite loop insurance
return ids unless ids.length > initial_id_count
end
Expand Down
4 changes: 2 additions & 2 deletions lib/vin/config.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

class VIN
class Config
# Expressed in milliseconds.
Expand Down Expand Up @@ -85,9 +83,11 @@ def fetch_allowed_range!
ENV.fetch("VIN_LOGICAL_SHARD_ID_RANGE_MIN", 0).to_i,
ENV.fetch("VIN_LOGICAL_SHARD_ID_RANGE_MAX", 0).to_i,
)
# rubocop:disable Style/BitwisePredicate
unless (logical_shard_id_allowed_range.to_a & range.to_a) == range.to_a
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.")
end
# rubocop:enable Style/BitwisePredicate
range
end
end
Expand Down
Loading
Loading