active_median 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38d8e44bc15d376d41dcbd21e10e48a5d64b93894120321d1a84580458a28532
4
- data.tar.gz: 2869dbc3182b206b18b0e83649ec851aed9c2b846995b462ca6166db0bfd65b2
3
+ metadata.gz: 2fde94235a65aa88d7417686a9ac804ca31bf48cb631ce6fa1f33f82f182f683
4
+ data.tar.gz: bca00d9fa0e7be65745217fc1c0934de095238302eaff1ce687fd47da73ad4aa
5
5
  SHA512:
6
- metadata.gz: 5a571e7dee0f23a1a13767763ed192ca3f9b3db1e66d4fa963c609c6a9c9f613701198901ba8960aae5ceddecad6b862ef84cde3fe19b271fdb669d9dc53dba5
7
- data.tar.gz: 0fe523c846b32a5ec8e3463c901a229cb7d00ba00cd86f7fd922d249d774c728324b4acd848b1ad06ec4120e748b9696dfe90f38ce4e4dcc7df62239c1406d58
6
+ metadata.gz: 4ff7c51cd683245dd808ee4ee314e20b100b944201c623bb2bb05ab490d5b90b5331de797062f152b77cffc1adfa94796a8f21558d3223b375fa4af050ac0a0f
7
+ data.tar.gz: 841082d44d97415a8a7c56893d286399c95fa8e601deafb26f60f97c1ad10c9f64c8199b1bc172557429738348ae99021eee742924d00797615beb9155f0e69f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.5.0 (2024-10-07)
2
+
3
+ - Fixed connection leasing for Active Record 7.2+
4
+ - Dropped support for Ruby < 3.1 and Active Record < 7
5
+
1
6
  ## 0.4.1 (2023-09-20)
2
7
 
3
8
  - Added support for Trilogy
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:
@@ -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.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-09-20 00:00:00.000000000 Z
11
+ date: 2024-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '6.1'
19
+ version: '7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '6.1'
26
+ version: '7'
27
27
  description:
28
28
  email: andrew@ankane.org
29
29
  executables: []
@@ -51,14 +51,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '3'
54
+ version: '3.1'
55
55
  required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
59
  version: '0'
60
60
  requirements: []
61
- rubygems_version: 3.4.10
61
+ rubygems_version: 3.5.16
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: Median and percentile for Active Record, Mongoid, arrays, and hashes