active_record_attributes_equality 1.0.0.rc

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Diogo Almeida
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ ## Introduction
2
+
3
+ Active Record Attributes Equality is a very simple rails plugin / gem that forces ActiveRecord to compare the mode's attributes in the presence of two new records.
4
+
5
+
6
+ ## Example
7
+
8
+ Consider a User model that holds the notion of users that have a name.
9
+
10
+ # create_table(:user, :force => true) do |t|
11
+ # t.string :name, null => false
12
+ # end
13
+ class User < ActiveRecord::Base; end
14
+
15
+ Default ActiveRecord behavior:
16
+
17
+ User.new(:name => "John") == User.new(:name => "John") #=> false
18
+
19
+ Introduce ActiveRecordAttributesEquality and that same instruction will return true:
20
+
21
+ User.new(:name => "John") == User.new(:name => "John") #=> true
22
+
23
+
24
+ ## Feedback, questions, improvements, critics or just say hi
25
+
26
+ Feel free to fork the project and to send pull requests with your changes. Should you run into problems, please use the issue tracker made available in this Github project.
27
+
28
+
29
+ ## License
30
+
31
+ Copyright (c) 2010 Gnomeslab, released under the MIT license. For more information regarding this license type please check the MIT-LICENSE file.
@@ -0,0 +1,26 @@
1
+ # Module containing the attributes equality logic.
2
+ module ActiveRecordAttributesEquality
3
+
4
+ # When included, the object including this module, will be issued a class eval in order to load the attributes
5
+ # equallity logic.
6
+ def self.included(klass)
7
+ klass.class_eval do
8
+ # Overriding ActiveRecord::Base equality method, forcing it to look at the attributes hash whenever two new
9
+ # new records are being compared.
10
+ #
11
+ # If the objects being compared are not new records, this method fallsback to +ActiveRecord::Base#==+
12
+ def ==(other)
13
+ return false unless other.is_a? self.class
14
+
15
+ if self.new_record? && other.new_record?
16
+ self.attributes == other.attributes
17
+ else
18
+ super(other)
19
+ end
20
+ end
21
+ end
22
+ end # included
23
+
24
+ end # ActiveRecordAttributesEquality
25
+
26
+ ActiveRecord::Base.send :include, ActiveRecordAttributesEquality
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_record_attributes_equality
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ - rc
10
+ version: 1.0.0.rc
11
+ platform: ruby
12
+ authors:
13
+ - Diogo Almeida
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-30 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activerecord
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ segments:
30
+ - 3
31
+ - 0
32
+ - 0
33
+ - rc
34
+ version: 3.0.0.rc
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Active Record Attributes Equality is a very simple rails plugin / gem that forces ActiveRecord to compare the mode's attributes in the presence of two new records.
38
+ email:
39
+ - diogo.almeida@gnomeslab.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - lib/active_record_attributes_equality.rb
48
+ - MIT-LICENSE
49
+ - README.md
50
+ has_rdoc: true
51
+ homepage: http://github.com/GnomesLab/active_record_attributes_equality/
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ segments:
65
+ - 0
66
+ version: "0"
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ segments:
73
+ - 1
74
+ - 3
75
+ - 7
76
+ version: 1.3.7
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.7
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Forces ActiveRecord::Base equality to look into the attributes hash.
84
+ test_files: []
85
+