calculated_attributes 0.3.0 → 0.4.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
- SHA1:
3
- metadata.gz: 954ce2e582490fe3654d1d193bf8788b2a8e27df
4
- data.tar.gz: 3fba4d9c4d1c4efbf988c9280d6af0b8b2fc7905
2
+ SHA256:
3
+ metadata.gz: 75294a4fd8a1504df08bc397beaab706bb9095c6bd81ad96afac8e1dc0c69a12
4
+ data.tar.gz: 781fdbe8798f790f43e41872f92afe74601178f6b8c9648a9d8d7a0c27a1cccf
5
5
  SHA512:
6
- metadata.gz: 6128772777526edf97a6fa6633adc8a643770a2e129054cb4aa74890a1cae3429f41fb3cf7bfb8c881bce79aeea304a3852d0fbb042cc2528e8e868f11a78266
7
- data.tar.gz: 2d711c3c87b4cca7f71a1f512cd5e3de33b6c694664dee1e6cf2f2065ef3659c988732d74dfd20e42e9ba9819fdf664cc0b2a80a9533f96e657fd7939be94379
6
+ metadata.gz: 36ffdd30ac91c3c4b715a4d634d8b08a62dd1a2b629f642efa8acc5bc6d444f76e9a71b59f3cdd2af754db4631d76af6c6024e3a4ec3550411f60718b7819ec8
7
+ data.tar.gz: 9b40258eba9fa9002963fc1defe93b3ede2b255d351becbb50421f10a652a890597bbf4d110f4d25f3d34fe91c2b5f17aacb52f37c474600ae0c6d149943f95e
data/.circleci/config.yml CHANGED
@@ -3,7 +3,7 @@ jobs:
3
3
  test:
4
4
  working_directory: ~/calculated_attributes
5
5
  docker:
6
- - image: circleci/ruby:2.3
6
+ - image: circleci/ruby:2.5
7
7
  environment:
8
8
  GEM_HOME: ~/calculated_attributes/vendor/bundle
9
9
  steps:
@@ -12,7 +12,7 @@ jobs:
12
12
  key: dependency-cache-{{ checksum "calculated_attributes.gemspec" }}
13
13
  - run:
14
14
  name: bundle-install
15
- command: bundle check || bundle install --jobs=4 --retry=3
15
+ command: bundle check || bundle install --jobs=4 --retry=3
16
16
  - run:
17
17
  name: appraisal-install
18
18
  command: bundle exec appraisal install
@@ -26,7 +26,7 @@ jobs:
26
26
  - run:
27
27
  name: rubocop
28
28
  command: bundle exec rubocop
29
-
29
+
30
30
  workflows:
31
31
  version: 2
32
32
  test:
data/.rubocop.yml CHANGED
@@ -1,11 +1,8 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.3
2
+ TargetRubyVersion: 2.5
3
3
  DisplayCopNames: true
4
4
  Exclude:
5
- - lib/calculated_attributes/rails_3_patches.rb
6
- - lib/calculated_attributes/rails_4_patches.rb
7
- - lib/calculated_attributes/rails_5_patches.rb
8
- - lib/calculated_attributes/rails_5_2_patches.rb
5
+ - lib/calculated_attributes/rails_*_patches.rb
9
6
 
10
7
  Metrics/AbcSize:
11
8
  Enabled: false
@@ -25,4 +22,7 @@ Style/FrozenStringLiteralComment:
25
22
  Enabled: false
26
23
  Style/PercentLiteralDelimiters:
27
24
  PreferredDelimiters:
28
- '%w': ()
25
+ "%w": ()
26
+ Style/StringLiterals:
27
+ Exclude:
28
+ - gemfiles/*.gemfile
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.5.3
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.5.3
data/Appraisals CHANGED
@@ -1,11 +1,3 @@
1
- appraise 'rails3' do
2
- gem 'activerecord', '~> 3.2'
3
- end
4
-
5
- appraise 'rails4_1' do
6
- gem 'activerecord', '~> 4.1'
7
- end
8
-
9
1
  appraise 'rails4_2' do
10
2
  gem 'activerecord', '~> 4.2'
11
3
  end
@@ -19,5 +11,10 @@ appraise 'rails5_1' do
19
11
  end
20
12
 
21
13
  appraise 'rails5_2' do
22
- gem 'activerecord', '~> 5.2.0.rc1'
14
+ gem 'activerecord', '~> 5.2'
15
+ end
16
+
17
+ appraise 'rails6_0' do
18
+ gem 'activerecord', '~> 6.0'
19
+ gem 'sqlite3', '~> 1.4'
23
20
  end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- [![Gem Version](https://badge.fury.io/rb/calculated_attributes.svg)](https://badge.fury.io/rb/calculated_attributes)
1
+ [![Gem Version](https://badge.fury.io/rb/calculated_attributes.svg)](https://badge.fury.io/rb/calculated_attributes)
2
2
  [![CircleCI](https://circleci.com/gh/aha-app/calculated_attributes.svg?style=shield)](https://circleci.com/gh/aha-app/calculated_attributes)
3
3
 
4
4
  # CalculatedAttributes
@@ -35,7 +35,7 @@ class Post < ActiveRecord::Base
35
35
  ...
36
36
  end
37
37
  ```
38
-
38
+
39
39
  Then, the comments count may be accessed as follows:
40
40
 
41
41
  ```ruby
@@ -43,7 +43,7 @@ Post.scoped.calculated(:comments_count).first.comments_count
43
43
  Post.scoped.calculated(comments_count_by_user: user).first.comments_count_by_user
44
44
  #=> 5
45
45
  ```
46
-
46
+
47
47
  Multiple calculated attributes may be attached to each model. If we add a `Tag` model that also has a `post_id`, we can update the Post model as following:
48
48
 
49
49
  ```ruby
@@ -96,19 +96,23 @@ class Post < ActiveRecord::Base
96
96
  end
97
97
  ```
98
98
 
99
- ## Known Issues
99
+ ## Version support
100
+
101
+ Patches are included to support Rails 3.2, 4.x, 5.x, and 6.x. However, only 4.2 and up are tested and actively maintained.
102
+
103
+ ## Known issues
100
104
 
101
- In Rails 4.x, you cannot call `count` on a relation with calculated attributes, e.g.
105
+ In Rails 4.x and up, you cannot call `count` on a relation with calculated attributes, e.g.
102
106
 
103
107
  ```ruby
104
108
  Post.scoped.calculated(:comments_count).count
105
109
  ```
106
110
 
107
- will error. This is because of an [ActiveRecord issue](https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/calculations.rb#L368-L375) that does not permit Arel nodes in the count method.
111
+ will error because ActiveRecord does not permit Arel nodes in the count method.
108
112
 
109
113
  ## Contributing
110
114
 
111
- 1. Fork it ( https://github.com/aha-app/calculated_attributes/fork )
115
+ 1. Fork it (https://github.com/aha-app/calculated_attributes/fork)
112
116
  2. Create your feature branch (`git checkout -b my-new-feature`)
113
117
  3. Commit your changes (`git commit -am 'Add some feature'`)
114
118
  4. Push to the branch (`git push origin my-new-feature`)
@@ -1,6 +1,4 @@
1
- # coding: utf-8
2
-
3
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
4
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
3
  require 'calculated_attributes/version'
6
4
 
@@ -22,7 +20,7 @@ Gem::Specification.new do |spec|
22
20
  spec.add_development_dependency 'bundler', '~> 1.15'
23
21
  spec.add_development_dependency 'rake', '~> 10.0'
24
22
  spec.add_development_dependency 'rspec', '~> 3.1'
25
- spec.add_development_dependency 'rubocop', '~> 0.49.0'
23
+ spec.add_development_dependency 'rubocop', '~> 0.74.0'
26
24
  spec.add_development_dependency 'sqlite3', '~> 1.3.10'
27
25
 
28
26
  spec.add_dependency 'activerecord', '>= 3.2.20'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- calculated_attributes (0.3.0)
4
+ calculated_attributes (0.4.0)
5
5
  activerecord (>= 3.2.20)
6
6
 
7
7
  GEM
@@ -25,18 +25,17 @@ GEM
25
25
  rake
26
26
  thor (>= 0.14.0)
27
27
  arel (6.0.0)
28
- ast (2.3.0)
28
+ ast (2.4.0)
29
29
  builder (3.2.2)
30
30
  diff-lcs (1.2.5)
31
31
  i18n (0.7.0)
32
- json (1.8.3)
32
+ jaro_winkler (1.5.3)
33
+ json (1.8.5)
33
34
  minitest (5.7.0)
34
- parallel (1.11.2)
35
- parser (2.4.0.0)
36
- ast (~> 2.2)
37
- powerpack (0.1.1)
38
- rainbow (2.2.2)
39
- rake
35
+ parallel (1.17.0)
36
+ parser (2.6.4.0)
37
+ ast (~> 2.4.0)
38
+ rainbow (3.0.0)
40
39
  rake (10.4.2)
41
40
  rspec (3.3.0)
42
41
  rspec-core (~> 3.3.0)
@@ -51,20 +50,20 @@ GEM
51
50
  diff-lcs (>= 1.2.0, < 2.0)
52
51
  rspec-support (~> 3.3.0)
53
52
  rspec-support (3.3.0)
54
- rubocop (0.49.1)
53
+ rubocop (0.74.0)
54
+ jaro_winkler (~> 1.5.1)
55
55
  parallel (~> 1.10)
56
- parser (>= 2.3.3.1, < 3.0)
57
- powerpack (~> 0.1)
58
- rainbow (>= 1.99.1, < 3.0)
56
+ parser (>= 2.6)
57
+ rainbow (>= 2.2.2, < 4.0)
59
58
  ruby-progressbar (~> 1.7)
60
- unicode-display_width (~> 1.0, >= 1.0.1)
61
- ruby-progressbar (1.8.1)
59
+ unicode-display_width (>= 1.4.0, < 1.7)
60
+ ruby-progressbar (1.10.1)
62
61
  sqlite3 (1.3.10)
63
62
  thor (0.19.4)
64
63
  thread_safe (0.3.5)
65
64
  tzinfo (1.2.2)
66
65
  thread_safe (~> 0.1)
67
- unicode-display_width (1.3.0)
66
+ unicode-display_width (1.6.0)
68
67
 
69
68
  PLATFORMS
70
69
  ruby
@@ -76,8 +75,8 @@ DEPENDENCIES
76
75
  calculated_attributes!
77
76
  rake (~> 10.0)
78
77
  rspec (~> 3.1)
79
- rubocop (~> 0.49.0)
78
+ rubocop (~> 0.74.0)
80
79
  sqlite3 (~> 1.3.10)
81
80
 
82
81
  BUNDLED WITH
83
- 1.16.1
82
+ 1.17.0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- calculated_attributes (0.3.0)
4
+ calculated_attributes (0.4.0)
5
5
  activerecord (>= 3.2.20)
6
6
 
7
7
  GEM
@@ -23,17 +23,16 @@ GEM
23
23
  rake
24
24
  thor (>= 0.14.0)
25
25
  arel (7.1.1)
26
- ast (2.3.0)
26
+ ast (2.4.0)
27
27
  concurrent-ruby (1.0.2)
28
28
  diff-lcs (1.2.5)
29
29
  i18n (0.7.0)
30
+ jaro_winkler (1.5.3)
30
31
  minitest (5.9.0)
31
- parallel (1.11.2)
32
- parser (2.4.0.0)
33
- ast (~> 2.2)
34
- powerpack (0.1.1)
35
- rainbow (2.2.2)
36
- rake
32
+ parallel (1.17.0)
33
+ parser (2.6.4.0)
34
+ ast (~> 2.4.0)
35
+ rainbow (3.0.0)
37
36
  rake (10.5.0)
38
37
  rspec (3.5.0)
39
38
  rspec-core (~> 3.5.0)
@@ -48,20 +47,20 @@ GEM
48
47
  diff-lcs (>= 1.2.0, < 2.0)
49
48
  rspec-support (~> 3.5.0)
50
49
  rspec-support (3.5.0)
51
- rubocop (0.49.1)
50
+ rubocop (0.74.0)
51
+ jaro_winkler (~> 1.5.1)
52
52
  parallel (~> 1.10)
53
- parser (>= 2.3.3.1, < 3.0)
54
- powerpack (~> 0.1)
55
- rainbow (>= 1.99.1, < 3.0)
53
+ parser (>= 2.6)
54
+ rainbow (>= 2.2.2, < 4.0)
56
55
  ruby-progressbar (~> 1.7)
57
- unicode-display_width (~> 1.0, >= 1.0.1)
58
- ruby-progressbar (1.8.1)
56
+ unicode-display_width (>= 1.4.0, < 1.7)
57
+ ruby-progressbar (1.10.1)
59
58
  sqlite3 (1.3.11)
60
59
  thor (0.19.4)
61
60
  thread_safe (0.3.5)
62
61
  tzinfo (1.2.2)
63
62
  thread_safe (~> 0.1)
64
- unicode-display_width (1.3.0)
63
+ unicode-display_width (1.6.0)
65
64
 
66
65
  PLATFORMS
67
66
  ruby
@@ -73,8 +72,8 @@ DEPENDENCIES
73
72
  calculated_attributes!
74
73
  rake (~> 10.0)
75
74
  rspec (~> 3.1)
76
- rubocop (~> 0.49.0)
75
+ rubocop (~> 0.74.0)
77
76
  sqlite3 (~> 1.3.10)
78
77
 
79
78
  BUNDLED WITH
80
- 1.16.1
79
+ 1.17.0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- calculated_attributes (0.3.0)
4
+ calculated_attributes (0.4.0)
5
5
  activerecord (>= 3.2.20)
6
6
 
7
7
  GEM
@@ -23,17 +23,16 @@ GEM
23
23
  rake
24
24
  thor (>= 0.14.0)
25
25
  arel (8.0.0)
26
- ast (2.3.0)
26
+ ast (2.4.0)
27
27
  concurrent-ruby (1.0.5)
28
28
  diff-lcs (1.3)
29
29
  i18n (0.8.6)
30
+ jaro_winkler (1.5.3)
30
31
  minitest (5.10.2)
31
- parallel (1.11.2)
32
- parser (2.4.0.0)
33
- ast (~> 2.2)
34
- powerpack (0.1.1)
35
- rainbow (2.2.2)
36
- rake
32
+ parallel (1.17.0)
33
+ parser (2.6.4.0)
34
+ ast (~> 2.4.0)
35
+ rainbow (3.0.0)
37
36
  rake (10.5.0)
38
37
  rspec (3.6.0)
39
38
  rspec-core (~> 3.6.0)
@@ -48,20 +47,20 @@ GEM
48
47
  diff-lcs (>= 1.2.0, < 2.0)
49
48
  rspec-support (~> 3.6.0)
50
49
  rspec-support (3.6.0)
51
- rubocop (0.49.1)
50
+ rubocop (0.74.0)
51
+ jaro_winkler (~> 1.5.1)
52
52
  parallel (~> 1.10)
53
- parser (>= 2.3.3.1, < 3.0)
54
- powerpack (~> 0.1)
55
- rainbow (>= 1.99.1, < 3.0)
53
+ parser (>= 2.6)
54
+ rainbow (>= 2.2.2, < 4.0)
56
55
  ruby-progressbar (~> 1.7)
57
- unicode-display_width (~> 1.0, >= 1.0.1)
58
- ruby-progressbar (1.8.1)
56
+ unicode-display_width (>= 1.4.0, < 1.7)
57
+ ruby-progressbar (1.10.1)
59
58
  sqlite3 (1.3.13)
60
59
  thor (0.19.4)
61
60
  thread_safe (0.3.6)
62
61
  tzinfo (1.2.3)
63
62
  thread_safe (~> 0.1)
64
- unicode-display_width (1.3.0)
63
+ unicode-display_width (1.6.0)
65
64
 
66
65
  PLATFORMS
67
66
  ruby
@@ -73,8 +72,8 @@ DEPENDENCIES
73
72
  calculated_attributes!
74
73
  rake (~> 10.0)
75
74
  rspec (~> 3.1)
76
- rubocop (~> 0.49.0)
75
+ rubocop (~> 0.74.0)
77
76
  sqlite3 (~> 1.3.10)
78
77
 
79
78
  BUNDLED WITH
80
- 1.16.1
79
+ 1.17.0
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 5.2.0.rc1"
5
+ gem "activerecord", "~> 5.2"
6
6
 
7
7
  gemspec path: "../"
@@ -1,21 +1,21 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- calculated_attributes (0.3.0)
4
+ calculated_attributes (0.4.0)
5
5
  activerecord (>= 3.2.20)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (5.2.0.rc1)
11
- activesupport (= 5.2.0.rc1)
12
- activerecord (5.2.0.rc1)
13
- activemodel (= 5.2.0.rc1)
14
- activesupport (= 5.2.0.rc1)
10
+ activemodel (5.2.3)
11
+ activesupport (= 5.2.3)
12
+ activerecord (5.2.3)
13
+ activemodel (= 5.2.3)
14
+ activesupport (= 5.2.3)
15
15
  arel (>= 9.0)
16
- activesupport (5.2.0.rc1)
16
+ activesupport (5.2.3)
17
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
- i18n (~> 0.7)
18
+ i18n (>= 0.7, < 2)
19
19
  minitest (~> 5.1)
20
20
  tzinfo (~> 1.1)
21
21
  appraisal (2.2.0)
@@ -24,58 +24,57 @@ GEM
24
24
  thor (>= 0.14.0)
25
25
  arel (9.0.0)
26
26
  ast (2.4.0)
27
- concurrent-ruby (1.0.5)
27
+ concurrent-ruby (1.1.5)
28
28
  diff-lcs (1.3)
29
- i18n (0.9.5)
29
+ i18n (1.6.0)
30
30
  concurrent-ruby (~> 1.0)
31
+ jaro_winkler (1.5.3)
31
32
  minitest (5.11.3)
32
- parallel (1.12.1)
33
- parser (2.5.0.0)
33
+ parallel (1.17.0)
34
+ parser (2.6.4.0)
34
35
  ast (~> 2.4.0)
35
- powerpack (0.1.1)
36
- rainbow (2.2.2)
37
- rake
36
+ rainbow (3.0.0)
38
37
  rake (10.5.0)
39
- rspec (3.7.0)
40
- rspec-core (~> 3.7.0)
41
- rspec-expectations (~> 3.7.0)
42
- rspec-mocks (~> 3.7.0)
43
- rspec-core (3.7.1)
44
- rspec-support (~> 3.7.0)
45
- rspec-expectations (3.7.0)
38
+ rspec (3.8.0)
39
+ rspec-core (~> 3.8.0)
40
+ rspec-expectations (~> 3.8.0)
41
+ rspec-mocks (~> 3.8.0)
42
+ rspec-core (3.8.2)
43
+ rspec-support (~> 3.8.0)
44
+ rspec-expectations (3.8.4)
46
45
  diff-lcs (>= 1.2.0, < 2.0)
47
- rspec-support (~> 3.7.0)
48
- rspec-mocks (3.7.0)
46
+ rspec-support (~> 3.8.0)
47
+ rspec-mocks (3.8.1)
49
48
  diff-lcs (>= 1.2.0, < 2.0)
50
- rspec-support (~> 3.7.0)
51
- rspec-support (3.7.1)
52
- rubocop (0.49.1)
49
+ rspec-support (~> 3.8.0)
50
+ rspec-support (3.8.2)
51
+ rubocop (0.74.0)
52
+ jaro_winkler (~> 1.5.1)
53
53
  parallel (~> 1.10)
54
- parser (>= 2.3.3.1, < 3.0)
55
- powerpack (~> 0.1)
56
- rainbow (>= 1.99.1, < 3.0)
54
+ parser (>= 2.6)
55
+ rainbow (>= 2.2.2, < 4.0)
57
56
  ruby-progressbar (~> 1.7)
58
- unicode-display_width (~> 1.0, >= 1.0.1)
59
- ruby-progressbar (1.9.0)
57
+ unicode-display_width (>= 1.4.0, < 1.7)
58
+ ruby-progressbar (1.10.1)
60
59
  sqlite3 (1.3.13)
61
- thor (0.20.0)
60
+ thor (0.20.3)
62
61
  thread_safe (0.3.6)
63
62
  tzinfo (1.2.5)
64
63
  thread_safe (~> 0.1)
65
- unicode-display_width (1.3.0)
64
+ unicode-display_width (1.6.0)
66
65
 
67
66
  PLATFORMS
68
67
  ruby
69
68
 
70
69
  DEPENDENCIES
71
- activerecord (~> 5.2.0.rc1)
70
+ activerecord (~> 5.2)
72
71
  appraisal (~> 2.2.0)
73
72
  bundler (~> 1.15)
74
73
  calculated_attributes!
75
74
  rake (~> 10.0)
76
75
  rspec (~> 3.1)
77
- rubocop (~> 0.49.0)
76
+ rubocop (~> 0.74.0)
78
77
  sqlite3 (~> 1.3.10)
79
78
 
80
79
  BUNDLED WITH
81
- 1.16.1
80
+ 1.17.0
@@ -2,6 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "~> 3.2"
5
+ gem "activerecord", "~> 6.0"
6
+ gem "sqlite3", "~> 1.4"
6
7
 
7
8
  gemspec path: "../"
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ calculated_attributes (0.4.0)
5
+ activerecord (>= 3.2.20)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (6.0.0)
11
+ activesupport (= 6.0.0)
12
+ activerecord (6.0.0)
13
+ activemodel (= 6.0.0)
14
+ activesupport (= 6.0.0)
15
+ activesupport (6.0.0)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 0.7, < 2)
18
+ minitest (~> 5.1)
19
+ tzinfo (~> 1.1)
20
+ zeitwerk (~> 2.1, >= 2.1.8)
21
+ appraisal (2.2.0)
22
+ bundler
23
+ rake
24
+ thor (>= 0.14.0)
25
+ ast (2.4.0)
26
+ concurrent-ruby (1.1.5)
27
+ diff-lcs (1.3)
28
+ i18n (1.6.0)
29
+ concurrent-ruby (~> 1.0)
30
+ jaro_winkler (1.5.3)
31
+ minitest (5.11.3)
32
+ parallel (1.17.0)
33
+ parser (2.6.4.0)
34
+ ast (~> 2.4.0)
35
+ rainbow (3.0.0)
36
+ rake (10.5.0)
37
+ rspec (3.8.0)
38
+ rspec-core (~> 3.8.0)
39
+ rspec-expectations (~> 3.8.0)
40
+ rspec-mocks (~> 3.8.0)
41
+ rspec-core (3.8.2)
42
+ rspec-support (~> 3.8.0)
43
+ rspec-expectations (3.8.4)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.8.0)
46
+ rspec-mocks (3.8.1)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.8.0)
49
+ rspec-support (3.8.2)
50
+ rubocop (0.74.0)
51
+ jaro_winkler (~> 1.5.1)
52
+ parallel (~> 1.10)
53
+ parser (>= 2.6)
54
+ rainbow (>= 2.2.2, < 4.0)
55
+ ruby-progressbar (~> 1.7)
56
+ unicode-display_width (>= 1.4.0, < 1.7)
57
+ ruby-progressbar (1.10.1)
58
+ sqlite3 (1.4.1)
59
+ thor (0.20.3)
60
+ thread_safe (0.3.6)
61
+ tzinfo (1.2.5)
62
+ thread_safe (~> 0.1)
63
+ unicode-display_width (1.6.0)
64
+ zeitwerk (2.1.10)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ activerecord (~> 6.0)
71
+ appraisal (~> 2.2.0)
72
+ bundler (~> 1.15)
73
+ calculated_attributes!
74
+ rake (~> 10.0)
75
+ rspec (~> 3.1)
76
+ rubocop (~> 0.74.0)
77
+ sqlite3 (~> 1.4)
78
+
79
+ BUNDLED WITH
80
+ 1.17.0
@@ -0,0 +1,65 @@
1
+ module ActiveRecord
2
+ module AttributeMethods
3
+ module ClassMethods
4
+ # Generates all the attribute related methods for columns in the database
5
+ # accessors, mutators and query methods.
6
+ def define_attribute_methods # :nodoc:
7
+ return false if @attribute_methods_generated
8
+ # Use a mutex; we don't want two threads simultaneously trying to define
9
+ # attribute methods.
10
+ generated_attribute_methods.synchronize do
11
+ return false if @attribute_methods_generated
12
+ superclass.define_attribute_methods unless base_class?
13
+ columns_to_define =
14
+ if defined?(calculated) && calculated.instance_variable_get('@calculations')
15
+ calculated_keys = calculated.instance_variable_get('@calculations').keys
16
+ attribute_names.reject { |c| calculated_keys.include? c.intern }
17
+ else
18
+ attribute_names
19
+ end
20
+ super(columns_to_define)
21
+ @attribute_methods_generated = true
22
+ @attribute_methods_generated = true
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ module Associations
29
+ class JoinDependency
30
+ attr_writer :calculated_columns
31
+
32
+ def instantiate(result_set, &block)
33
+ primary_key = aliases.column_alias(join_root, join_root.primary_key)
34
+
35
+ seen = Hash.new { |i, object_id|
36
+ i[object_id] = Hash.new { |j, child_class|
37
+ j[child_class] = {}
38
+ }
39
+ }
40
+
41
+ model_cache = Hash.new { |h, klass| h[klass] = {} }
42
+ parents = model_cache[join_root]
43
+ column_aliases = aliases.column_aliases join_root
44
+
45
+ message_bus = ActiveSupport::Notifications.instrumenter
46
+
47
+ payload = {
48
+ record_count: result_set.length,
49
+ class_name: join_root.base_klass.name
50
+ }
51
+
52
+ message_bus.instrument("instantiation.active_record", payload) do
53
+ result_set.each { |row_hash|
54
+ parent_key = primary_key ? row_hash[primary_key] : row_hash
55
+ parent = parents[parent_key] ||= join_root.instantiate(row_hash, column_aliases, &block)
56
+ @calculated_columns.each { |column| parent[column.right] = model[column.right] } if @calculated_columns
57
+ construct(parent, join_root, row_hash, seen, model_cache)
58
+ }
59
+ end
60
+
61
+ parents.values
62
+ end
63
+ end
64
+ end
65
+ end
@@ -1,3 +1,3 @@
1
1
  module CalculatedAttributes
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -4,12 +4,14 @@ require 'active_record'
4
4
  # Include patches.
5
5
  require 'calculated_attributes/rails_patches'
6
6
  require 'calculated_attributes/arel_patches'
7
- raise "Unsupported ActiveRecord version: #{ActiveRecord::VERSION::MAJOR}" unless [3, 4, 5].include? ActiveRecord::VERSION::MAJOR
7
+ raise "Unsupported ActiveRecord version: #{ActiveRecord::VERSION::MAJOR}" unless [3, 4, 5, 6].include? ActiveRecord::VERSION::MAJOR
8
8
 
9
- if Gem::Version.new(ActiveRecord::VERSION::STRING) <= Gem::Version.new('5.1.4')
10
- require "calculated_attributes/rails_#{ActiveRecord::VERSION::MAJOR}_patches"
11
- else
9
+ # Rails 5.2 has its own patches which are different from 5.0/5.1. In every other
10
+ # case, just require the patch file for the major version.
11
+ if Gem::Version.new(ActiveRecord::VERSION::STRING).canonical_segments.take(2) == [5, 2]
12
12
  require 'calculated_attributes/rails_5_2_patches'
13
+ else
14
+ require "calculated_attributes/rails_#{ActiveRecord::VERSION::MAJOR}_patches"
13
15
  end
14
16
 
15
17
  # Include model code.
@@ -119,12 +119,7 @@ describe 'calculated_attributes' do
119
119
 
120
120
  context 'when eager loading models' do
121
121
  it 'includes calculated attributes' do
122
- scope =
123
- case ActiveRecord::VERSION::MAJOR
124
- when 5 then model_scoped(Post).includes(:comments).references(:comments)
125
- when 4 then model_scoped(Post).includes(:comments).references(:comments)
126
- when 3 then model_scoped(Post).eager_load(:comments)
127
- end
122
+ scope = model_scoped(Post).includes(:comments).references(:comments)
128
123
  expect(scope.first.comments_count).to eq(1)
129
124
  end
130
125
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calculated_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Schneider
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-21 00:00:00.000000000 Z
11
+ date: 2019-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.49.0
75
+ version: 0.74.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.49.0
82
+ version: 0.74.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: sqlite3
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -120,16 +120,13 @@ files:
120
120
  - ".rspec"
121
121
  - ".rubocop.yml"
122
122
  - ".ruby-version"
123
+ - ".tool-versions"
123
124
  - Appraisals
124
125
  - Gemfile
125
126
  - LICENSE.txt
126
127
  - README.md
127
128
  - Rakefile
128
129
  - calculated_attributes.gemspec
129
- - gemfiles/rails3.gemfile
130
- - gemfiles/rails3.gemfile.lock
131
- - gemfiles/rails4_1.gemfile
132
- - gemfiles/rails4_1.gemfile.lock
133
130
  - gemfiles/rails4_2.gemfile
134
131
  - gemfiles/rails4_2.gemfile.lock
135
132
  - gemfiles/rails5_0.gemfile
@@ -138,6 +135,8 @@ files:
138
135
  - gemfiles/rails5_1.gemfile.lock
139
136
  - gemfiles/rails5_2.gemfile
140
137
  - gemfiles/rails5_2.gemfile.lock
138
+ - gemfiles/rails6_0.gemfile
139
+ - gemfiles/rails6_0.gemfile.lock
141
140
  - lib/calculated_attributes.rb
142
141
  - lib/calculated_attributes/arel_patches.rb
143
142
  - lib/calculated_attributes/model_methods.rb
@@ -145,6 +144,7 @@ files:
145
144
  - lib/calculated_attributes/rails_4_patches.rb
146
145
  - lib/calculated_attributes/rails_5_2_patches.rb
147
146
  - lib/calculated_attributes/rails_5_patches.rb
147
+ - lib/calculated_attributes/rails_6_patches.rb
148
148
  - lib/calculated_attributes/rails_patches.rb
149
149
  - lib/calculated_attributes/version.rb
150
150
  - spec/lib/calculated_attributes_spec.rb
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
172
172
  version: '0'
173
173
  requirements: []
174
174
  rubyforge_project:
175
- rubygems_version: 2.6.14
175
+ rubygems_version: 2.7.6
176
176
  signing_key:
177
177
  specification_version: 4
178
178
  summary: Automatically add calculated attributes to ActiveRecord models.
@@ -1,78 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- calculated_attributes (0.3.0)
5
- activerecord (>= 3.2.20)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (3.2.21)
11
- activesupport (= 3.2.21)
12
- builder (~> 3.0.0)
13
- activerecord (3.2.21)
14
- activemodel (= 3.2.21)
15
- activesupport (= 3.2.21)
16
- arel (~> 3.0.2)
17
- tzinfo (~> 0.3.29)
18
- activesupport (3.2.21)
19
- i18n (~> 0.6, >= 0.6.4)
20
- multi_json (~> 1.0)
21
- appraisal (2.2.0)
22
- bundler
23
- rake
24
- thor (>= 0.14.0)
25
- arel (3.0.3)
26
- ast (2.3.0)
27
- builder (3.0.4)
28
- diff-lcs (1.2.5)
29
- i18n (0.7.0)
30
- multi_json (1.11.1)
31
- parallel (1.11.2)
32
- parser (2.4.0.0)
33
- ast (~> 2.2)
34
- powerpack (0.1.1)
35
- rainbow (2.2.2)
36
- rake
37
- rake (10.4.2)
38
- rspec (3.3.0)
39
- rspec-core (~> 3.3.0)
40
- rspec-expectations (~> 3.3.0)
41
- rspec-mocks (~> 3.3.0)
42
- rspec-core (3.3.0)
43
- rspec-support (~> 3.3.0)
44
- rspec-expectations (3.3.0)
45
- diff-lcs (>= 1.2.0, < 2.0)
46
- rspec-support (~> 3.3.0)
47
- rspec-mocks (3.3.0)
48
- diff-lcs (>= 1.2.0, < 2.0)
49
- rspec-support (~> 3.3.0)
50
- rspec-support (3.3.0)
51
- rubocop (0.49.1)
52
- parallel (~> 1.10)
53
- parser (>= 2.3.3.1, < 3.0)
54
- powerpack (~> 0.1)
55
- rainbow (>= 1.99.1, < 3.0)
56
- ruby-progressbar (~> 1.7)
57
- unicode-display_width (~> 1.0, >= 1.0.1)
58
- ruby-progressbar (1.8.1)
59
- sqlite3 (1.3.10)
60
- thor (0.19.4)
61
- tzinfo (0.3.44)
62
- unicode-display_width (1.3.0)
63
-
64
- PLATFORMS
65
- ruby
66
-
67
- DEPENDENCIES
68
- activerecord (~> 3.2)
69
- appraisal (~> 2.2.0)
70
- bundler (~> 1.15)
71
- calculated_attributes!
72
- rake (~> 10.0)
73
- rspec (~> 3.1)
74
- rubocop (~> 0.49.0)
75
- sqlite3 (~> 1.3.10)
76
-
77
- BUNDLED WITH
78
- 1.16.1
@@ -1,7 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.1"
6
-
7
- gemspec path: "../"
@@ -1,83 +0,0 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- calculated_attributes (0.3.0)
5
- activerecord (>= 3.2.20)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activemodel (4.1.11)
11
- activesupport (= 4.1.11)
12
- builder (~> 3.1)
13
- activerecord (4.1.11)
14
- activemodel (= 4.1.11)
15
- activesupport (= 4.1.11)
16
- arel (~> 5.0.0)
17
- activesupport (4.1.11)
18
- i18n (~> 0.6, >= 0.6.9)
19
- json (~> 1.7, >= 1.7.7)
20
- minitest (~> 5.1)
21
- thread_safe (~> 0.1)
22
- tzinfo (~> 1.1)
23
- appraisal (2.2.0)
24
- bundler
25
- rake
26
- thor (>= 0.14.0)
27
- arel (5.0.1.20140414130214)
28
- ast (2.3.0)
29
- builder (3.2.2)
30
- diff-lcs (1.2.5)
31
- i18n (0.7.0)
32
- json (1.8.3)
33
- minitest (5.7.0)
34
- parallel (1.11.2)
35
- parser (2.4.0.0)
36
- ast (~> 2.2)
37
- powerpack (0.1.1)
38
- rainbow (2.2.2)
39
- rake
40
- rake (10.4.2)
41
- rspec (3.3.0)
42
- rspec-core (~> 3.3.0)
43
- rspec-expectations (~> 3.3.0)
44
- rspec-mocks (~> 3.3.0)
45
- rspec-core (3.3.1)
46
- rspec-support (~> 3.3.0)
47
- rspec-expectations (3.3.0)
48
- diff-lcs (>= 1.2.0, < 2.0)
49
- rspec-support (~> 3.3.0)
50
- rspec-mocks (3.3.0)
51
- diff-lcs (>= 1.2.0, < 2.0)
52
- rspec-support (~> 3.3.0)
53
- rspec-support (3.3.0)
54
- rubocop (0.49.1)
55
- parallel (~> 1.10)
56
- parser (>= 2.3.3.1, < 3.0)
57
- powerpack (~> 0.1)
58
- rainbow (>= 1.99.1, < 3.0)
59
- ruby-progressbar (~> 1.7)
60
- unicode-display_width (~> 1.0, >= 1.0.1)
61
- ruby-progressbar (1.8.1)
62
- sqlite3 (1.3.10)
63
- thor (0.19.4)
64
- thread_safe (0.3.5)
65
- tzinfo (1.2.2)
66
- thread_safe (~> 0.1)
67
- unicode-display_width (1.3.0)
68
-
69
- PLATFORMS
70
- ruby
71
-
72
- DEPENDENCIES
73
- activerecord (~> 4.1)
74
- appraisal (~> 2.2.0)
75
- bundler (~> 1.15)
76
- calculated_attributes!
77
- rake (~> 10.0)
78
- rspec (~> 3.1)
79
- rubocop (~> 0.49.0)
80
- sqlite3 (~> 1.3.10)
81
-
82
- BUNDLED WITH
83
- 1.16.1