calculate-all 0.3.0 → 0.3.1
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -0
- data/README.md +4 -4
- data/lib/calculate-all/version.rb +1 -1
- data/lib/calculate-all.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f15872602a35e41a3619150837e69840e82da1d2a42bd058a7c6986092024a97
|
4
|
+
data.tar.gz: f3665c7b64a083c5f24fd861e6ef22a5dde177e4a68eab9638449e26f89e2dc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d7ed4f530ff56be9378644b209add40b415bedf363425599a10a7d3fc14b1d0cb0920dd6744f5c334ae83f0ec9296b161d8bc387a2e4f93c1a849d7764e571a
|
7
|
+
data.tar.gz: 164b353805bf7fdd12e10087186c20a805231f68922c4d46a42e7c8f02307165d36592cbcf0c67d2a27f61e6dbb43c9cd7ab2934b9a64112ef239cf4e50edf05
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -78,7 +78,7 @@ or arbitrary symbols and keyword arguments with SQL snippets, aggregate function
|
|
78
78
|
)
|
79
79
|
```
|
80
80
|
|
81
|
-
For convenience, `calculate_all(:count, :avg_column)` is the same as `
|
81
|
+
For convenience, `calculate_all(:count, :avg_column)` is the same as `calculate_all(count: :count, avg_column: :avg_column)`
|
82
82
|
|
83
83
|
Here's a cheatsheet of recognized shortcuts:
|
84
84
|
|
@@ -139,7 +139,7 @@ with aggregate functions.
|
|
139
139
|
```ruby
|
140
140
|
Order.group(:payment_method).calculate_all('CAST(SUM(price) AS decimal) / COUNT(DISTINCT user_id)')
|
141
141
|
# => {
|
142
|
-
# "card" => 0.524e3
|
142
|
+
# "card" => 0.524e3,
|
143
143
|
# "cash" => 0.132e3
|
144
144
|
# }
|
145
145
|
```
|
@@ -186,7 +186,7 @@ Order.group_by_year(:created_at).calculate_all(*Stats.members, &Stats.method(:ne
|
|
186
186
|
# => {
|
187
187
|
# Wed, 01 Jan 2014 => #<data Stats count=2, max_price=700>,
|
188
188
|
# Thu, 01 Jan 2015 => #<data Stats count=0, max_price=nil>,
|
189
|
-
# Fri, 01 Jan 2016 => #<data Stats count=3,
|
189
|
+
# Fri, 01 Jan 2016 => #<data Stats count=3, max_price=800>
|
190
190
|
# }
|
191
191
|
```
|
192
192
|
|
@@ -227,7 +227,7 @@ Or install it yourself as:
|
|
227
227
|
|
228
228
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests.
|
229
229
|
Run `BUNDLE_GEMFILE=gemfiles/activerecord60.gemfile bundle` then `BUNDLE_GEMFILE=gemfiles/activerecord60.gemfile rake`
|
230
|
-
to test
|
230
|
+
to test against specific active record version.
|
231
231
|
|
232
232
|
To experiment you can load a test database and jump to IRB with
|
233
233
|
|
data/lib/calculate-all.rb
CHANGED
@@ -27,8 +27,8 @@ module CalculateAll
|
|
27
27
|
|
28
28
|
results = {}
|
29
29
|
pluck(*columns).each do |row|
|
30
|
-
# If pluck called with
|
31
|
-
# it will return an array of
|
30
|
+
# If pluck called with a single argument
|
31
|
+
# it will return an array of scalars instead of array of arrays
|
32
32
|
row = [row] if columns.size == 1
|
33
33
|
|
34
34
|
key = if group_values.size == 0
|
@@ -51,7 +51,7 @@ module CalculateAll
|
|
51
51
|
# Additional groupdate magic of filling empty periods with defaults
|
52
52
|
if defined?(Groupdate.process_result)
|
53
53
|
# Since that hash is the same instance for every backfilled row, at least
|
54
|
-
# freeze it to prevent
|
54
|
+
# freeze it to prevent surprise modifications across multiple rows in the calling code.
|
55
55
|
default_value = return_plain_values ? nil : {}.freeze
|
56
56
|
results = Groupdate.process_result(self, results, default_value: default_value)
|
57
57
|
end
|
@@ -97,7 +97,7 @@ module CalculateAll
|
|
97
97
|
when /^(\w+)_minimum$/, /^minimum_(\w+)$/
|
98
98
|
"MIN(#{$1})"
|
99
99
|
else
|
100
|
-
raise ArgumentError, "Can't recognize expression shortcut #{
|
100
|
+
raise ArgumentError, "Can't recognize expression shortcut #{shortcut}"
|
101
101
|
end
|
102
102
|
end
|
103
103
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: calculate-all
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Trofimenko
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-05-
|
10
|
+
date: 2025-05-19 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activesupport
|