calculated_attributes 0.1.4 → 0.1.5

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: 31b050a3311b7b6c70f23b201f4761b103b6137f
4
- data.tar.gz: 875255b28e9c8e597b4bf0d912f3f02283544d18
3
+ metadata.gz: a0940be8c91d38d2aec6592df3ab0ecb9d45cff3
4
+ data.tar.gz: 9d497e3a163e7447892aa73e81b0b647fa16d8ec
5
5
  SHA512:
6
- metadata.gz: 9dd904985c4d11aa47ecbc53e90b9500f5a427437ec934e8666ffdb29db88c129151843899f93dad9dc6f9aa884903933ad529b0f5bf03c8e15ad5a23e718f18
7
- data.tar.gz: 493f1937397278a71be5743c39160f12582ebe30a93530de9e9138454423e475259fc72e0d1c26d800314a4a5b39f7d956443855827bd014c9a05bc2658c54c2
6
+ metadata.gz: 195341ee43dcb6b87fd1ca1a45c9c5eb41f26ad3bd9479c8aabc3cd96e131d1b5671276a20767f99d43e0c3c136d2b5188d988e481afa5045b21641956d7c50c
7
+ data.tar.gz: f9634c6a9762bfc550001d92b98f112dbcc51397e5f81f0e0fcbd4ca36508f45a28cd0d12ece28ab40919add24740c26b04f78bfe8f2cec193485db93c824483
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.3.1
data/Appraisals CHANGED
@@ -9,3 +9,7 @@ end
9
9
  appraise 'rails4_2' do
10
10
  gem 'activerecord', '4.2.2'
11
11
  end
12
+
13
+ appraise 'rails5_0' do
14
+ gem 'activerecord', '5.0.0'
15
+ end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- calculated_attributes (0.1.4)
4
+ calculated_attributes (0.1.5)
5
5
  activerecord (>= 3.2.20)
6
6
 
7
7
  GEM
@@ -72,4 +72,4 @@ DEPENDENCIES
72
72
  sqlite3 (~> 1.3.10)
73
73
 
74
74
  BUNDLED WITH
75
- 1.11.2
75
+ 1.12.5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- calculated_attributes (0.1.4)
4
+ calculated_attributes (0.1.5)
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.11.2
80
+ 1.12.5
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../
3
3
  specs:
4
- calculated_attributes (0.1.4)
4
+ calculated_attributes (0.1.5)
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.11.2
80
+ 1.12.5
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "5.0.0"
6
+
7
+ gemspec :path => "../"
@@ -0,0 +1,77 @@
1
+ PATH
2
+ remote: ../
3
+ specs:
4
+ calculated_attributes (0.1.5)
5
+ activerecord (>= 3.2.20)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (5.0.0)
11
+ activesupport (= 5.0.0)
12
+ activerecord (5.0.0)
13
+ activemodel (= 5.0.0)
14
+ activesupport (= 5.0.0)
15
+ arel (~> 7.0)
16
+ activesupport (5.0.0)
17
+ concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ i18n (~> 0.7)
19
+ minitest (~> 5.1)
20
+ tzinfo (~> 1.1)
21
+ appraisal (1.0.3)
22
+ bundler
23
+ rake
24
+ thor (>= 0.14.0)
25
+ arel (7.1.1)
26
+ ast (2.3.0)
27
+ astrolabe (1.3.1)
28
+ parser (~> 2.2)
29
+ concurrent-ruby (1.0.2)
30
+ diff-lcs (1.2.5)
31
+ i18n (0.7.0)
32
+ minitest (5.9.0)
33
+ parser (2.3.1.2)
34
+ ast (~> 2.2)
35
+ powerpack (0.1.1)
36
+ rainbow (2.1.0)
37
+ rake (10.5.0)
38
+ rspec (3.5.0)
39
+ rspec-core (~> 3.5.0)
40
+ rspec-expectations (~> 3.5.0)
41
+ rspec-mocks (~> 3.5.0)
42
+ rspec-core (3.5.3)
43
+ rspec-support (~> 3.5.0)
44
+ rspec-expectations (3.5.0)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.5.0)
47
+ rspec-mocks (3.5.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.5.0)
50
+ rspec-support (3.5.0)
51
+ rubocop (0.32.1)
52
+ astrolabe (~> 1.3)
53
+ parser (>= 2.2.2.5, < 3.0)
54
+ powerpack (~> 0.1)
55
+ rainbow (>= 1.99.1, < 3.0)
56
+ ruby-progressbar (~> 1.4)
57
+ ruby-progressbar (1.8.1)
58
+ sqlite3 (1.3.11)
59
+ thor (0.19.1)
60
+ thread_safe (0.3.5)
61
+ tzinfo (1.2.2)
62
+ thread_safe (~> 0.1)
63
+
64
+ PLATFORMS
65
+ ruby
66
+
67
+ DEPENDENCIES
68
+ activerecord (= 5.0.0)
69
+ appraisal (~> 1.0.3)
70
+ calculated_attributes!
71
+ rake (~> 10.0)
72
+ rspec (~> 3.1)
73
+ rubocop (~> 0.32.0)
74
+ sqlite3 (~> 1.3.10)
75
+
76
+ BUNDLED WITH
77
+ 1.12.5
@@ -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, aliases)
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)
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
@@ -15,7 +15,7 @@ module ActiveRecord
15
15
  # Updates the attribute identified by <tt>attr_name</tt> with the specified +value+. Empty strings
16
16
  # for fixnum and float columns are turned into +nil+.
17
17
  def write_attribute(attr_name, value)
18
- if ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 2
18
+ if ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 2 || ActiveRecord::VERSION::MAJOR == 5
19
19
  write_attribute_with_type_cast(attr_name, value, true)
20
20
  else
21
21
  attr_name = attr_name.to_s
@@ -1,3 +1,3 @@
1
1
  module CalculatedAttributes
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.5'
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].include? ActiveRecord::VERSION::MAJOR
7
+ fail "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.
@@ -120,6 +120,7 @@ describe 'calculated_attributes' do
120
120
  context 'when eager loading models' do
121
121
  it 'includes calculated attributes' do
122
122
  scope = case ActiveRecord::VERSION::MAJOR
123
+ when 5 then model_scoped(Post).includes(:comments).references(:comments)
123
124
  when 4 then model_scoped(Post).includes(:comments).references(:comments)
124
125
  when 3 then model_scoped(Post).eager_load(:comments)
125
126
  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.4
4
+ version: 0.1.5
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-06-02 00:00:00.000000000 Z
11
+ date: 2016-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appraisal
@@ -118,11 +118,14 @@ files:
118
118
  - gemfiles/rails4_1.gemfile.lock
119
119
  - gemfiles/rails4_2.gemfile
120
120
  - gemfiles/rails4_2.gemfile.lock
121
+ - gemfiles/rails5_0.gemfile
122
+ - gemfiles/rails5_0.gemfile.lock
121
123
  - lib/calculated_attributes.rb
122
124
  - lib/calculated_attributes/arel_patches.rb
123
125
  - lib/calculated_attributes/model_methods.rb
124
126
  - lib/calculated_attributes/rails_3_patches.rb
125
127
  - lib/calculated_attributes/rails_4_patches.rb
128
+ - lib/calculated_attributes/rails_5_patches.rb
126
129
  - lib/calculated_attributes/rails_patches.rb
127
130
  - lib/calculated_attributes/version.rb
128
131
  - spec/lib/calculated_attributes_spec.rb