calculated_attributes 0.2.0 → 0.3.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 +4 -4
- data/.rubocop.yml +1 -0
- data/Appraisals +4 -0
- data/gemfiles/rails3.gemfile.lock +2 -2
- data/gemfiles/rails4_1.gemfile.lock +2 -2
- data/gemfiles/rails4_2.gemfile.lock +2 -2
- data/gemfiles/rails5_0.gemfile.lock +2 -2
- data/gemfiles/rails5_1.gemfile.lock +2 -2
- data/gemfiles/rails5_2.gemfile +7 -0
- data/gemfiles/rails5_2.gemfile.lock +81 -0
- data/lib/calculated_attributes/rails_5_2_patches.rb +65 -0
- data/lib/calculated_attributes/version.rb +1 -1
- data/lib/calculated_attributes.rb +6 -1
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 954ce2e582490fe3654d1d193bf8788b2a8e27df
|
|
4
|
+
data.tar.gz: 3fba4d9c4d1c4efbf988c9280d6af0b8b2fc7905
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6128772777526edf97a6fa6633adc8a643770a2e129054cb4aa74890a1cae3429f41fb3cf7bfb8c881bce79aeea304a3852d0fbb042cc2528e8e868f11a78266
|
|
7
|
+
data.tar.gz: 2d711c3c87b4cca7f71a1f512cd5e3de33b6c694664dee1e6cf2f2065ef3659c988732d74dfd20e42e9ba9819fdf664cc0b2a80a9533f96e657fd7939be94379
|
data/.rubocop.yml
CHANGED
data/Appraisals
CHANGED
|
@@ -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
|
|
@@ -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
|
-
|
|
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.
|
|
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:
|
|
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.
|
|
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.
|