active_record_attributes_equality 1.0.0.rc.2 → 1.0.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.
- data/lib/active_record_attributes_equality.rb +11 -5
- metadata +4 -6
@@ -1,26 +1,32 @@
|
|
1
|
+
require 'active_record' unless defined? ActiveRecord
|
2
|
+
|
1
3
|
# Module containing the attributes equality logic.
|
2
4
|
module ActiveRecordAttributesEquality
|
3
5
|
|
4
6
|
# When included, the object including this module, will be issued a class eval in order to load the attributes
|
5
7
|
# equallity logic.
|
6
8
|
def self.included(klass)
|
9
|
+
|
7
10
|
klass.class_eval do
|
11
|
+
|
8
12
|
# Overriding ActiveRecord::Base equality method, forcing it to look at the attributes hash whenever two new
|
9
13
|
# new records are being compared.
|
10
14
|
#
|
11
|
-
# If the objects being compared are not new records,
|
15
|
+
# If the objects being compared are not new records, like +ActiveRecord::Base#==+ the ID of both is compared.
|
12
16
|
def ==(other)
|
13
17
|
return false unless other.is_a? self.class
|
14
18
|
|
15
19
|
if self.new_record? && other.new_record?
|
16
20
|
self.attributes == other.attributes
|
17
21
|
else
|
18
|
-
|
22
|
+
self.id == other.id
|
19
23
|
end
|
20
|
-
end
|
21
|
-
|
24
|
+
end # ==
|
25
|
+
|
26
|
+
end # eval
|
27
|
+
|
22
28
|
end # included
|
23
29
|
|
24
30
|
end # ActiveRecordAttributesEquality
|
25
31
|
|
26
|
-
ActiveRecord::Base.send :include, ActiveRecordAttributesEquality
|
32
|
+
ActiveRecord::Base.send :include, ActiveRecordAttributesEquality
|
metadata
CHANGED
@@ -1,14 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_attributes_equality
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
|
10
|
-
- 2
|
11
|
-
version: 1.0.0.rc.2
|
9
|
+
version: 1.0.0
|
12
10
|
platform: ruby
|
13
11
|
authors:
|
14
12
|
- Diogo Almeida
|
@@ -16,7 +14,7 @@ autorequire:
|
|
16
14
|
bindir: bin
|
17
15
|
cert_chain: []
|
18
16
|
|
19
|
-
date: 2010-07-
|
17
|
+
date: 2010-07-31 00:00:00 +01:00
|
20
18
|
default_executable:
|
21
19
|
dependencies:
|
22
20
|
- !ruby/object:Gem::Dependency
|
@@ -35,7 +33,7 @@ dependencies:
|
|
35
33
|
version: 3.0.0.rc
|
36
34
|
type: :runtime
|
37
35
|
version_requirements: *id001
|
38
|
-
description: Active Record Attributes Equality is a very simple rails plugin / gem that forces ActiveRecord to compare the model's attributes in the presence of two new records. Otherwise, it
|
36
|
+
description: Active Record Attributes Equality is a very simple rails plugin / gem that forces ActiveRecord to compare the model's attributes in the presence of two new records. Otherwise, it compares their IDs, just like ActiveRecord::Base#==.
|
39
37
|
email:
|
40
38
|
- diogo.almeida@gnomeslab.com
|
41
39
|
executables: []
|