calculated_attributes 0.2.0 → 0.3.0

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
  SHA1:
3
- metadata.gz: 1c3bf23247f51652ecb2a074be62c27c5a1d9a20
4
- data.tar.gz: f3d08403e2e8fdf7ad6cf2edabebc2ce2e81dd23
3
+ metadata.gz: 954ce2e582490fe3654d1d193bf8788b2a8e27df
4
+ data.tar.gz: 3fba4d9c4d1c4efbf988c9280d6af0b8b2fc7905
5
5
  SHA512:
6
- metadata.gz: ec8f02c57c71a0753fbc235d19510d21dc120131dfbcc593becd70c966be90a34542ff11593389397e82e071c3cff02647b48b3a7b5ec9c40d932bd16fd6d666
7
- data.tar.gz: b4b53833e117d6795d498ca0698f75d74853dfec32d5d10cf15035b4befbadee7961dc54fe3aab3c49cf7a7adbb2e9ded25bb5c8349ad6d98b6b394f8b5571c2
6
+ metadata.gz: 6128772777526edf97a6fa6633adc8a643770a2e129054cb4aa74890a1cae3429f41fb3cf7bfb8c881bce79aeea304a3852d0fbb042cc2528e8e868f11a78266
7
+ data.tar.gz: 2d711c3c87b4cca7f71a1f512cd5e3de33b6c694664dee1e6cf2f2065ef3659c988732d74dfd20e42e9ba9819fdf664cc0b2a80a9533f96e657fd7939be94379
data/.rubocop.yml CHANGED
@@ -5,6 +5,7 @@ AllCops:
5
5
  - lib/calculated_attributes/rails_3_patches.rb
6
6
  - lib/calculated_attributes/rails_4_patches.rb
7
7
  - lib/calculated_attributes/rails_5_patches.rb
8
+ - lib/calculated_attributes/rails_5_2_patches.rb
8
9
 
9
10
  Metrics/AbcSize:
10
11
  Enabled: false
data/Appraisals CHANGED
@@ -17,3 +17,7 @@ end
17
17
  appraise 'rails5_1' do
18
18
  gem 'activerecord', '~> 5.1'
19
19
  end
20
+
21
+ appraise 'rails5_2' do
22
+ gem 'activerecord', '~> 5.2.0.rc1'
23
+ end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- calculated_attributes (0.2.0)
4
+ calculated_attributes (0.3.0)
5
5
  activerecord (>= 3.2.20)
6
6
 
7
7
  GEM
@@ -75,4 +75,4 @@ DEPENDENCIES
75
75
  sqlite3 (~> 1.3.10)
76
76
 
77
77
  BUNDLED WITH
78
- 1.15.1
78
+ 1.16.1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- calculated_attributes (0.2.0)
4
+ calculated_attributes (0.3.0)
5
5
  activerecord (>= 3.2.20)
6
6
 
7
7
  GEM
@@ -80,4 +80,4 @@ DEPENDENCIES
80
80
  sqlite3 (~> 1.3.10)
81
81
 
82
82
  BUNDLED WITH
83
- 1.15.1
83
+ 1.16.1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- calculated_attributes (0.2.0)
4
+ calculated_attributes (0.3.0)
5
5
  activerecord (>= 3.2.20)
6
6
 
7
7
  GEM
@@ -80,4 +80,4 @@ DEPENDENCIES
80
80
  sqlite3 (~> 1.3.10)
81
81
 
82
82
  BUNDLED WITH
83
- 1.15.1
83
+ 1.16.1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- calculated_attributes (0.2.0)
4
+ calculated_attributes (0.3.0)
5
5
  activerecord (>= 3.2.20)
6
6
 
7
7
  GEM
@@ -77,4 +77,4 @@ DEPENDENCIES
77
77
  sqlite3 (~> 1.3.10)
78
78
 
79
79
  BUNDLED WITH
80
- 1.15.1
80
+ 1.16.1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- calculated_attributes (0.2.0)
4
+ calculated_attributes (0.3.0)
5
5
  activerecord (>= 3.2.20)
6
6
 
7
7
  GEM
@@ -77,4 +77,4 @@ DEPENDENCIES
77
77
  sqlite3 (~> 1.3.10)
78
78
 
79
79
  BUNDLED WITH
80
- 1.15.1
80
+ 1.16.1
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 5.2.0.rc1"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,81 @@
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 (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)
15
+ arel (>= 9.0)
16
+ activesupport (5.2.0.rc1)
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 (9.0.0)
26
+ ast (2.4.0)
27
+ concurrent-ruby (1.0.5)
28
+ diff-lcs (1.3)
29
+ i18n (0.9.5)
30
+ concurrent-ruby (~> 1.0)
31
+ minitest (5.11.3)
32
+ parallel (1.12.1)
33
+ parser (2.5.0.0)
34
+ ast (~> 2.4.0)
35
+ powerpack (0.1.1)
36
+ rainbow (2.2.2)
37
+ rake
38
+ 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)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.7.0)
48
+ rspec-mocks (3.7.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.7.0)
51
+ rspec-support (3.7.1)
52
+ rubocop (0.49.1)
53
+ parallel (~> 1.10)
54
+ parser (>= 2.3.3.1, < 3.0)
55
+ powerpack (~> 0.1)
56
+ rainbow (>= 1.99.1, < 3.0)
57
+ ruby-progressbar (~> 1.7)
58
+ unicode-display_width (~> 1.0, >= 1.0.1)
59
+ ruby-progressbar (1.9.0)
60
+ sqlite3 (1.3.13)
61
+ thor (0.20.0)
62
+ thread_safe (0.3.6)
63
+ tzinfo (1.2.5)
64
+ thread_safe (~> 0.1)
65
+ unicode-display_width (1.3.0)
66
+
67
+ PLATFORMS
68
+ ruby
69
+
70
+ DEPENDENCIES
71
+ activerecord (~> 5.2.0.rc1)
72
+ appraisal (~> 2.2.0)
73
+ bundler (~> 1.15)
74
+ calculated_attributes!
75
+ rake (~> 10.0)
76
+ rspec (~> 3.1)
77
+ rubocop (~> 0.49.0)
78
+ sqlite3 (~> 1.3.10)
79
+
80
+ BUNDLED WITH
81
+ 1.16.1
@@ -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 self == 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
+ column_names.reject { |c| calculated_keys.include? c.intern }
17
+ else
18
+ column_names
19
+ end
20
+ super(columns_to_define)
21
+ @attribute_methods_generated = true
22
+ end
23
+ true
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, result_set, seen, model_cache, aliases)
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.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
@@ -5,7 +5,12 @@ require 'active_record'
5
5
  require 'calculated_attributes/rails_patches'
6
6
  require 'calculated_attributes/arel_patches'
7
7
  raise "Unsupported ActiveRecord version: #{ActiveRecord::VERSION::MAJOR}" unless [3, 4, 5].include? ActiveRecord::VERSION::MAJOR
8
- require "calculated_attributes/rails_#{ActiveRecord::VERSION::MAJOR}_patches"
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
12
+ require 'calculated_attributes/rails_5_2_patches'
13
+ end
9
14
 
10
15
  # Include model code.
11
16
  require 'calculated_attributes/model_methods'
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.2.0
4
+ version: 0.3.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: 2017-07-17 00:00:00.000000000 Z
11
+ date: 2018-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -136,11 +136,14 @@ files:
136
136
  - gemfiles/rails5_0.gemfile.lock
137
137
  - gemfiles/rails5_1.gemfile
138
138
  - gemfiles/rails5_1.gemfile.lock
139
+ - gemfiles/rails5_2.gemfile
140
+ - gemfiles/rails5_2.gemfile.lock
139
141
  - lib/calculated_attributes.rb
140
142
  - lib/calculated_attributes/arel_patches.rb
141
143
  - lib/calculated_attributes/model_methods.rb
142
144
  - lib/calculated_attributes/rails_3_patches.rb
143
145
  - lib/calculated_attributes/rails_4_patches.rb
146
+ - lib/calculated_attributes/rails_5_2_patches.rb
144
147
  - lib/calculated_attributes/rails_5_patches.rb
145
148
  - lib/calculated_attributes/rails_patches.rb
146
149
  - lib/calculated_attributes/version.rb
@@ -169,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
172
  version: '0'
170
173
  requirements: []
171
174
  rubyforge_project:
172
- rubygems_version: 2.5.1
175
+ rubygems_version: 2.6.14
173
176
  signing_key:
174
177
  specification_version: 4
175
178
  summary: Automatically add calculated attributes to ActiveRecord models.