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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c64f8e5f3fa58f5d618e5f38b34700b78c7448e1
4
- data.tar.gz: b90a4dc2764d21648b4a05aacc82df635d66c344
3
+ metadata.gz: 80416120490eb1fa174ee1af4318c93ce18fd432
4
+ data.tar.gz: e4379495924e83d42bb9b610b9adef3ba4ca3b01
5
5
  SHA512:
6
- metadata.gz: 4775a81d5bf1cf18e5b91aa4bebe4f0115f304a23d8c64430f38239cf32df51b7ca9b60b0a8d053d206886c2c279249ea01067dd11ea05e89006dfac33fbf687
7
- data.tar.gz: 3681d4acbc2c467654806b955aa12d3e5325442ef02dfec8409b3ce9329c2d0478e701ecc64f8bd48c9569929fb526f952229b0f2563cc6c258d2f4e3cd8b920
6
+ metadata.gz: efb7a94db723785ea7e3eab7c2a8919aa32cd16441c3f4b60d63d7463f63720a35d2f46c97fb81dd7c876d55337f7982f6a9fc525905401393abbf56fe94dedf
7
+ data.tar.gz: d7094fe9d1419a44aa156e3b315ffcb981b449b1c419a8e5d52500389d2be0bbf14ab7cc8db79cca895931ac3a3027556de7a8d58957ac98001b822074f9209e
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.8
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- assignable_values (0.13.1)
4
+ assignable_values (0.13.2)
5
5
  activerecord (>= 2.3)
6
6
 
7
7
  GEM
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- assignable_values (0.13.1)
4
+ assignable_values (0.13.2)
5
5
  activerecord (>= 2.3)
6
6
 
7
7
  GEM
@@ -67,4 +67,4 @@ DEPENDENCIES
67
67
  rspec_candy
68
68
 
69
69
  BUNDLED WITH
70
- 1.15.4
70
+ 1.16.1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- assignable_values (0.13.1)
4
+ assignable_values (0.13.2)
5
5
  activerecord (>= 2.3)
6
6
 
7
7
  GEM
@@ -64,4 +64,4 @@ DEPENDENCIES
64
64
  rspec_candy
65
65
 
66
66
  BUNDLED WITH
67
- 1.15.4
67
+ 1.16.1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- assignable_values (0.13.1)
4
+ assignable_values (0.13.2)
5
5
  activerecord (>= 2.3)
6
6
 
7
7
  GEM
@@ -65,4 +65,4 @@ DEPENDENCIES
65
65
  rspec_candy
66
66
 
67
67
  BUNDLED WITH
68
- 1.15.4
68
+ 1.16.1
@@ -27,11 +27,15 @@ module AssignableValues
27
27
  end
28
28
 
29
29
  def has_previously_saved_value?(record)
30
- !record.new_record? && record.respond_to?(association_id_was_method)
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.send(association_id_was_method).presence
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
- !record.new_record? && record.respond_to?(value_was_method)
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.send(value_was_method)
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
@@ -1,3 +1,3 @@
1
1
  module AssignableValues
2
- VERSION = '0.13.1'
2
+ VERSION = '0.13.2'
3
3
  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.1
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: 2017-10-24 00:00:00.000000000 Z
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: