lib/librarian/manifest.rb in librarianp-0.4.0 vs lib/librarian/manifest.rb in librarianp-0.5.0
- old
+ new
@@ -1,144 +1,12 @@
require 'rubygems'
+require 'librarian/manifest/version'
+require 'librarian/manifest/pre_release_version'
module Librarian
class Manifest
- class Version
- include Comparable
-
- @@SEMANTIC_VERSION_PATTERN = /^([0-9]+\.[0-9]+(?:\.[0-9]+)?)(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/
-
- attr_reader :prerelease
-
- def initialize(*args)
- args = initialize_normalize_args(args)
- semver = Version.parse_semver(*args)
- if semver
- self.backing = Gem::Version.new(semver[:version])
- @prerelease = semver[:prerelease]
- @full_version = semver[:full_version]
- else
- self.backing = Gem::Version.new(*args)
- @full_version = to_gem_version.to_s
- end
- end
-
- def to_gem_version
- backing
- end
-
- def <=>(other)
- cmp = to_gem_version <=> other.to_gem_version
-
- # Should compare pre-release versions?
- if cmp == 0 and not (prerelease.nil? and other.prerelease.nil?)
- case # Versions without prerelease take precedence
- when (prerelease.nil? and not other.prerelease.nil?)
- 1
- when (not prerelease.nil? and other.prerelease.nil?)
- -1
- else
- prerelease <=> other.prerelease
- end
- else
- cmp
- end
- end
-
- def to_s
- @full_version
- end
-
- def inspect
- "#<#{self.class} #{to_s}>"
- end
-
- def self.parse_semver(version_string)
- parsed = @@SEMANTIC_VERSION_PATTERN.match(version_string.strip)
- if parsed
- {
- :full_version => parsed[0],
- :version => parsed[1],
- :prerelease => (PreReleaseVersion.new(parsed[2]) if parsed[2]),
- :build => parsed[3]
- }
- end
- end
-
- private
-
- def initialize_normalize_args(args)
- args.map do |arg|
- arg = [arg] if self.class === arg
- arg
- end
- end
-
- attr_accessor :backing
- end
-
- class PreReleaseVersion
-
- # Compares pre-release component ids using Semver 2.0.0 spec
- def self.compare_components(this_id,other_id)
- case # Strings have higher precedence than numbers
- when (this_id.is_a?(Integer) and other_id.is_a?(String))
- -1
- when (this_id.is_a?(String) and other_id.is_a?(Integer))
- 1
- else
- this_id <=> other_id
- end
- end
-
- # Parses pre-release components `a.b.c` into an array ``[a,b,c]`
- # Converts numeric components into +Integer+
- def self.parse(prerelease)
- if prerelease.nil?
- []
- else
- prerelease.split('.').collect do |id|
- id = Integer(id) if /^[0-9]+$/ =~ id
- id
- end
- end
- end
-
- include Comparable
-
- attr_reader :components
-
- def initialize(prerelease)
- @prerelease = prerelease
- @components = PreReleaseVersion.parse(prerelease)
- end
-
- def to_s
- @prerelease
- end
-
- def <=>(other)
- # null-fill zip array to prevent loss of components
- z = Array.new([components.length,other.components.length])
-
- # Compare each component against the other
- comp = z.zip(components,other.components).collect do |ids|
- case # All components being equal, the version with more of them takes precedence
- when ids[1].nil? # Self has less elements, other wins
- -1
- when ids[2].nil? # Other has less elements, self wins
- 1
- else
- PreReleaseVersion.compare_components(ids[1],ids[2])
- end
- end
- # Chose the first non-zero comparison or return 0
- comp.delete_if {|c| c == 0}[0] || 0
- end
- end
-
attr_accessor :source, :name, :extra
private :source=, :name=, :extra=
def initialize(source, name, extra = nil)
assert_name_valid! name
@@ -188,10 +56,17 @@
defined_dependencies.zip(fetched_dependencies).all? do |(a, b)|
a.name == b.name && a.requirement == b.requirement
end
end
+ # Remove dependencies excluded, and return them
+ def exclude_dependencies!(exclusions)
+ included, excluded = dependencies.partition { |d| !exclusions.include? d.name }
+ self.dependencies = included
+ excluded
+ end
+
def satisfies?(dependency)
dependency.requirement.satisfied_by?(version)
end
def install!
@@ -224,10 +99,10 @@
# merge dependencies with the same name into one
# with the source of the first one and merged requirements
def merge_dependencies(dependencies)
requirement = Dependency::Requirement.new(*dependencies.map{|d| d.requirement})
- Dependency.new(dependencies.first.name, requirement, dependencies.first.source)
+ dependencies.first.class.new(dependencies.first.name, requirement, dependencies.first.source)
end
# Avoid duplicated dependencies with different sources or requirements
def remove_duplicate_dependencies(module_name, dependencies)
uniq = []