active_median 0.3.3 → 0.4.1

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: 8fac5b8a4669bedd7b9a7bd104c375df5acf6c9e60bc2c91ec97efb2ebea6969
4
- data.tar.gz: afc2609d7983f06b975244e57ab4f6890916fdc3943870974a56d50cca19a832
3
+ metadata.gz: 38d8e44bc15d376d41dcbd21e10e48a5d64b93894120321d1a84580458a28532
4
+ data.tar.gz: 2869dbc3182b206b18b0e83649ec851aed9c2b846995b462ca6166db0bfd65b2
5
5
  SHA512:
6
- metadata.gz: f3cff2041e5d602bd84f99f99cd75efbe6fba5c78faf4efbd6b3886edb91bf1db7deeca609ded57a859f10e670298f04a225f3f1b69ea8b4df9aecda68661b5e
7
- data.tar.gz: d494fddff7e01063c99d549d4669f6efff207fef25f71761329d3c16166bc6a268f02020e12adde251be855ed0c31998f47fb73890689565bb67a0c320875b06
6
+ metadata.gz: 5a571e7dee0f23a1a13767763ed192ca3f9b3db1e66d4fa963c609c6a9c9f613701198901ba8960aae5ceddecad6b862ef84cde3fe19b271fdb669d9dc53dba5
7
+ data.tar.gz: 0fe523c846b32a5ec8e3463c901a229cb7d00ba00cd86f7fd922d249d774c728324b4acd848b1ad06ec4120e748b9696dfe90f38ce4e4dcc7df62239c1406d58
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 0.4.1 (2023-09-20)
2
+
3
+ - Added support for Trilogy
4
+
5
+ ## 0.4.0 (2023-05-25)
6
+
7
+ - Fixed error with Active Record 7.0.5
8
+ - Raise `ArgumentError` for invalid percentiles
9
+ - Dropped support for Ruby < 3 and Active Record < 6.1
10
+
1
11
  ## 0.3.3 (2021-08-17)
2
12
 
3
13
  - Fixed null values for SQLite without an extension and MongoDB
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2021 Andrew Kane
1
+ Copyright (c) 2013-2023 Andrew Kane
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -20,7 +20,7 @@ Supports:
20
20
  Add this line to your application’s Gemfile:
21
21
 
22
22
  ```ruby
23
- gem 'active_median'
23
+ gem "active_median"
24
24
  ```
25
25
 
26
26
  For MySQL, also follow [these instructions](#additional-instructions).
@@ -105,18 +105,6 @@ db.load_extension("percentile.so") # or percentile.dylib
105
105
  db.enable_load_extension(0)
106
106
  ```
107
107
 
108
- ## Upgrading
109
-
110
- ### 0.3.0
111
-
112
- ActiveMedian 0.3.0 protects against unsafe input by default. For non-attribute arguments, use:
113
-
114
- ```ruby
115
- Item.median(Arel.sql(known_safe_value))
116
- ```
117
-
118
- Also, percentiles are now supported with SQLite. Use the [percentile extension](#sqlite) instead of `extension-functions`.
119
-
120
108
  ## Contributing
121
109
 
122
110
  Everyone is encouraged to help improve this project. Here are a few ways you can help:
@@ -126,12 +114,29 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
126
114
  - Write, clarify, or fix documentation
127
115
  - Suggest or add new features
128
116
 
129
- To get started with development and testing:
117
+ To get started with development:
130
118
 
131
119
  ```sh
132
120
  git clone https://github.com/ankane/active_median.git
133
121
  cd active_median
134
- createdb active_median_test
135
122
  bundle install
123
+
124
+ # Postgres
125
+ createdb active_median_test
136
126
  bundle exec rake test
127
+
128
+ # SQLite
129
+ ADAPTER=sqlite3 BUNDLE_GEMFILE=gemfiles/sqlite3.gemfile bundle exec rake test
130
+
131
+ # MariaDB and MySQL (for MySQL, install the extension first)
132
+ mysqladmin create active_median_test
133
+ ADAPTER=mysql2 BUNDLE_GEMFILE=gemfiles/mysql2.gemfile bundle exec rake test
134
+
135
+ # SQL Server
136
+ 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"
138
+ ADAPTER=sqlserver BUNDLE_GEMFILE=gemfiles/sqlserver.gemfile bundle exec rake test
139
+
140
+ # MongoDB
141
+ BUNDLE_GEMFILE=gemfiles/mongoid7.gemfile bundle exec rake test
137
142
  ```
@@ -11,7 +11,8 @@ module ActiveMedian
11
11
  private
12
12
 
13
13
  def calculate_percentile(column, percentile, operation)
14
- percentile = percentile.to_f
14
+ percentile = Float(percentile, exception: false)
15
+ raise ArgumentError, "invalid percentile" if percentile.nil?
15
16
  raise ArgumentError, "percentile is not between 0 and 1" if percentile < 0 || percentile > 1
16
17
 
17
18
  # basic version of Active Record disallow_raw_sql!
@@ -24,7 +25,13 @@ module ActiveMedian
24
25
  end
25
26
  end
26
27
 
27
- column_alias = relation.send(:column_alias_for, "#{operation} #{column.to_s.downcase}")
28
+ column_alias =
29
+ if relation.respond_to?(:column_alias_for, true)
30
+ relation.send(:column_alias_for, "#{operation} #{column.to_s.downcase}")
31
+ else
32
+ # Active Record 7.0.5+
33
+ ActiveRecord::Calculations::ColumnAliasTracker.new(connection).alias_for("#{operation} #{column.to_s.downcase}")
34
+ end
28
35
  # safety check
29
36
  # could quote, but want to keep consistent with Active Record
30
37
  raise "Bad column alias: #{column_alias}. Please report a bug." unless column_alias =~ /\A[a-z0-9_]+\z/
@@ -44,7 +51,7 @@ module ActiveMedian
44
51
 
45
52
  relation =
46
53
  case connection.adapter_name
47
- when /mysql/i
54
+ when /mysql/i, /trilogy/i
48
55
  # assume mariadb by default
49
56
  # use send as this method is private in Rails 4.2
50
57
  mariadb = connection.send(:mariadb?) rescue true
@@ -6,7 +6,8 @@ module ActiveMedian
6
6
 
7
7
  # https://www.compose.com/articles/mongo-metrics-finding-a-happy-median/
8
8
  def percentile(column, percentile)
9
- percentile = percentile.to_f
9
+ percentile = Float(percentile, exception: false)
10
+ raise ArgumentError, "invalid percentile" if percentile.nil?
10
11
  raise ArgumentError, "percentile is not between 0 and 1" if percentile < 0 || percentile > 1
11
12
 
12
13
  relation =
@@ -1,3 +1,3 @@
1
1
  module ActiveMedian
2
- VERSION = "0.3.3"
2
+ VERSION = "0.4.1"
3
3
  end
data/lib/active_median.rb CHANGED
@@ -1,25 +1,16 @@
1
+ # dependencies
1
2
  require "active_support"
2
3
 
3
- require "active_median/enumerable"
4
- require "active_median/version"
5
-
6
- module ActiveMedian
7
- # TODO remove in 0.4.0
8
- def self.drop_function
9
- ActiveRecord::Base.connection.execute <<-SQL
10
- DROP AGGREGATE IF EXISTS median(anyelement);
11
- DROP FUNCTION IF EXISTS median(anyarray);
12
- SQL
13
- true
14
- end
15
- end
4
+ # modules
5
+ require_relative "active_median/enumerable"
6
+ require_relative "active_median/version"
16
7
 
17
8
  ActiveSupport.on_load(:active_record) do
18
- require "active_median/model"
9
+ require_relative "active_median/model"
19
10
  extend(ActiveMedian::Model)
20
11
  end
21
12
 
22
13
  ActiveSupport.on_load(:mongoid) do
23
- require "active_median/mongoid"
14
+ require_relative "active_median/mongoid"
24
15
  Mongoid::Document::ClassMethods.include(ActiveMedian::Mongoid)
25
16
  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.3.3
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-17 00:00:00.000000000 Z
11
+ date: 2023-09-20 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: '5.2'
19
+ version: '6.1'
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: '5.2'
26
+ version: '6.1'
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: '2.6'
54
+ version: '3'
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.2.22
61
+ rubygems_version: 3.4.10
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: Median and percentile for Active Record, Mongoid, arrays, and hashes