difference 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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'activerecord'
4
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "difference/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "difference"
7
+ s.version = Difference::VERSION
8
+ s.authors = ["Manish Puri"]
9
+ s.email = ["manishspuri@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{difference between 2 objects}
12
+ s.description = %q{This is a simple gem to compare 2 objects of the same class and return a hash of differences}
13
+
14
+ s.rubyforge_project = "difference"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
@@ -0,0 +1,3 @@
1
+ module Difference
2
+ VERSION = "1.0.0"
3
+ end
data/lib/difference.rb ADDED
@@ -0,0 +1,22 @@
1
+ require "difference/version"
2
+
3
+ module Difference
4
+ class ActiveRecord::Base
5
+ def differs_from(object,opt={})
6
+ return "We cannot compare objects of different classes" if self.class.name != object.class.name
7
+
8
+ # Set attribute list to compare.
9
+ diff={}
10
+ attr_list =self.attributes.keys
11
+ attr_list= attr_list - opt[:ignore_attributes].to_a if opt[:ignore_attributes].present?
12
+ attr_list= opt[:only_attributes].to_a if opt[:only_attributes].present?
13
+
14
+
15
+ attr_list.each do |attr|
16
+ (diff[attr.to_sym] = [self[attr],object[attr]]) if self[attr] != object[attr]
17
+ end
18
+ diff
19
+ end
20
+ end
21
+
22
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: difference
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Manish Puri
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-04-28 00:00:00 +05:30
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: This is a simple gem to compare 2 objects of the same class and return a hash of differences
23
+ email:
24
+ - manishspuri@gmail.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Rakefile
35
+ - difference.gemspec
36
+ - lib/difference.rb
37
+ - lib/difference/version.rb
38
+ has_rdoc: true
39
+ homepage: ""
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ hash: 3
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project: difference
68
+ rubygems_version: 1.5.3
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: difference between 2 objects
72
+ test_files: []
73
+