active_median 0.4.1 → 0.6.0

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: 38d8e44bc15d376d41dcbd21e10e48a5d64b93894120321d1a84580458a28532
4
- data.tar.gz: 2869dbc3182b206b18b0e83649ec851aed9c2b846995b462ca6166db0bfd65b2
3
+ metadata.gz: 2f20b499191401477b52d09088bf8ce3483997442def2d070c595f38a1cf5d12
4
+ data.tar.gz: 501907135423ed1d3d2aa1e3d40edc4f8cc013eaaad36f210d12d0e003989ecf
5
5
  SHA512:
6
- metadata.gz: 5a571e7dee0f23a1a13767763ed192ca3f9b3db1e66d4fa963c609c6a9c9f613701198901ba8960aae5ceddecad6b862ef84cde3fe19b271fdb669d9dc53dba5
7
- data.tar.gz: 0fe523c846b32a5ec8e3463c901a229cb7d00ba00cd86f7fd922d249d774c728324b4acd848b1ad06ec4120e748b9696dfe90f38ce4e4dcc7df62239c1406d58
6
+ metadata.gz: '00592bcc97c6f70f85c2a1d6066fae1636af84e63a7e6113d73668c058a94c29b63c0cd334b6425c4b53d45efbff8de819530d0525d197f330b7225e6af5fe69'
7
+ data.tar.gz: ad385cad31559496b0049389a8bfc1145b32070d7f9b71dce00225f05b6d7881584ea8e6fa073675911fe2993d28feb240f3ffbca80b1a01f0f1cfad8fed0a3d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 0.6.0 (2025-05-04)
2
+
3
+ - Dropped support for Ruby < 3.2 and Active Record < 7.1
4
+ - Dropped support for Mongoid < 8
5
+
6
+ ## 0.5.0 (2024-10-07)
7
+
8
+ - Fixed connection leasing for Active Record 7.2+
9
+ - Dropped support for Ruby < 3.1 and Active Record < 7
10
+
1
11
  ## 0.4.1 (2023-09-20)
2
12
 
3
13
  - Added support for Trilogy
@@ -90,4 +100,8 @@ Breaking
90
100
 
91
101
  ## 0.1.0 (2014-03-13)
92
102
 
103
+ - Added support for Active Record 4
104
+
105
+ ## 0.0.1 (2013-08-03)
106
+
93
107
  - First release
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2023 Andrew Kane
1
+ Copyright (c) 2013-2025 Andrew Kane
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -13,7 +13,7 @@ Supports:
13
13
 
14
14
  :fire: Uses native functions for blazing performance
15
15
 
16
- [![Build Status](https://github.com/ankane/active_median/workflows/build/badge.svg?branch=master)](https://github.com/ankane/active_median/actions)
16
+ [![Build Status](https://github.com/ankane/active_median/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/active_median/actions)
17
17
 
18
18
  ## Getting Started
19
19
 
@@ -105,6 +105,10 @@ db.load_extension("percentile.so") # or percentile.dylib
105
105
  db.enable_load_extension(0)
106
106
  ```
107
107
 
108
+ ## History
109
+
110
+ View the [changelog](https://github.com/ankane/active_median/blob/master/CHANGELOG.md)
111
+
108
112
  ## Contributing
109
113
 
110
114
  Everyone is encouraged to help improve this project. Here are a few ways you can help:
@@ -134,7 +138,7 @@ ADAPTER=mysql2 BUNDLE_GEMFILE=gemfiles/mysql2.gemfile bundle exec rake test
134
138
 
135
139
  # SQL Server
136
140
  docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourStrong!Passw0rd' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2022-latest
137
- docker exec -it <container-id> /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P YourStrong\!Passw0rd -Q "CREATE DATABASE active_median_test"
141
+ docker exec -it <container-id> /opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P YourStrong\!Passw0rd -C -Q "CREATE DATABASE active_median_test"
138
142
  ADAPTER=sqlserver BUNDLE_GEMFILE=gemfiles/sqlserver.gemfile bundle exec rake test
139
143
 
140
144
  # MongoDB
@@ -2,7 +2,7 @@ module Enumerable
2
2
  unless method_defined?(:median)
3
3
  def median(*args, &block)
4
4
  if !block && respond_to?(:scoping)
5
- scoping { @klass.median(*args) }
5
+ scoping { klass.median(*args) }
6
6
  elsif !block && respond_to?(:with_scope)
7
7
  with_scope(self) { klass.median(*args) }
8
8
  else
@@ -15,7 +15,7 @@ module Enumerable
15
15
  unless method_defined?(:percentile)
16
16
  def percentile(*args, &block)
17
17
  if !block && respond_to?(:scoping)
18
- scoping { @klass.percentile(*args) }
18
+ scoping { klass.percentile(*args) }
19
19
  elsif !block && respond_to?(:with_scope)
20
20
  with_scope(self) { klass.percentile(*args) }
21
21
  else
@@ -1,16 +1,20 @@
1
1
  module ActiveMedian
2
2
  module Model
3
3
  def median(column)
4
- calculate_percentile(column, 0.5, "median")
4
+ connection_pool.with_connection do |connection|
5
+ calculate_percentile(column, 0.5, "median", connection)
6
+ end
5
7
  end
6
8
 
7
9
  def percentile(column, percentile)
8
- calculate_percentile(column, percentile, "percentile")
10
+ connection_pool.with_connection do |connection|
11
+ calculate_percentile(column, percentile, "percentile", connection)
12
+ end
9
13
  end
10
14
 
11
15
  private
12
16
 
13
- def calculate_percentile(column, percentile, operation)
17
+ def calculate_percentile(column, percentile, operation, connection)
14
18
  percentile = Float(percentile, exception: false)
15
19
  raise ArgumentError, "invalid percentile" if percentile.nil?
16
20
  raise ArgumentError, "percentile is not between 0 and 1" if percentile < 0 || percentile > 1
@@ -20,7 +24,7 @@ module ActiveMedian
20
24
  # matches table.column and column
21
25
  unless column.is_a?(Symbol) || column.is_a?(Arel::Nodes::SqlLiteral)
22
26
  column = column.to_s
23
- unless /\A\w+(\.\w+)?\z/i.match(column)
27
+ unless /\A\w+(\.\w+)?\z/i.match?(column)
24
28
  raise ActiveRecord::UnknownAttributeReference, "Query method called with non-attribute argument(s): #{column.inspect}. Use Arel.sql() for known-safe values."
25
29
  end
26
30
  end
@@ -34,12 +38,12 @@ module ActiveMedian
34
38
  end
35
39
  # safety check
36
40
  # could quote, but want to keep consistent with Active Record
37
- raise "Bad column alias: #{column_alias}. Please report a bug." unless column_alias =~ /\A[a-z0-9_]+\z/
41
+ raise "Bad column alias: #{column_alias}. Please report a bug." unless /\A[a-z0-9_]+\z/.match?(column_alias)
38
42
 
39
43
  # column resolution
40
44
  node = relation.send(:arel_columns, [column]).first
41
45
  node = Arel::Nodes::SqlLiteral.new(node) if node.is_a?(String)
42
- column = relation.connection.visitor.accept(node, Arel::Collectors::SQLString.new).value
46
+ column = connection.visitor.accept(node, Arel::Collectors::SQLString.new).value
43
47
 
44
48
  # prevent SQL injection
45
49
  percentile = connection.quote(percentile)
@@ -1,3 +1,3 @@
1
1
  module ActiveMedian
2
- VERSION = "0.4.1"
2
+ VERSION = "0.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_median
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-09-20 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -16,15 +15,14 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: '6.1'
18
+ version: '7.1'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
- version: '6.1'
27
- description:
25
+ version: '7.1'
28
26
  email: andrew@ankane.org
29
27
  executables: []
30
28
  extensions: []
@@ -43,7 +41,6 @@ homepage: https://github.com/ankane/active_median
43
41
  licenses:
44
42
  - MIT
45
43
  metadata: {}
46
- post_install_message:
47
44
  rdoc_options: []
48
45
  require_paths:
49
46
  - lib
@@ -51,15 +48,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
48
  requirements:
52
49
  - - ">="
53
50
  - !ruby/object:Gem::Version
54
- version: '3'
51
+ version: '3.2'
55
52
  required_rubygems_version: !ruby/object:Gem::Requirement
56
53
  requirements:
57
54
  - - ">="
58
55
  - !ruby/object:Gem::Version
59
56
  version: '0'
60
57
  requirements: []
61
- rubygems_version: 3.4.10
62
- signing_key:
58
+ rubygems_version: 3.6.7
63
59
  specification_version: 4
64
60
  summary: Median and percentile for Active Record, Mongoid, arrays, and hashes
65
61
  test_files: []