groupdate 6.5.0 → 6.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: 1ef9a0ee3177e94a0e797036221d6e33b124e41f7f867fe8b0904a24bd7cf741
4
- data.tar.gz: 73ef98496e157ba77bc8afb226c625dc9f117347b676eb39d767f4d55023309a
3
+ metadata.gz: e81c8d8bce77a4b40a6e612c9dac7017561e3083cbe3f232ca7326d4cbc45941
4
+ data.tar.gz: 993879fa7e1fd657e3362dd2e8edcda080c5c808cb5265ae9e14f46d5704a870
5
5
  SHA512:
6
- metadata.gz: b38cacba795f7f0e0430fa1c1935b5e2aa6556926b70533966e912f5a7110291bb2a5f6542c37c6fd7bb996cf973db5241eb7299a8c664e327026fb702cf191a
7
- data.tar.gz: 393f55d1892c6b65cbe51608aaee4f7e1f2a06067637196a1d6ed82e69434ebb10169553308f21cb8738d06513e19eb505657ccea8d47544da85ca3c77eff02d
6
+ metadata.gz: 867a01e2efd77e36617edcc345a1503194a32518115afcd6f952f0eecf1fb03a26c1e4abbbb8acf82255db650408403c4c6744008e17d0c6355375a37b4cc10f
7
+ data.tar.gz: d28f72bb69616b0389107d902758b41e1268c5785edb442406f9b213e8a1790185f3b61e91c7496edd992a6599b7bfd967721d861be79d78d3e28c3753b15cac
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 6.6.0 (2025-05-04)
2
+
3
+ - Dropped support for Ruby < 3.2 and Active Record < 7.1
4
+
5
+ ## 6.5.1 (2024-10-07)
6
+
7
+ - Fixed connection leasing for Active Record 7.2+
8
+
1
9
  ## 6.5.0 (2024-10-01)
2
10
 
3
11
  - Added support for Active Record 8
@@ -268,3 +276,44 @@ Breaking changes
268
276
  ## 1.0.0 (2013-05-15)
269
277
 
270
278
  - First major release
279
+
280
+ ## 0.1.6 (2013-05-07)
281
+
282
+ - Fixed error with Ruby 1.8
283
+
284
+ ## 0.1.5 (2013-05-01)
285
+
286
+ - Added support for getting the entire series
287
+
288
+ ## 0.1.4 (2013-05-01)
289
+
290
+ - Added support for Ruby 1.8
291
+
292
+ ## 0.1.3 (2013-04-25)
293
+
294
+ - Improved field names for ordering
295
+
296
+ ## 0.1.2 (2013-04-24)
297
+
298
+ - Added ability to order easily
299
+
300
+ ## 0.1.1 (2013-04-21)
301
+
302
+ - Improved return types for MySQL
303
+
304
+ ## 0.1.0 (2013-04-21)
305
+
306
+ - Added `day_of_week`
307
+ - Added `hour_of_day`
308
+
309
+ ## 0.0.3 (2013-04-18)
310
+
311
+ - Added support for Rails time zone strings
312
+
313
+ ## 0.0.2 (2013-04-18)
314
+
315
+ - Added tests
316
+
317
+ ## 0.0.1 (2013-04-17)
318
+
319
+ - First release
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2024 Andrew Kane
1
+ Copyright (c) 2013-2025 Andrew Kane
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -11,7 +11,7 @@ The simplest way to group by:
11
11
 
12
12
  :cake: Get the entire series - **the other best part**
13
13
 
14
- Supports PostgreSQL, MySQL, and Redshift, plus arrays and hashes (and limited support for [SQLite](#for-sqlite))
14
+ Supports PostgreSQL, MySQL, MariaDB, and Redshift, plus arrays and hashes (and limited support for [SQLite](#for-sqlite))
15
15
 
16
16
  :cupid: Goes hand in hand with [Chartkick](https://www.chartkick.com)
17
17
 
@@ -25,16 +25,16 @@ Add this line to your application’s Gemfile:
25
25
  gem "groupdate"
26
26
  ```
27
27
 
28
- For MySQL and SQLite, also follow [these instructions](#additional-instructions).
28
+ For MySQL, MariaDB, and SQLite, also follow [these instructions](#additional-instructions).
29
29
 
30
30
  ## Getting Started
31
31
 
32
32
  ```ruby
33
33
  User.group_by_day(:created_at).count
34
34
  # {
35
- # Sat, 24 May 2020 => 50,
36
- # Sun, 25 May 2020 => 100,
37
- # Mon, 26 May 2020 => 34
35
+ # Wed, 01 Jan 2025 => 50,
36
+ # Thu, 02 Jan 2025 => 100,
37
+ # Fri, 03 Jan 2025 => 34
38
38
  # }
39
39
  ```
40
40
 
@@ -75,9 +75,9 @@ or
75
75
  ```ruby
76
76
  User.group_by_week(:created_at, time_zone: "Pacific Time (US & Canada)").count
77
77
  # {
78
- # Sun, 08 Mar 2020 => 70,
79
- # Sun, 15 Mar 2020 => 54,
80
- # Sun, 22 Mar 2020 => 80
78
+ # Sun, 05 Jan 2025 => 70,
79
+ # Sun, 12 Jan 2025 => 54,
80
+ # Sun, 19 Jan 2025 => 80
81
81
  # }
82
82
  ```
83
83
 
@@ -154,8 +154,8 @@ To get keys in a different format, use:
154
154
  ```ruby
155
155
  User.group_by_month(:created_at, format: "%b %Y").count
156
156
  # {
157
- # "Jan 2020" => 10
158
- # "Feb 2020" => 12
157
+ # "Jan 2025" => 10
158
+ # "Feb 2025" => 12
159
159
  # }
160
160
  ```
161
161
 
@@ -250,7 +250,9 @@ users.group_by_day { |u| u.created_at }.to_h { |k, v| [k, v.count] }
250
250
 
251
251
  ## Additional Instructions
252
252
 
253
- ### For MySQL
253
+ <a name="for-mysql"></a>
254
+
255
+ ### For MySQL and MariaDB
254
256
 
255
257
  [Time zone support](https://dev.mysql.com/doc/refman/8.0/en/time-zone-support.html) must be installed on the server.
256
258
 
@@ -3,7 +3,7 @@ module Groupdate
3
3
  class BaseAdapter
4
4
  attr_reader :period, :column, :day_start, :week_start, :n_seconds
5
5
 
6
- def initialize(relation, column:, period:, time_zone:, time_range:, week_start:, day_start:, n_seconds:)
6
+ def initialize(relation, column:, period:, time_zone:, time_range:, week_start:, day_start:, n_seconds:, adapter_name: nil)
7
7
  @relation = relation
8
8
  @column = column
9
9
  @period = period
@@ -12,15 +12,10 @@ module Groupdate
12
12
  @week_start = week_start
13
13
  @day_start = day_start
14
14
  @n_seconds = n_seconds
15
+ @adapter_name = adapter_name
15
16
 
16
- if ActiveRecord::VERSION::MAJOR >= 7
17
- if ActiveRecord.default_timezone == :local
18
- raise Groupdate::Error, "ActiveRecord.default_timezone must be :utc to use Groupdate"
19
- end
20
- else
21
- if relation.default_timezone == :local
22
- raise Groupdate::Error, "ActiveRecord::Base.default_timezone must be :utc to use Groupdate"
23
- end
17
+ if ActiveRecord.default_timezone == :local
18
+ raise Groupdate::Error, "ActiveRecord.default_timezone must be :utc to use Groupdate"
24
19
  end
25
20
  end
26
21
 
@@ -23,7 +23,7 @@ module Groupdate
23
23
  when :week
24
24
  ["(DATE_TRUNC('day', #{day_start_column} - INTERVAL '1 day' * ((? + EXTRACT(DOW FROM #{day_start_column})::integer) % 7)) + INTERVAL ?)::date", time_zone, day_start_interval, 13 - week_start, time_zone, day_start_interval, day_start_interval]
25
25
  when :custom
26
- if @relation.connection.adapter_name == "Redshift"
26
+ if @adapter_name == "Redshift"
27
27
  ["TIMESTAMP 'epoch' + (FLOOR(EXTRACT(EPOCH FROM #{column}::timestamp) / ?) * ?) * INTERVAL '1 second'", n_seconds, n_seconds]
28
28
  else
29
29
  ["TO_TIMESTAMP(FLOOR(EXTRACT(EPOCH FROM #{column}::timestamptz) / ?) * ?)", n_seconds, n_seconds]
@@ -180,12 +180,13 @@ module Groupdate
180
180
  end
181
181
 
182
182
  def time_zone_support?(relation)
183
- if relation.connection.adapter_name.match?(/mysql/i)
184
- # need to call klass for Rails < 5.2
185
- sql = relation.klass.send(:sanitize_sql_array, ["SELECT CONVERT_TZ(NOW(), '+00:00', ?)", time_zone.tzinfo.name])
186
- !relation.connection.select_all(sql).to_a.first.values.first.nil?
187
- else
188
- true
183
+ relation.connection_pool.with_connection do |connection|
184
+ if connection.adapter_name.match?(/mysql|trilogy/i)
185
+ sql = relation.send(:sanitize_sql_array, ["SELECT CONVERT_TZ(NOW(), '+00:00', ?)", time_zone.tzinfo.name])
186
+ !connection.select_all(sql).to_a.first.values.first.nil?
187
+ else
188
+ true
189
+ end
189
190
  end
190
191
  end
191
192
 
@@ -203,7 +204,7 @@ module Groupdate
203
204
  def self.generate_relation(relation, field:, **options)
204
205
  magic = Groupdate::Magic::Relation.new(**options)
205
206
 
206
- adapter_name = relation.connection.adapter_name
207
+ adapter_name = relation.connection_pool.with_connection { |c| c.adapter_name }
207
208
  adapter = Groupdate.adapters[adapter_name]
208
209
  raise Groupdate::Error, "Connection adapter not supported: #{adapter_name}" unless adapter
209
210
 
@@ -221,7 +222,8 @@ module Groupdate
221
222
  time_range: magic.time_range,
222
223
  week_start: magic.week_start,
223
224
  day_start: magic.day_start,
224
- n_seconds: magic.n_seconds
225
+ n_seconds: magic.n_seconds,
226
+ adapter_name: adapter_name
225
227
  ).generate
226
228
 
227
229
  # add Groupdate info
@@ -251,7 +253,7 @@ module Groupdate
251
253
  def resolve_column(relation, column)
252
254
  node = relation.send(:relation).send(:arel_columns, [column]).first
253
255
  node = Arel::Nodes::SqlLiteral.new(node) if node.is_a?(String)
254
- relation.connection.visitor.accept(node, Arel::Collectors::SQLString.new).value
256
+ relation.connection_pool.with_connection { |c| c.visitor.accept(node, Arel::Collectors::SQLString.new).value }
255
257
  end
256
258
  end
257
259
 
@@ -1,3 +1,3 @@
1
1
  module Groupdate
2
- VERSION = "6.5.0"
2
+ VERSION = "6.6.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groupdate
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.5.0
4
+ version: 6.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: 2024-10-01 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: '7'
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: '7'
27
- description:
25
+ version: '7.1'
28
26
  email: andrew@ankane.org
29
27
  executables: []
30
28
  extensions: []
@@ -50,7 +48,6 @@ homepage: https://github.com/ankane/groupdate
50
48
  licenses:
51
49
  - MIT
52
50
  metadata: {}
53
- post_install_message:
54
51
  rdoc_options: []
55
52
  require_paths:
56
53
  - lib
@@ -58,15 +55,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
55
  requirements:
59
56
  - - ">="
60
57
  - !ruby/object:Gem::Version
61
- version: '3.1'
58
+ version: '3.2'
62
59
  required_rubygems_version: !ruby/object:Gem::Requirement
63
60
  requirements:
64
61
  - - ">="
65
62
  - !ruby/object:Gem::Version
66
63
  version: '0'
67
64
  requirements: []
68
- rubygems_version: 3.5.16
69
- signing_key:
65
+ rubygems_version: 3.6.7
70
66
  specification_version: 4
71
67
  summary: The simplest way to group temporal data
72
68
  test_files: []