assignable_values 0.13.1 → 0.13.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +7 -0
- data/gemfiles/Gemfile.3.2.lock +1 -1
- data/gemfiles/Gemfile.4.2.lock +2 -2
- data/gemfiles/Gemfile.5.0.lock +2 -2
- data/gemfiles/Gemfile.5.1.lock +2 -2
- data/lib/assignable_values/active_record/restriction/belongs_to_association.rb +14 -2
- data/lib/assignable_values/active_record/restriction/scalar_attribute.rb +14 -2
- data/lib/assignable_values/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80416120490eb1fa174ee1af4318c93ce18fd432
|
4
|
+
data.tar.gz: e4379495924e83d42bb9b610b9adef3ba4ca3b01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efb7a94db723785ea7e3eab7c2a8919aa32cd16441c3f4b60d63d7463f63720a35d2f46c97fb81dd7c876d55337f7982f6a9fc525905401393abbf56fe94dedf
|
7
|
+
data.tar.gz: d7094fe9d1419a44aa156e3b315ffcb981b449b1c419a8e5d52500389d2be0bbf14ab7cc8db79cca895931ac3a3027556de7a8d58957ac98001b822074f9209e
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1
|
1
|
+
2.3.1
|
data/.travis.yml
CHANGED
@@ -4,6 +4,7 @@ rvm:
|
|
4
4
|
- 1.8.7
|
5
5
|
- 2.1.8
|
6
6
|
- 2.3.1
|
7
|
+
- 2.4.2
|
7
8
|
|
8
9
|
gemfile:
|
9
10
|
- gemfiles/Gemfile.2.3
|
@@ -18,10 +19,16 @@ matrix:
|
|
18
19
|
rvm: 2.1.8
|
19
20
|
- gemfile: gemfiles/Gemfile.2.3
|
20
21
|
rvm: 2.3.1
|
22
|
+
- gemfile: gemfiles/Gemfile.2.3
|
23
|
+
rvm: 2.4.2
|
21
24
|
- gemfile: gemfiles/Gemfile.3.2
|
22
25
|
rvm: 2.3.1
|
26
|
+
- gemfile: gemfiles/Gemfile.3.2
|
27
|
+
rvm: 2.4.2
|
23
28
|
- gemfile: gemfiles/Gemfile.4.2
|
24
29
|
rvm: 1.8.7
|
30
|
+
- gemfile: gemfiles/Gemfile.4.2
|
31
|
+
rvm: 2.4.2
|
25
32
|
- gemfile: gemfiles/Gemfile.5.0
|
26
33
|
rvm: 2.1.8
|
27
34
|
- gemfile: gemfiles/Gemfile.5.0
|
data/gemfiles/Gemfile.3.2.lock
CHANGED
data/gemfiles/Gemfile.4.2.lock
CHANGED
data/gemfiles/Gemfile.5.0.lock
CHANGED
data/gemfiles/Gemfile.5.1.lock
CHANGED
@@ -27,11 +27,15 @@ module AssignableValues
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def has_previously_saved_value?(record)
|
30
|
-
|
30
|
+
if record.respond_to?(:attribute_in_database)
|
31
|
+
!record.new_record? # Rails >= 5.1
|
32
|
+
else
|
33
|
+
!record.new_record? && record.respond_to?(association_id_was_method) # Rails <= 5.0
|
34
|
+
end
|
31
35
|
end
|
32
36
|
|
33
37
|
def previously_saved_value(record)
|
34
|
-
if old_id = record
|
38
|
+
if old_id = association_id_was(record)
|
35
39
|
if old_id == association_id(record)
|
36
40
|
current_value(record) # no need to query the database if nothing changed
|
37
41
|
else
|
@@ -46,6 +50,14 @@ module AssignableValues
|
|
46
50
|
|
47
51
|
private
|
48
52
|
|
53
|
+
def association_id_was(record)
|
54
|
+
if record.respond_to?(:attribute_in_database)
|
55
|
+
record.attribute_in_database(:"#{association_id_method}").presence # Rails >= 5.1
|
56
|
+
else
|
57
|
+
record.send(association_id_was_method).presence # Rails <= 5.0
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
49
61
|
def association_id_was_method
|
50
62
|
:"#{association_id_method}_was"
|
51
63
|
end
|
@@ -75,15 +75,27 @@ module AssignableValues
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def has_previously_saved_value?(record)
|
78
|
-
|
78
|
+
if record.respond_to?(:attribute_in_database)
|
79
|
+
!record.new_record? # Rails >= 5.1
|
80
|
+
else
|
81
|
+
!record.new_record? && record.respond_to?(value_was_method) # Rails <= 5.0
|
82
|
+
end
|
79
83
|
end
|
80
84
|
|
81
85
|
def previously_saved_value(record)
|
82
|
-
record
|
86
|
+
value_was(record)
|
83
87
|
end
|
84
88
|
|
85
89
|
private
|
86
90
|
|
91
|
+
def value_was(record)
|
92
|
+
if record.respond_to?(:attribute_in_database)
|
93
|
+
record.attribute_in_database(:"#{property}") # Rails >= 5.1
|
94
|
+
else
|
95
|
+
record.send(value_was_method) # Rails <= 5.0
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
87
99
|
def value_was_method
|
88
100
|
:"#{property}_was"
|
89
101
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assignable_values
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henning Koch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -100,4 +100,3 @@ test_files:
|
|
100
100
|
- spec/support/database.travis.yml
|
101
101
|
- spec/support/i18n.yml
|
102
102
|
- spec/support/models.rb
|
103
|
-
has_rdoc:
|