simple-identity 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/simple-identity.rb +18 -1
- data/lib/simple-identity/version.rb +1 -1
- data/simple-identity.gemspec +2 -0
- data/test/spec_simple-identity.rb +12 -0
- metadata +20 -4
data/lib/simple-identity.rb
CHANGED
@@ -1,6 +1,21 @@
|
|
1
|
+
require "forwardablex"
|
1
2
|
require "simple-identity/version"
|
2
3
|
|
3
4
|
module SimpleIdentity
|
5
|
+
extend ForwardableX
|
6
|
+
|
7
|
+
def self.included(klass)
|
8
|
+
def klass.ignore_identity(symbol)
|
9
|
+
(@__ignore_identities__ ||= []) << symbol
|
10
|
+
end
|
11
|
+
|
12
|
+
def klass.__ignore_identities__
|
13
|
+
@__ignore_identities__ || []
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
forward :class, :__ignore_identities__
|
18
|
+
|
4
19
|
def eql?(other)
|
5
20
|
return false unless other.kind_of?(self.class)
|
6
21
|
__identities__.all? do |symbol|
|
@@ -14,6 +29,8 @@ module SimpleIdentity
|
|
14
29
|
end
|
15
30
|
|
16
31
|
def __identities__
|
17
|
-
instance_variables.select
|
32
|
+
instance_variables.select do |id|
|
33
|
+
not(id.to_s.start_with?("@__") or __ignore_identities__.include?(id.to_s[1..-1].to_sym))
|
34
|
+
end
|
18
35
|
end
|
19
36
|
end
|
data/simple-identity.gemspec
CHANGED
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
+
spec.add_dependency "forwardablex"
|
23
|
+
|
22
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
23
25
|
spec.add_development_dependency "rake"
|
24
26
|
spec.add_development_dependency "bacon"
|
@@ -12,16 +12,28 @@ class A
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
class B
|
16
|
+
include SimpleIdentity
|
17
|
+
ignore_identity :b
|
18
|
+
attr_accessor :a, :b
|
19
|
+
def initialize(a, b)
|
20
|
+
@a = a
|
21
|
+
@b = b
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
15
25
|
describe "SimpleIdentity" do
|
16
26
|
it 'should equal' do
|
17
27
|
A.new(1,2,3).should == A.new(1,2,3)
|
18
28
|
A.new(1,2,3,4).should == A.new(1,2,3)
|
19
29
|
A.new(1,2,3,4).should == A.new(1,2,3,5)
|
30
|
+
B.new(1,2).should == B.new(1,3)
|
20
31
|
end
|
21
32
|
|
22
33
|
it 'should not equal' do
|
23
34
|
A.new(1,2,3).should != A.new(3,2,1)
|
24
35
|
A.new(1,2,3).should != 1
|
36
|
+
B.new(1,2).should != B.new(2,3)
|
25
37
|
end
|
26
38
|
|
27
39
|
it 'should have same hash values' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-identity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: forwardablex
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: bundler
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -93,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
109
|
version: '0'
|
94
110
|
segments:
|
95
111
|
- 0
|
96
|
-
hash:
|
112
|
+
hash: -1996033258242692954
|
97
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
114
|
none: false
|
99
115
|
requirements:
|
@@ -102,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
102
118
|
version: '0'
|
103
119
|
segments:
|
104
120
|
- 0
|
105
|
-
hash:
|
121
|
+
hash: -1996033258242692954
|
106
122
|
requirements: []
|
107
123
|
rubyforge_project:
|
108
124
|
rubygems_version: 1.8.24
|