calculated_attributes 0.1.5 → 0.2.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
  SHA1:
3
- metadata.gz: a0940be8c91d38d2aec6592df3ab0ecb9d45cff3
4
- data.tar.gz: 9d497e3a163e7447892aa73e81b0b647fa16d8ec
3
+ metadata.gz: 1c3bf23247f51652ecb2a074be62c27c5a1d9a20
4
+ data.tar.gz: f3d08403e2e8fdf7ad6cf2edabebc2ce2e81dd23
5
5
  SHA512:
6
- metadata.gz: 195341ee43dcb6b87fd1ca1a45c9c5eb41f26ad3bd9479c8aabc3cd96e131d1b5671276a20767f99d43e0c3c136d2b5188d988e481afa5045b21641956d7c50c
7
- data.tar.gz: f9634c6a9762bfc550001d92b98f112dbcc51397e5f81f0e0fcbd4ca36508f45a28cd0d12ece28ab40919add24740c26b04f78bfe8f2cec193485db93c824483
6
+ metadata.gz: ec8f02c57c71a0753fbc235d19510d21dc120131dfbcc593becd70c966be90a34542ff11593389397e82e071c3cff02647b48b3a7b5ec9c40d932bd16fd6d666
7
+ data.tar.gz: b4b53833e117d6795d498ca0698f75d74853dfec32d5d10cf15035b4befbadee7961dc54fe3aab3c49cf7a7adbb2e9ded25bb5c8349ad6d98b6b394f8b5571c2
@@ -0,0 +1,34 @@
1
+ version: 2
2
+ jobs:
3
+ test:
4
+ working_directory: ~/calculated_attributes
5
+ docker:
6
+ - image: circleci/ruby:2.3
7
+ environment:
8
+ GEM_HOME: ~/calculated_attributes/vendor/bundle
9
+ steps:
10
+ - checkout
11
+ - restore_cache:
12
+ key: dependency-cache-{{ checksum "calculated_attributes.gemspec" }}
13
+ - run:
14
+ name: bundle-install
15
+ command: bundle check || bundle install --jobs=4 --retry=3
16
+ - run:
17
+ name: appraisal-install
18
+ command: bundle exec appraisal install
19
+ - save_cache:
20
+ key: dependency-cache-{{ checksum "calculated_attributes.gemspec" }}
21
+ paths:
22
+ - ./vendor/bundle
23
+ - run:
24
+ name: appraisal-rspec
25
+ command: bundle exec appraisal rspec
26
+ - run:
27
+ name: rubocop
28
+ command: bundle exec rubocop
29
+
30
+ workflows:
31
+ version: 2
32
+ test:
33
+ jobs:
34
+ - test
data/.rubocop.yml CHANGED
@@ -1,22 +1,27 @@
1
1
  AllCops:
2
+ TargetRubyVersion: 2.3
3
+ DisplayCopNames: true
2
4
  Exclude:
3
- - db/**/*
5
+ - lib/calculated_attributes/rails_3_patches.rb
6
+ - lib/calculated_attributes/rails_4_patches.rb
7
+ - lib/calculated_attributes/rails_5_patches.rb
4
8
 
5
- BlockNesting:
6
- Max: 4
7
- ClassLength:
8
- Enabled: False
9
- ClassVars:
10
- Enabled: False
11
- CyclomaticComplexity:
12
- Enabled: False
13
- Documentation:
9
+ Metrics/AbcSize:
14
10
  Enabled: false
15
- LineLength:
11
+ Metrics/BlockLength:
16
12
  Enabled: false
17
- MethodLength:
13
+ Metrics/CyclomaticComplexity:
14
+ Enabled: False
15
+ Metrics/LineLength:
18
16
  Enabled: false
19
- Metrics/AbcSize:
17
+ Metrics/MethodLength:
20
18
  Enabled: false
21
19
  Metrics/PerceivedComplexity:
22
- Enabled: false
20
+ Enabled: false
21
+ Style/Documentation:
22
+ Enabled: false
23
+ Style/FrozenStringLiteralComment:
24
+ Enabled: false
25
+ Style/PercentLiteralDelimiters:
26
+ PreferredDelimiters:
27
+ '%w': ()
data/Appraisals CHANGED
@@ -1,15 +1,19 @@
1
1
  appraise 'rails3' do
2
- gem 'activerecord', '3.2.21'
2
+ gem 'activerecord', '~> 3.2'
3
3
  end
4
4
 
5
5
  appraise 'rails4_1' do
6
- gem 'activerecord', '4.1.11'
6
+ gem 'activerecord', '~> 4.1'
7
7
  end
8
8
 
9
9
  appraise 'rails4_2' do
10
- gem 'activerecord', '4.2.2'
10
+ gem 'activerecord', '~> 4.2'
11
11
  end
12
12
 
13
13
  appraise 'rails5_0' do
14
- gem 'activerecord', '5.0.0'
14
+ gem 'activerecord', '~> 5.0'
15
+ end
16
+
17
+ appraise 'rails5_1' do
18
+ gem 'activerecord', '~> 5.1'
15
19
  end
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'calculated_attributes/version'
@@ -17,10 +18,11 @@ Gem::Specification.new do |spec|
17
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
19
  spec.require_paths = ['lib']
19
20
 
20
- spec.add_development_dependency 'appraisal', '~> 1.0.3'
21
+ spec.add_development_dependency 'appraisal', '~> 2.2.0'
22
+ spec.add_development_dependency 'bundler', '~> 1.15'
21
23
  spec.add_development_dependency 'rake', '~> 10.0'
22
24
  spec.add_development_dependency 'rspec', '~> 3.1'
23
- spec.add_development_dependency 'rubocop', '~> 0.32.0'
25
+ spec.add_development_dependency 'rubocop', '~> 0.49.0'
24
26
  spec.add_development_dependency 'sqlite3', '~> 1.3.10'
25
27
 
26
28
  spec.add_dependency 'activerecord', '>= 3.2.20'
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "3.2.21"
5
+ gem "activerecord", "~> 3.2"
6
6
 
7
- gemspec :path => "../"
7
+ gemspec path: "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
- remote: ../
2
+ remote: ..
3
3
  specs:
4
- calculated_attributes (0.1.5)
4
+ calculated_attributes (0.2.0)
5
5
  activerecord (>= 3.2.20)
6
6
 
7
7
  GEM
@@ -18,22 +18,22 @@ GEM
18
18
  activesupport (3.2.21)
19
19
  i18n (~> 0.6, >= 0.6.4)
20
20
  multi_json (~> 1.0)
21
- appraisal (1.0.3)
21
+ appraisal (2.2.0)
22
22
  bundler
23
23
  rake
24
24
  thor (>= 0.14.0)
25
25
  arel (3.0.3)
26
- ast (2.0.0)
27
- astrolabe (1.3.0)
28
- parser (>= 2.2.0.pre.3, < 3.0)
26
+ ast (2.3.0)
29
27
  builder (3.0.4)
30
28
  diff-lcs (1.2.5)
31
29
  i18n (0.7.0)
32
30
  multi_json (1.11.1)
33
- parser (2.3.0.pre.2)
34
- ast (>= 1.1, < 3.0)
31
+ parallel (1.11.2)
32
+ parser (2.4.0.0)
33
+ ast (~> 2.2)
35
34
  powerpack (0.1.1)
36
- rainbow (2.0.0)
35
+ rainbow (2.2.2)
36
+ rake
37
37
  rake (10.4.2)
38
38
  rspec (3.3.0)
39
39
  rspec-core (~> 3.3.0)
@@ -48,28 +48,31 @@ GEM
48
48
  diff-lcs (>= 1.2.0, < 2.0)
49
49
  rspec-support (~> 3.3.0)
50
50
  rspec-support (3.3.0)
51
- rubocop (0.32.0)
52
- astrolabe (~> 1.3)
53
- parser (>= 2.2.2.5, < 3.0)
51
+ rubocop (0.49.1)
52
+ parallel (~> 1.10)
53
+ parser (>= 2.3.3.1, < 3.0)
54
54
  powerpack (~> 0.1)
55
55
  rainbow (>= 1.99.1, < 3.0)
56
- ruby-progressbar (~> 1.4)
57
- ruby-progressbar (1.7.5)
56
+ ruby-progressbar (~> 1.7)
57
+ unicode-display_width (~> 1.0, >= 1.0.1)
58
+ ruby-progressbar (1.8.1)
58
59
  sqlite3 (1.3.10)
59
- thor (0.19.1)
60
+ thor (0.19.4)
60
61
  tzinfo (0.3.44)
62
+ unicode-display_width (1.3.0)
61
63
 
62
64
  PLATFORMS
63
65
  ruby
64
66
 
65
67
  DEPENDENCIES
66
- activerecord (= 3.2.21)
67
- appraisal (~> 1.0.3)
68
+ activerecord (~> 3.2)
69
+ appraisal (~> 2.2.0)
70
+ bundler (~> 1.15)
68
71
  calculated_attributes!
69
72
  rake (~> 10.0)
70
73
  rspec (~> 3.1)
71
- rubocop (~> 0.32.0)
74
+ rubocop (~> 0.49.0)
72
75
  sqlite3 (~> 1.3.10)
73
76
 
74
77
  BUNDLED WITH
75
- 1.12.5
78
+ 1.15.1
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "4.1.11"
5
+ gem "activerecord", "~> 4.1"
6
6
 
7
- gemspec :path => "../"
7
+ gemspec path: "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
- remote: ../
2
+ remote: ..
3
3
  specs:
4
- calculated_attributes (0.1.5)
4
+ calculated_attributes (0.2.0)
5
5
  activerecord (>= 3.2.20)
6
6
 
7
7
  GEM
@@ -20,23 +20,23 @@ GEM
20
20
  minitest (~> 5.1)
21
21
  thread_safe (~> 0.1)
22
22
  tzinfo (~> 1.1)
23
- appraisal (1.0.3)
23
+ appraisal (2.2.0)
24
24
  bundler
25
25
  rake
26
26
  thor (>= 0.14.0)
27
27
  arel (5.0.1.20140414130214)
28
- ast (2.0.0)
29
- astrolabe (1.3.0)
30
- parser (>= 2.2.0.pre.3, < 3.0)
28
+ ast (2.3.0)
31
29
  builder (3.2.2)
32
30
  diff-lcs (1.2.5)
33
31
  i18n (0.7.0)
34
32
  json (1.8.3)
35
33
  minitest (5.7.0)
36
- parser (2.2.2.5)
37
- ast (>= 1.1, < 3.0)
34
+ parallel (1.11.2)
35
+ parser (2.4.0.0)
36
+ ast (~> 2.2)
38
37
  powerpack (0.1.1)
39
- rainbow (2.0.0)
38
+ rainbow (2.2.2)
39
+ rake
40
40
  rake (10.4.2)
41
41
  rspec (3.3.0)
42
42
  rspec-core (~> 3.3.0)
@@ -51,30 +51,33 @@ GEM
51
51
  diff-lcs (>= 1.2.0, < 2.0)
52
52
  rspec-support (~> 3.3.0)
53
53
  rspec-support (3.3.0)
54
- rubocop (0.32.0)
55
- astrolabe (~> 1.3)
56
- parser (>= 2.2.2.5, < 3.0)
54
+ rubocop (0.49.1)
55
+ parallel (~> 1.10)
56
+ parser (>= 2.3.3.1, < 3.0)
57
57
  powerpack (~> 0.1)
58
58
  rainbow (>= 1.99.1, < 3.0)
59
- ruby-progressbar (~> 1.4)
60
- ruby-progressbar (1.7.5)
59
+ ruby-progressbar (~> 1.7)
60
+ unicode-display_width (~> 1.0, >= 1.0.1)
61
+ ruby-progressbar (1.8.1)
61
62
  sqlite3 (1.3.10)
62
- thor (0.19.1)
63
+ thor (0.19.4)
63
64
  thread_safe (0.3.5)
64
65
  tzinfo (1.2.2)
65
66
  thread_safe (~> 0.1)
67
+ unicode-display_width (1.3.0)
66
68
 
67
69
  PLATFORMS
68
70
  ruby
69
71
 
70
72
  DEPENDENCIES
71
- activerecord (= 4.1.11)
72
- appraisal (~> 1.0.3)
73
+ activerecord (~> 4.1)
74
+ appraisal (~> 2.2.0)
75
+ bundler (~> 1.15)
73
76
  calculated_attributes!
74
77
  rake (~> 10.0)
75
78
  rspec (~> 3.1)
76
- rubocop (~> 0.32.0)
79
+ rubocop (~> 0.49.0)
77
80
  sqlite3 (~> 1.3.10)
78
81
 
79
82
  BUNDLED WITH
80
- 1.12.5
83
+ 1.15.1
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "4.2.2"
5
+ gem "activerecord", "~> 4.2"
6
6
 
7
- gemspec :path => "../"
7
+ gemspec path: "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
- remote: ../
2
+ remote: ..
3
3
  specs:
4
- calculated_attributes (0.1.5)
4
+ calculated_attributes (0.2.0)
5
5
  activerecord (>= 3.2.20)
6
6
 
7
7
  GEM
@@ -20,23 +20,23 @@ GEM
20
20
  minitest (~> 5.1)
21
21
  thread_safe (~> 0.3, >= 0.3.4)
22
22
  tzinfo (~> 1.1)
23
- appraisal (1.0.3)
23
+ appraisal (2.2.0)
24
24
  bundler
25
25
  rake
26
26
  thor (>= 0.14.0)
27
27
  arel (6.0.0)
28
- ast (2.0.0)
29
- astrolabe (1.3.0)
30
- parser (>= 2.2.0.pre.3, < 3.0)
28
+ ast (2.3.0)
31
29
  builder (3.2.2)
32
30
  diff-lcs (1.2.5)
33
31
  i18n (0.7.0)
34
32
  json (1.8.3)
35
33
  minitest (5.7.0)
36
- parser (2.2.2.5)
37
- ast (>= 1.1, < 3.0)
34
+ parallel (1.11.2)
35
+ parser (2.4.0.0)
36
+ ast (~> 2.2)
38
37
  powerpack (0.1.1)
39
- rainbow (2.0.0)
38
+ rainbow (2.2.2)
39
+ rake
40
40
  rake (10.4.2)
41
41
  rspec (3.3.0)
42
42
  rspec-core (~> 3.3.0)
@@ -51,30 +51,33 @@ GEM
51
51
  diff-lcs (>= 1.2.0, < 2.0)
52
52
  rspec-support (~> 3.3.0)
53
53
  rspec-support (3.3.0)
54
- rubocop (0.32.0)
55
- astrolabe (~> 1.3)
56
- parser (>= 2.2.2.5, < 3.0)
54
+ rubocop (0.49.1)
55
+ parallel (~> 1.10)
56
+ parser (>= 2.3.3.1, < 3.0)
57
57
  powerpack (~> 0.1)
58
58
  rainbow (>= 1.99.1, < 3.0)
59
- ruby-progressbar (~> 1.4)
60
- ruby-progressbar (1.7.5)
59
+ ruby-progressbar (~> 1.7)
60
+ unicode-display_width (~> 1.0, >= 1.0.1)
61
+ ruby-progressbar (1.8.1)
61
62
  sqlite3 (1.3.10)
62
- thor (0.19.1)
63
+ thor (0.19.4)
63
64
  thread_safe (0.3.5)
64
65
  tzinfo (1.2.2)
65
66
  thread_safe (~> 0.1)
67
+ unicode-display_width (1.3.0)
66
68
 
67
69
  PLATFORMS
68
70
  ruby
69
71
 
70
72
  DEPENDENCIES
71
- activerecord (= 4.2.2)
72
- appraisal (~> 1.0.3)
73
+ activerecord (~> 4.2)
74
+ appraisal (~> 2.2.0)
75
+ bundler (~> 1.15)
73
76
  calculated_attributes!
74
77
  rake (~> 10.0)
75
78
  rspec (~> 3.1)
76
- rubocop (~> 0.32.0)
79
+ rubocop (~> 0.49.0)
77
80
  sqlite3 (~> 1.3.10)
78
81
 
79
82
  BUNDLED WITH
80
- 1.12.5
83
+ 1.15.1
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", "5.0.0"
5
+ gem "activerecord", "~> 5.0"
6
6
 
7
- gemspec :path => "../"
7
+ gemspec path: "../"
@@ -1,7 +1,7 @@
1
1
  PATH
2
- remote: ../
2
+ remote: ..
3
3
  specs:
4
- calculated_attributes (0.1.5)
4
+ calculated_attributes (0.2.0)
5
5
  activerecord (>= 3.2.20)
6
6
 
7
7
  GEM
@@ -18,22 +18,22 @@ GEM
18
18
  i18n (~> 0.7)
19
19
  minitest (~> 5.1)
20
20
  tzinfo (~> 1.1)
21
- appraisal (1.0.3)
21
+ appraisal (2.2.0)
22
22
  bundler
23
23
  rake
24
24
  thor (>= 0.14.0)
25
25
  arel (7.1.1)
26
26
  ast (2.3.0)
27
- astrolabe (1.3.1)
28
- parser (~> 2.2)
29
27
  concurrent-ruby (1.0.2)
30
28
  diff-lcs (1.2.5)
31
29
  i18n (0.7.0)
32
30
  minitest (5.9.0)
33
- parser (2.3.1.2)
31
+ parallel (1.11.2)
32
+ parser (2.4.0.0)
34
33
  ast (~> 2.2)
35
34
  powerpack (0.1.1)
36
- rainbow (2.1.0)
35
+ rainbow (2.2.2)
36
+ rake
37
37
  rake (10.5.0)
38
38
  rspec (3.5.0)
39
39
  rspec-core (~> 3.5.0)
@@ -48,30 +48,33 @@ GEM
48
48
  diff-lcs (>= 1.2.0, < 2.0)
49
49
  rspec-support (~> 3.5.0)
50
50
  rspec-support (3.5.0)
51
- rubocop (0.32.1)
52
- astrolabe (~> 1.3)
53
- parser (>= 2.2.2.5, < 3.0)
51
+ rubocop (0.49.1)
52
+ parallel (~> 1.10)
53
+ parser (>= 2.3.3.1, < 3.0)
54
54
  powerpack (~> 0.1)
55
55
  rainbow (>= 1.99.1, < 3.0)
56
- ruby-progressbar (~> 1.4)
56
+ ruby-progressbar (~> 1.7)
57
+ unicode-display_width (~> 1.0, >= 1.0.1)
57
58
  ruby-progressbar (1.8.1)
58
59
  sqlite3 (1.3.11)
59
- thor (0.19.1)
60
+ thor (0.19.4)
60
61
  thread_safe (0.3.5)
61
62
  tzinfo (1.2.2)
62
63
  thread_safe (~> 0.1)
64
+ unicode-display_width (1.3.0)
63
65
 
64
66
  PLATFORMS
65
67
  ruby
66
68
 
67
69
  DEPENDENCIES
68
- activerecord (= 5.0.0)
69
- appraisal (~> 1.0.3)
70
+ activerecord (~> 5.0)
71
+ appraisal (~> 2.2.0)
72
+ bundler (~> 1.15)
70
73
  calculated_attributes!
71
74
  rake (~> 10.0)
72
75
  rspec (~> 3.1)
73
- rubocop (~> 0.32.0)
76
+ rubocop (~> 0.49.0)
74
77
  sqlite3 (~> 1.3.10)
75
78
 
76
79
  BUNDLED WITH
77
- 1.12.5
80
+ 1.15.1
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.1"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ calculated_attributes (0.2.0)
5
+ activerecord (>= 3.2.20)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (5.1.2)
11
+ activesupport (= 5.1.2)
12
+ activerecord (5.1.2)
13
+ activemodel (= 5.1.2)
14
+ activesupport (= 5.1.2)
15
+ arel (~> 8.0)
16
+ activesupport (5.1.2)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (~> 0.7)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ appraisal (2.2.0)
22
+ bundler
23
+ rake
24
+ thor (>= 0.14.0)
25
+ arel (8.0.0)
26
+ ast (2.3.0)
27
+ concurrent-ruby (1.0.5)
28
+ diff-lcs (1.3)
29
+ i18n (0.8.6)
30
+ 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
37
+ rake (10.5.0)
38
+ rspec (3.6.0)
39
+ rspec-core (~> 3.6.0)
40
+ rspec-expectations (~> 3.6.0)
41
+ rspec-mocks (~> 3.6.0)
42
+ rspec-core (3.6.0)
43
+ rspec-support (~> 3.6.0)
44
+ rspec-expectations (3.6.0)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.6.0)
47
+ rspec-mocks (3.6.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.6.0)
50
+ rspec-support (3.6.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.13)
60
+ thor (0.19.4)
61
+ thread_safe (0.3.6)
62
+ tzinfo (1.2.3)
63
+ thread_safe (~> 0.1)
64
+ unicode-display_width (1.3.0)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ activerecord (~> 5.1)
71
+ appraisal (~> 2.2.0)
72
+ bundler (~> 1.15)
73
+ calculated_attributes!
74
+ rake (~> 10.0)
75
+ rspec (~> 3.1)
76
+ rubocop (~> 0.49.0)
77
+ sqlite3 (~> 1.3.10)
78
+
79
+ BUNDLED WITH
80
+ 1.15.1
@@ -1,5 +1,7 @@
1
- class Arel::SelectManager
2
- def projections
3
- @ctx.projections
1
+ module Arel
2
+ class SelectManager
3
+ def projections
4
+ @ctx.projections
5
+ end
4
6
  end
5
7
  end
@@ -17,78 +17,82 @@ module CalculatedAttributes
17
17
  end
18
18
  ActiveRecord::Base.extend CalculatedAttributes
19
19
 
20
- class ActiveRecord::Base
21
- def calculated(*args)
22
- if self.class.respond_to? :scoped
23
- self.class.scoped.calculated(*args).find(id)
24
- else
25
- self.class.all.calculated(*args).find(id)
26
- end
27
- end
28
-
29
- def method_missing(sym, *args, &block)
30
- no_sym_in_attr =
31
- if @attributes.respond_to? :include?
32
- !@attributes.include?(sym.to_s)
20
+ module ActiveRecord
21
+ class Base
22
+ def calculated(*args)
23
+ if self.class.respond_to? :scoped
24
+ self.class.scoped.calculated(*args).find(id)
33
25
  else
34
- !@attributes.key?(sym.to_s)
26
+ self.class.all.calculated(*args).find(id)
35
27
  end
36
- if no_sym_in_attr && (self.class.calculated.calculated[sym] || self.class.base_class.calculated.calculated[sym])
37
- Rails.logger.warn("Using calculated value without including it in the relation: #{sym}") if defined? Rails
38
- class_with_attr =
39
- if self.class.calculated.calculated[sym]
40
- self.class
28
+ end
29
+
30
+ def method_missing(sym, *args)
31
+ no_sym_in_attr =
32
+ if @attributes.respond_to? :include?
33
+ !@attributes.include?(sym.to_s)
34
+ else
35
+ !@attributes.key?(sym.to_s)
36
+ end
37
+ if no_sym_in_attr && (self.class.calculated.calculated[sym] || self.class.base_class.calculated.calculated[sym])
38
+ Rails.logger.warn("Using calculated value without including it in the relation: #{sym}") if defined? Rails
39
+ class_with_attr =
40
+ if self.class.calculated.calculated[sym]
41
+ self.class
42
+ else
43
+ self.class.base_class
44
+ end
45
+ if class_with_attr.respond_to? :scoped
46
+ class_with_attr.scoped.calculated(sym => args).find(id).send(sym)
41
47
  else
42
- self.class.base_class
48
+ class_with_attr.all.calculated(sym => args).find(id).send(sym)
43
49
  end
44
- if class_with_attr.respond_to? :scoped
45
- class_with_attr.scoped.calculated(sym => args).find(id).send(sym)
46
50
  else
47
- class_with_attr.all.calculated(sym => args).find(id).send(sym)
51
+ super
48
52
  end
49
- else
50
- super(sym, *args, &block)
51
53
  end
52
- end
53
54
 
54
- def respond_to?(method, include_private = false)
55
- no_sym_in_attr =
56
- if @attributes.respond_to? :include?
57
- !@attributes.include?(method.to_s)
58
- elsif @attributes.respond_to? :key?
59
- !@attributes.key?(method.to_s)
60
- else
61
- true
62
- end
63
- super || (no_sym_in_attr && (self.class.calculated.calculated[method] || self.class.base_class.calculated.calculated[method]))
55
+ def respond_to_missing?(method, include_private = false)
56
+ no_sym_in_attr =
57
+ if @attributes.respond_to? :include?
58
+ !@attributes.include?(method.to_s)
59
+ elsif @attributes.respond_to? :key?
60
+ !@attributes.key?(method.to_s)
61
+ else
62
+ true
63
+ end
64
+ super || (no_sym_in_attr && (self.class.calculated.calculated[method] || self.class.base_class.calculated.calculated[method]))
65
+ end
64
66
  end
65
67
  end
66
68
 
67
- class ActiveRecord::Relation
68
- def calculated(*args)
69
- projections = arel.projections
70
- args = args.flat_map do |arg|
71
- case arg
72
- when Symbol then [[arg, []]]
73
- when Hash then arg.to_a
69
+ module ActiveRecord
70
+ class Relation
71
+ def calculated(*args)
72
+ projections = arel.projections
73
+ args = args.flat_map do |arg|
74
+ case arg
75
+ when Symbol then [[arg, []]]
76
+ when Hash then arg.to_a
77
+ end
74
78
  end
75
- end
76
79
 
77
- args.each do |attribute, arguments|
78
- lam = klass.calculated.calculated[attribute] || klass.base_class.calculated.calculated[attribute]
79
- sql = lam.call(*arguments)
80
- sql = klass.send(:sanitize_sql, *sql) if sql.is_a?(Array)
81
- new_projection =
82
- if sql.is_a?(String)
83
- Arel.sql("(#{sql})").as(attribute.to_s)
84
- elsif sql.respond_to? :to_sql
85
- Arel.sql("(#{sql.to_sql})").as(attribute.to_s)
86
- else
87
- sql.as(attribute.to_s)
88
- end
89
- new_projection.calculated_attr!
90
- projections.push new_projection
80
+ args.each do |attribute, arguments|
81
+ lam = klass.calculated.calculated[attribute] || klass.base_class.calculated.calculated[attribute]
82
+ sql = lam.call(*arguments)
83
+ sql = klass.send(:sanitize_sql, *sql) if sql.is_a?(Array)
84
+ new_projection =
85
+ if sql.is_a?(String)
86
+ Arel.sql("(#{sql})").as(attribute.to_s)
87
+ elsif sql.respond_to? :to_sql
88
+ Arel.sql("(#{sql.to_sql})").as(attribute.to_s)
89
+ else
90
+ sql.as(attribute.to_s)
91
+ end
92
+ new_projection.calculated_attr!
93
+ projections.push new_projection
94
+ end
95
+ select(projections)
91
96
  end
92
- select(projections)
93
97
  end
94
98
  end
@@ -9,27 +9,6 @@ module ActiveRecord
9
9
  end
10
10
  end
11
11
 
12
- module ActiveRecord
13
- module AttributeMethods
14
- module Write
15
- # Updates the attribute identified by <tt>attr_name</tt> with the specified +value+. Empty strings
16
- # for fixnum and float columns are turned into +nil+.
17
- def write_attribute(attr_name, value)
18
- if ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 2 || ActiveRecord::VERSION::MAJOR == 5
19
- write_attribute_with_type_cast(attr_name, value, true)
20
- else
21
- attr_name = attr_name.to_s
22
- attr_name = self.class.primary_key if attr_name == 'id' && self.class.primary_key
23
- @attributes_cache.delete(attr_name)
24
- column = column_for_attribute(attr_name)
25
-
26
- @attributes[attr_name] = type_cast_attribute_for_write(column, value)
27
- end
28
- end
29
- end
30
- end
31
- end
32
-
33
12
  module Arel
34
13
  module Nodes
35
14
  class Node
@@ -1,3 +1,3 @@
1
1
  module CalculatedAttributes
2
- VERSION = '0.1.5'
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -4,7 +4,7 @@ require 'active_record'
4
4
  # Include patches.
5
5
  require 'calculated_attributes/rails_patches'
6
6
  require 'calculated_attributes/arel_patches'
7
- fail "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].include? ActiveRecord::VERSION::MAJOR
8
8
  require "calculated_attributes/rails_#{ActiveRecord::VERSION::MAJOR}_patches"
9
9
 
10
10
  # Include model code.
@@ -119,11 +119,12 @@ describe 'calculated_attributes' do
119
119
 
120
120
  context 'when eager loading models' do
121
121
  it 'includes calculated attributes' do
122
- scope = case ActiveRecord::VERSION::MAJOR
123
- when 5 then model_scoped(Post).includes(:comments).references(:comments)
124
- when 4 then model_scoped(Post).includes(:comments).references(:comments)
125
- when 3 then model_scoped(Post).eager_load(:comments)
126
- end
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
127
128
  expect(scope.first.comments_count).to eq(1)
128
129
  end
129
130
  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.1.5
4
+ version: 0.2.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: 2016-09-09 00:00:00.000000000 Z
11
+ date: 2017-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.3
19
+ version: 2.2.0
20
20
  type: :development
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: 1.0.3
26
+ version: 2.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +72,14 @@ dependencies:
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: 0.32.0
75
+ version: 0.49.0
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: 0.32.0
82
+ version: 0.49.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: sqlite3
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -101,6 +115,7 @@ executables: []
101
115
  extensions: []
102
116
  extra_rdoc_files: []
103
117
  files:
118
+ - ".circleci/config.yml"
104
119
  - ".gitignore"
105
120
  - ".rspec"
106
121
  - ".rubocop.yml"
@@ -111,7 +126,6 @@ files:
111
126
  - README.md
112
127
  - Rakefile
113
128
  - calculated_attributes.gemspec
114
- - circle.yml
115
129
  - gemfiles/rails3.gemfile
116
130
  - gemfiles/rails3.gemfile.lock
117
131
  - gemfiles/rails4_1.gemfile
@@ -120,6 +134,8 @@ files:
120
134
  - gemfiles/rails4_2.gemfile.lock
121
135
  - gemfiles/rails5_0.gemfile
122
136
  - gemfiles/rails5_0.gemfile.lock
137
+ - gemfiles/rails5_1.gemfile
138
+ - gemfiles/rails5_1.gemfile.lock
123
139
  - lib/calculated_attributes.rb
124
140
  - lib/calculated_attributes/arel_patches.rb
125
141
  - lib/calculated_attributes/model_methods.rb
data/circle.yml DELETED
@@ -1,3 +0,0 @@
1
- database:
2
- override:
3
- - echo "no database setup"