From 25a6d1ba08a52503f3d9aeb99422afdf01683c6c Mon Sep 17 00:00:00 2001 From: Carlos Sanchez Date: Fri, 19 Apr 2013 00:25:35 +0200 Subject: [PATCH] Ensure equality comparisons work for Source objects Implement functions eql? and hash as they are required for proper evaluation of functions like uniq and to add them to a Set without duplicates --- lib/librarian/dependency.rb | 6 ++++++ lib/librarian/mock/source/mock.rb | 6 ++++++ lib/librarian/source/git.rb | 6 ++++++ lib/librarian/source/path.rb | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/lib/librarian/dependency.rb b/lib/librarian/dependency.rb index ea8c8d93..01b3eed1 100644 --- a/lib/librarian/dependency.rb +++ b/lib/librarian/dependency.rb @@ -22,6 +22,12 @@ def ==(other) to_gem_requirement == other.to_gem_requirement end + alias :eql? :== + + def hash + self.to_s.hash + end + def to_s to_gem_requirement.to_s end diff --git a/lib/librarian/mock/source/mock.rb b/lib/librarian/mock/source/mock.rb index cfb77385..d1f4e325 100644 --- a/lib/librarian/mock/source/mock.rb +++ b/lib/librarian/mock/source/mock.rb @@ -30,6 +30,12 @@ def ==(other) self.name == other.name end + alias :eql? :== + + def hash + self.to_s.hash + end + def to_spec_args [name, {}] end diff --git a/lib/librarian/source/git.rb b/lib/librarian/source/git.rb index 2094989b..45496b41 100644 --- a/lib/librarian/source/git.rb +++ b/lib/librarian/source/git.rb @@ -52,6 +52,12 @@ def ==(other) (self.sha.nil? || other.sha.nil? || self.sha == other.sha) end + alias :eql? :== + + def hash + self.to_s.hash + end + def to_spec_args options = {} options.merge!(:ref => ref) if ref != DEFAULTS[:ref] diff --git a/lib/librarian/source/path.rb b/lib/librarian/source/path.rb index 0d03a712..0f9974ce 100644 --- a/lib/librarian/source/path.rb +++ b/lib/librarian/source/path.rb @@ -29,6 +29,12 @@ def ==(other) self.path == other.path end + alias :eql? :== + + def hash + self.to_s.hash + end + def to_spec_args [path.to_s, {}] end