Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Abstract versions & requirements from rubygems.

* Favor composition over inheritance.

Fixes #53.
  • Loading branch information...
commit c6feb8f5358b0256f8e7e36884d0da8716261c40 1 parent bd1a193
@yfeldblum yfeldblum authored
Showing with 65 additions and 3 deletions.
  1. +34 −2 lib/librarian/dependency.rb
  2. +31 −1 lib/librarian/manifest.rb
View
36 lib/librarian/dependency.rb
@@ -5,7 +5,39 @@
module Librarian
class Dependency
- class Requirement < Gem::Requirement
+ class Requirement
+ def initialize(*args)
+ args = initialize_normalize_args(args)
+
+ self.backing = Gem::Requirement.create(*args)
+ end
+
+ def to_gem_requirement
+ backing
+ end
+
+ def satisfied_by?(version)
+ to_gem_requirement.satisfied_by?(version.to_gem_version)
+ end
+
+ def ==(other)
+ to_gem_requirement == other.to_gem_requirement
+ end
+
+ def to_s
+ to_gem_requirement.to_s
+ end
+
+ private
+
+ def initialize_normalize_args(args)
+ args.map do |arg|
+ arg = [arg] if self.class === arg
+ arg
+ end
+ end
+
+ attr_accessor :backing
end
include Helpers::Debug
@@ -17,7 +49,7 @@ def initialize(name, requirement, source)
assert_name_valid! name
self.name = name
- self.requirement = Requirement.create(requirement)
+ self.requirement = Requirement.new(requirement)
self.source = source
@manifests = nil
View
32 lib/librarian/manifest.rb
@@ -6,7 +6,37 @@
module Librarian
class Manifest
- class Version < Gem::Version
+ class Version
+ include Comparable
+
+ def initialize(*args)
+ args = initialize_normalize_args(args)
+
+ self.backing = Gem::Version.new(*args)
+ end
+
+ def to_gem_version
+ backing
+ end
+
+ def <=>(other)
+ to_gem_version <=> other.to_gem_version
+ end
+
+ def to_s
+ to_gem_version.to_s
+ end
+
+ private
+
+ def initialize_normalize_args(args)
+ args.map do |arg|
+ arg = [arg] if self.class === arg
+ arg
+ end
+ end
+
+ attr_accessor :backing
end
include Support::AbstractMethod
Please sign in to comment.
Something went wrong with that request. Please try again.