random-rails 1.0.1 → 1.0.3

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: 742b88b0a7c5aade166e3bb2d4729fc094955432503683d57aa102a16887cdd9
4
- data.tar.gz: fa97f1b124d647cb874c41f2ffa6f1f3188d817f6e093bc1f081eddc8c646c29
3
+ metadata.gz: bb6231f4307cc09e1807ac95198a0c16ea186cd1b82386b572fb3e6d6e8d6a80
4
+ data.tar.gz: da296f310d4bbcb76f141d2e2641aeb9227e2a566f66245a3fecc7a419f6e055
5
5
  SHA512:
6
- metadata.gz: 37c0f1ebecdde3365155e49d9e60cf5345a0c60880ede8e15de4bf64759e587240a5267cc4b3a1b941a3a7d8ef58a8bf095200a41ac9c5136ba4e2302d5ba16e
7
- data.tar.gz: 33238f0df65b20e6395205ee33834627f47b62f4022a5112a4d46f5cd964558d463a1c0535aa1068a095a2de2151733559a8f216e074b5b616bd3799c6d3e047
6
+ metadata.gz: fb108e18e97aefd8edceb1c8a012f7f9f1c1d92a467eb9e5428395c2ddc6842e5fd1e481e0ea224564946da5b877fc6b2a6e1db7ffdeb67e8ef8dd088ed14839
7
+ data.tar.gz: cb41d83806c9860331fe93afa5f885fe0967ac1f6560c4aeb8f0855c69183a703e9f04ec9e3c4232e0f83b37bae09340cbb48e5424e07ffec5c80cedb1d79007
data/.rubocop/rspec.yml CHANGED
@@ -44,9 +44,3 @@ RSpec/MissingExampleGroupArgument:
44
44
 
45
45
  RSpec/ReceiveCounts:
46
46
  Enabled: true
47
-
48
- FactoryBot/AttributeDefinedStatically:
49
- Enabled: true
50
-
51
- FactoryBot/CreateList:
52
- Enabled: true
data/CHANGELOG.md CHANGED
@@ -1,3 +1,56 @@
1
+ ## [1.0.3] - 2025-10-07
2
+
3
+ ### Maintenance Release - RuboCop & Dependency Updates
4
+
5
+ #### Fixed
6
+
7
+ - **RuboCop configuration**: Fixed configuration syntax by replacing `require:` with `plugins:` in RuboCop configuration files to follow the correct plugin loading mechanism
8
+ - **ActiveSupport loading**: Optimized ActiveSupport loading by using `lazy_load_hooks` instead of loading the entire core extensions
9
+
10
+ #### Changed
11
+
12
+ - **Dependency updates**:
13
+ - Updated RuboCop from ~> 1.52 to ~> 1.80
14
+ - Updated Standard from ~> 1.3 to ~> 1.51
15
+ - Updated rubocop-rspec from ~> 2.22 to ~> 3.7
16
+ - Updated rubocop-performance to ~> 1.25.0
17
+ - Added mutex_m and bigdecimal as development dependencies
18
+
19
+ #### Technical Improvements
20
+
21
+ - Improved RuboCop plugin configuration for better linting
22
+ - More efficient ActiveSupport loading to reduce memory footprint
23
+ - Updated development tooling for better code quality enforcement
24
+
25
+ ## [1.0.2] - 2025-10-06
26
+
27
+ ### Maintenance Release - Code Quality & CI Improvements
28
+
29
+ #### Fixed
30
+
31
+ - **Floating-point precision bug**: Replaced direct float equality comparison (`precision == 1.0`) with epsilon-based comparison (`(precision - 1.0).abs < Float::EPSILON`) to avoid floating-point precision issues
32
+ - **Code formatting**: Improved code consistency and readability with proper parentheses around ternary operators and aligned variable assignments
33
+
34
+ #### Added
35
+
36
+ - **Enhanced test matrix**: Added Ruby 3.2.9, 3.3.9, and Rails 8.0.3 to CI test matrix for better compatibility testing
37
+ - **Improved .gitignore**: Added missing `*.gem` pattern to prevent accidental gem file commits
38
+
39
+ #### Changed
40
+
41
+ - **Code style improvements**:
42
+ - Added parentheses around ternary operator conditions for better readability
43
+ - Aligned variable assignments for consistent formatting
44
+ - Updated string quotations to use double quotes consistently in specs
45
+ - Removed unused `cache_key` variable
46
+ - Added missing blank lines for better code organization
47
+
48
+ #### Technical Improvements
49
+
50
+ - Better floating-point comparison to prevent precision-related bugs
51
+ - More robust code style following Ruby best practices
52
+ - Enhanced CI coverage with additional Ruby and Rails versions
53
+
1
54
  ## [1.0.1] - 2025-09-30
2
55
 
3
56
  ### Major Release - Multi-Database Support & Performance Optimizations
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- random-rails (1.0.1)
4
+ random-rails (1.0.3)
5
5
  activerecord (>= 4.0, < 8.1)
6
6
  activesupport (>= 6.1.5, < 8.1)
7
7
 
@@ -18,7 +18,8 @@ GEM
18
18
  i18n (>= 1.6, < 2)
19
19
  minitest (>= 5.1)
20
20
  tzinfo (~> 2.0)
21
- ast (2.4.2)
21
+ ast (2.4.3)
22
+ bigdecimal (3.2.3)
22
23
  coderay (1.1.3)
23
24
  concurrent-ruby (1.2.2)
24
25
  diff-lcs (1.5.0)
@@ -27,26 +28,28 @@ GEM
27
28
  i18n (>= 1.8.11, < 2)
28
29
  i18n (1.14.1)
29
30
  concurrent-ruby (~> 1.0)
30
- json (2.6.3)
31
- language_server-protocol (3.17.0.3)
31
+ json (2.15.0)
32
+ language_server-protocol (3.17.0.5)
32
33
  lint_roller (1.1.0)
33
34
  method_source (1.0.0)
34
35
  mini_portile2 (2.8.9)
35
36
  minitest (5.18.1)
37
+ mutex_m (0.3.0)
36
38
  mysql2 (0.5.5)
37
- parallel (1.23.0)
38
- parser (3.2.2.3)
39
+ parallel (1.27.0)
40
+ parser (3.3.9.0)
39
41
  ast (~> 2.4.1)
40
42
  racc
41
43
  pg (1.5.3)
44
+ prism (1.5.1)
42
45
  pry (0.14.2)
43
46
  coderay (~> 1.1)
44
47
  method_source (~> 1.0)
45
- racc (1.7.1)
48
+ racc (1.8.1)
46
49
  rainbow (3.1.1)
47
50
  rake (13.0.6)
48
- regexp_parser (2.8.1)
49
- rexml (3.2.5)
51
+ regexp_parser (2.11.3)
52
+ rexml (3.4.4)
50
53
  rspec (3.12.0)
51
54
  rspec-core (~> 3.12.0)
52
55
  rspec-expectations (~> 3.12.0)
@@ -60,29 +63,25 @@ GEM
60
63
  diff-lcs (>= 1.2.0, < 2.0)
61
64
  rspec-support (~> 3.12.0)
62
65
  rspec-support (3.12.1)
63
- rubocop (1.52.1)
66
+ rubocop (1.64.1)
64
67
  json (~> 2.3)
68
+ language_server-protocol (>= 3.17.0)
65
69
  parallel (~> 1.10)
66
- parser (>= 3.2.2.3)
70
+ parser (>= 3.3.0.2)
67
71
  rainbow (>= 2.2.2, < 4.0)
68
72
  regexp_parser (>= 1.8, < 3.0)
69
73
  rexml (>= 3.2.5, < 4.0)
70
- rubocop-ast (>= 1.28.0, < 2.0)
74
+ rubocop-ast (>= 1.31.1, < 2.0)
71
75
  ruby-progressbar (~> 1.7)
72
76
  unicode-display_width (>= 2.4.0, < 3.0)
73
- rubocop-ast (1.29.0)
74
- parser (>= 3.2.1.0)
75
- rubocop-capybara (2.18.0)
76
- rubocop (~> 1.41)
77
- rubocop-factory_bot (2.23.1)
78
- rubocop (~> 1.33)
79
- rubocop-performance (1.18.0)
80
- rubocop (>= 1.7.0, < 2.0)
81
- rubocop-ast (>= 0.4.0)
82
- rubocop-rspec (2.22.0)
83
- rubocop (~> 1.33)
84
- rubocop-capybara (~> 2.17)
85
- rubocop-factory_bot (~> 2.22)
77
+ rubocop-ast (1.47.1)
78
+ parser (>= 3.3.7.2)
79
+ prism (~> 1.4)
80
+ rubocop-performance (1.21.1)
81
+ rubocop (>= 1.48.1, < 2.0)
82
+ rubocop-ast (>= 1.31.1, < 2.0)
83
+ rubocop-rspec (3.0.0)
84
+ rubocop (~> 1.40)
86
85
  ruby-progressbar (1.13.0)
87
86
  simplecov (0.22.0)
88
87
  docile (~> 1.1)
@@ -92,21 +91,21 @@ GEM
92
91
  simplecov_json_formatter (0.1.4)
93
92
  sqlite3 (1.6.3)
94
93
  mini_portile2 (~> 2.8.0)
95
- standard (1.30.1)
94
+ standard (1.37.0)
96
95
  language_server-protocol (~> 3.17.0.2)
97
96
  lint_roller (~> 1.0)
98
- rubocop (~> 1.52.0)
97
+ rubocop (~> 1.64.0)
99
98
  standard-custom (~> 1.0.0)
100
- standard-performance (~> 1.1.0)
99
+ standard-performance (~> 1.4)
101
100
  standard-custom (1.0.2)
102
101
  lint_roller (~> 1.0)
103
102
  rubocop (~> 1.50)
104
- standard-performance (1.1.1)
103
+ standard-performance (1.4.0)
105
104
  lint_roller (~> 1.1)
106
- rubocop-performance (~> 1.18.0)
105
+ rubocop-performance (~> 1.21.0)
107
106
  tzinfo (2.0.6)
108
107
  concurrent-ruby (~> 1.0)
109
- unicode-display_width (2.4.2)
108
+ unicode-display_width (2.6.0)
110
109
 
111
110
  PLATFORMS
112
111
  arm64-darwin-21
@@ -114,19 +113,22 @@ PLATFORMS
114
113
  x86_64-linux
115
114
 
116
115
  DEPENDENCIES
116
+ bigdecimal
117
117
  faker (~> 3.2)
118
+ mutex_m
118
119
  mysql2 (~> 0.5.5)
119
120
  pg (~> 1.5)
120
121
  pry (~> 0.14.2)
121
122
  rake (~> 13.0)
122
123
  random-rails!
123
124
  rspec (~> 3.0)
124
- rubocop (~> 1.52)
125
- rubocop-performance (~> 1.18)
126
- rubocop-rspec (~> 2.22)
125
+ rubocop (~> 1.64.0)
126
+ rubocop-performance (~> 1.21.0)
127
+ rubocop-rspec (~> 3.0.0)
127
128
  simplecov (~> 0.22.0)
128
129
  sqlite3 (~> 1.6)
129
- standard (~> 1.3)
130
+ standard (~> 1.37.0)
131
+ standard-performance (~> 1.4.0)
130
132
 
131
133
  BUNDLED WITH
132
134
  2.4.13
data/README.md CHANGED
@@ -153,4 +153,4 @@ Everyone interacting in the ActiveRecord::Random project's codebases, issue trac
153
153
 
154
154
  ## Thanks for your support!
155
155
 
156
- [`<img width="100" alt="RailsJazz" src="https://avatars.githubusercontent.com/u/104008706?s=200">`](https://github.com/railsjazz)
156
+ [<img width="100" alt="RailsJazz" src="https://avatars.githubusercontent.com/u/104008706?s=200">](https://github.com/railsjazz)
@@ -1,5 +1,4 @@
1
- require "active_support"
2
- require "active_support/core_ext"
1
+ require "active_support/lazy_load_hooks"
3
2
 
4
3
  require "random-rails/adapters/active_record/base"
5
4
 
@@ -24,7 +24,7 @@ module RandomRails
24
24
  end
25
25
 
26
26
  # Return single object for count=1, relation for count>1
27
- count == 1 ? relation.take : relation
27
+ (count == 1) ? relation.take : relation
28
28
  end
29
29
 
30
30
  private
@@ -45,7 +45,7 @@ module RandomRails
45
45
  # PostgreSQL supports TABLESAMPLE for large tables, offset for smaller ones
46
46
  estimated_count = estimate_table_size
47
47
 
48
- estimated_count > RandomRails.configuration.tablesample_threshold ? :tablesample : :offset
48
+ (estimated_count > RandomRails.configuration.tablesample_threshold) ? :tablesample : :offset
49
49
  when "mysql", "mysql2"
50
50
  # MySQL doesn't have TABLESAMPLE, use offset method
51
51
  :offset
@@ -62,7 +62,8 @@ module RandomRails
62
62
  def tablesample_random(precision:, count:)
63
63
  if connection.adapter_name.downcase == "postgresql"
64
64
  # Use configured precision if not specified
65
- precision = RandomRails.configuration.precision if precision == 1.0
65
+ # using Float::EPSILON to avoid floating point precision issues
66
+ precision = RandomRails.configuration.precision if (precision - 1.0).abs < Float::EPSILON
66
67
 
67
68
  from("#{table_name} TABLESAMPLE BERNOULLI(#{precision})").limit(count)
68
69
  else
@@ -78,8 +79,8 @@ module RandomRails
78
79
  return limit(count) if total_count == 0
79
80
 
80
81
  # Generate random offset, ensuring we always have an offset clause
81
- max_offset = [total_count - count, 0].max
82
- random_offset = max_offset > 0 ? rand(max_offset + 1) : 0
82
+ max_offset = [total_count - count, 0].max
83
+ random_offset = (max_offset > 0) ? rand(max_offset + 1) : 0
83
84
 
84
85
  # Always apply offset, even if it's 0, to ensure consistent SQL structure
85
86
  offset(random_offset).limit(count)
@@ -101,8 +102,6 @@ module RandomRails
101
102
 
102
103
  # Estimate table size efficiently
103
104
  def estimate_table_size
104
- cache_key = "#{table_name}_count_estimate"
105
-
106
105
  if RandomRails.configuration.cache_table_sizes && @estimated_count
107
106
  return @estimated_count
108
107
  end
@@ -111,13 +110,13 @@ module RandomRails
111
110
  case connection.adapter_name.downcase
112
111
  when "postgresql", "pg"
113
112
  # Use pg_class for fast estimate
114
- sql = "SELECT reltuples::INTEGER FROM pg_class WHERE relname = '#{table_name}'"
113
+ sql = "SELECT reltuples::INTEGER FROM pg_class WHERE relname = '#{table_name}'"
115
114
  result = connection.execute(sql).first
116
115
 
117
116
  result ? result["reltuples"].to_i : count
118
117
  when "mysql", "mysql2"
119
118
  # Use information_schema for fast estimate
120
- sql = "SELECT table_rows FROM information_schema.tables WHERE table_name = '#{table_name}'"
119
+ sql = "SELECT table_rows FROM information_schema.tables WHERE table_name = '#{table_name}'"
121
120
  result = connection.execute(sql).first
122
121
 
123
122
  result ? result[0].to_i : count
@@ -5,10 +5,10 @@ module RandomRails
5
5
  attr_accessor :default_strategy, :tablesample_threshold, :cache_table_sizes, :precision
6
6
 
7
7
  def initialize
8
- @default_strategy = :auto
8
+ @default_strategy = :auto
9
9
  @tablesample_threshold = 10_000 # Use TABLESAMPLE for tables larger than this
10
- @cache_table_sizes = true # Cache table size estimates
11
- @precision = 1.0 # Default precision for TABLESAMPLE
10
+ @cache_table_sizes = true # Cache table size estimates
11
+ @precision = 1.0 # Default precision for TABLESAMPLE
12
12
  end
13
13
  end
14
14
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RandomRails
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.3"
5
5
  end
data/random-rails.gemspec CHANGED
@@ -35,16 +35,19 @@ Gem::Specification.new do |spec|
35
35
  spec.add_runtime_dependency "activesupport", ">= 6.1.5", "< 8.1"
36
36
 
37
37
  spec.add_development_dependency "rspec", "~> 3.0"
38
- spec.add_development_dependency "rubocop-rspec", "~> 2.22"
39
- spec.add_development_dependency "standard", "~> 1.3"
40
- spec.add_development_dependency "rubocop", "~> 1.52"
41
- spec.add_development_dependency "rubocop-performance", "~> 1.18"
38
+ spec.add_development_dependency "rubocop-rspec", "~> 3.0.0"
39
+ spec.add_development_dependency "standard", "~> 1.37.0"
40
+ spec.add_development_dependency "rubocop", "~> 1.64.0"
41
+ spec.add_development_dependency "rubocop-performance", "~> 1.21.0"
42
+ spec.add_development_dependency "standard-performance", "~> 1.4.0"
42
43
  spec.add_development_dependency "simplecov", "~> 0.22.0"
43
44
  spec.add_development_dependency "pry", "~> 0.14.2"
44
45
  spec.add_development_dependency "sqlite3", "~> 1.6"
45
46
  spec.add_development_dependency "pg", "~> 1.5"
46
47
  spec.add_development_dependency "mysql2", "~> 0.5.5"
47
48
  spec.add_development_dependency "faker", "~> 3.2"
49
+ spec.add_development_dependency "mutex_m"
50
+ spec.add_development_dependency "bigdecimal"
48
51
 
49
52
  spec.post_install_message = <<~MSG
50
53
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: random-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - loqimean
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-10-06 00:00:00.000000000 Z
10
+ date: 2025-10-07 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activerecord
@@ -70,56 +69,70 @@ dependencies:
70
69
  requirements:
71
70
  - - "~>"
72
71
  - !ruby/object:Gem::Version
73
- version: '2.22'
72
+ version: 3.0.0
74
73
  type: :development
75
74
  prerelease: false
76
75
  version_requirements: !ruby/object:Gem::Requirement
77
76
  requirements:
78
77
  - - "~>"
79
78
  - !ruby/object:Gem::Version
80
- version: '2.22'
79
+ version: 3.0.0
81
80
  - !ruby/object:Gem::Dependency
82
81
  name: standard
83
82
  requirement: !ruby/object:Gem::Requirement
84
83
  requirements:
85
84
  - - "~>"
86
85
  - !ruby/object:Gem::Version
87
- version: '1.3'
86
+ version: 1.37.0
88
87
  type: :development
89
88
  prerelease: false
90
89
  version_requirements: !ruby/object:Gem::Requirement
91
90
  requirements:
92
91
  - - "~>"
93
92
  - !ruby/object:Gem::Version
94
- version: '1.3'
93
+ version: 1.37.0
95
94
  - !ruby/object:Gem::Dependency
96
95
  name: rubocop
97
96
  requirement: !ruby/object:Gem::Requirement
98
97
  requirements:
99
98
  - - "~>"
100
99
  - !ruby/object:Gem::Version
101
- version: '1.52'
100
+ version: 1.64.0
102
101
  type: :development
103
102
  prerelease: false
104
103
  version_requirements: !ruby/object:Gem::Requirement
105
104
  requirements:
106
105
  - - "~>"
107
106
  - !ruby/object:Gem::Version
108
- version: '1.52'
107
+ version: 1.64.0
109
108
  - !ruby/object:Gem::Dependency
110
109
  name: rubocop-performance
111
110
  requirement: !ruby/object:Gem::Requirement
112
111
  requirements:
113
112
  - - "~>"
114
113
  - !ruby/object:Gem::Version
115
- version: '1.18'
114
+ version: 1.21.0
116
115
  type: :development
117
116
  prerelease: false
118
117
  version_requirements: !ruby/object:Gem::Requirement
119
118
  requirements:
120
119
  - - "~>"
121
120
  - !ruby/object:Gem::Version
122
- version: '1.18'
121
+ version: 1.21.0
122
+ - !ruby/object:Gem::Dependency
123
+ name: standard-performance
124
+ requirement: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - "~>"
127
+ - !ruby/object:Gem::Version
128
+ version: 1.4.0
129
+ type: :development
130
+ prerelease: false
131
+ version_requirements: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - "~>"
134
+ - !ruby/object:Gem::Version
135
+ version: 1.4.0
123
136
  - !ruby/object:Gem::Dependency
124
137
  name: simplecov
125
138
  requirement: !ruby/object:Gem::Requirement
@@ -204,6 +217,34 @@ dependencies:
204
217
  - - "~>"
205
218
  - !ruby/object:Gem::Version
206
219
  version: '3.2'
220
+ - !ruby/object:Gem::Dependency
221
+ name: mutex_m
222
+ requirement: !ruby/object:Gem::Requirement
223
+ requirements:
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ version: '0'
227
+ type: :development
228
+ prerelease: false
229
+ version_requirements: !ruby/object:Gem::Requirement
230
+ requirements:
231
+ - - ">="
232
+ - !ruby/object:Gem::Version
233
+ version: '0'
234
+ - !ruby/object:Gem::Dependency
235
+ name: bigdecimal
236
+ requirement: !ruby/object:Gem::Requirement
237
+ requirements:
238
+ - - ">="
239
+ - !ruby/object:Gem::Version
240
+ version: '0'
241
+ type: :development
242
+ prerelease: false
243
+ version_requirements: !ruby/object:Gem::Requirement
244
+ requirements:
245
+ - - ">="
246
+ - !ruby/object:Gem::Version
247
+ version: '0'
207
248
  description: The easiest way to get random records from database with best performance
208
249
  that you ever seen.
209
250
  email:
@@ -263,8 +304,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
263
304
  - !ruby/object:Gem::Version
264
305
  version: '0'
265
306
  requirements: []
266
- rubygems_version: 3.5.16
267
- signing_key:
307
+ rubygems_version: 3.6.2
268
308
  specification_version: 4
269
309
  summary: Awesome gem to get random records from database.
270
310
  test_files: []