Geminstaller C0 Coverage Information - RCov

spec/fixture/rubygems_dist/rubygems-trunk/lib/rubygems/requirement.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
spec/fixture/rubygems_dist/rubygems-trunk/lib/rubygems/requirement.rb 153 81
96.08%
92.59%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 require "rubygems/version"
2 
3 ##
4 # A Requirement is a set of one or more version restrictions. It supports a
5 # few (<tt>=, !=, >, <, >=, <=, ~></tt>) different restriction operators.
6 
7 class Gem::Requirement
8   include Comparable
9 
10   OPS = { #:nodoc:
11     "="  =>  lambda { |v, r| v == r },
12     "!=" =>  lambda { |v, r| v != r },
13     ">"  =>  lambda { |v, r| v > r  },
14     "<"  =>  lambda { |v, r| v < r  },
15     ">=" =>  lambda { |v, r| v >= r },
16     "<=" =>  lambda { |v, r| v <= r },
17     "~>" =>  lambda { |v, r| v = v.release; v >= r && v < r.bump }
18   }
19 
20   quoted  = OPS.keys.map { |k| Regexp.quote k }.join "|"
21   PATTERN = /\A\s*(#{quoted})?\s*(#{Gem::Version::VERSION_PATTERN})\s*\z/
22 
23   ##
24   # Factory method to create a Gem::Requirement object.  Input may be
25   # a Version, a String, or nil.  Intended to simplify client code.
26   #
27   # If the input is "weird", the default version requirement is
28   # returned.
29 
30   def self.create input
31     case input
32     when Gem::Requirement then
33       input
34     when Gem::Version, Array then
35       new input
36     else
37       if input.respond_to? :to_str then
38         new [input.to_str]
39       else
40         default
41       end
42     end
43   end
44 
45   ##
46   # A default "version requirement" can surely _only_ be '>= 0'.
47   #--
48   # This comment once said:
49   #
50   # "A default "version requirement" can surely _only_ be '> 0'."
51 
52   def self.default
53     new '>= 0'
54   end
55 
56   ##
57   # Parse +obj+, returning an <tt>[op, version]</tt> pair. +obj+ can
58   # be a String or a Gem::Version.
59   #
60   # If +obj+ is a String, it can be either a full requirement
61   # specification, like <tt>">= 1.2"</tt>, or a simple version number,
62   # like <tt>"1.2"</tt>.
63   #
64   #     parse("> 1.0")                 # => [">", "1.0"]
65   #     parse("1.0")                   # => ["=", "1.0"]
66   #     parse(Gem::Version.new("1.0")) # => ["=,  "1.0"]
67 
68   def self.parse obj
69     return ["=", obj] if Gem::Version === obj
70 
71     unless PATTERN =~ obj.to_s
72       raise ArgumentError, "Illformed requirement [#{obj.inspect}]"
73     end
74 
75     [$1 || "=", Gem::Version.new($2)]
76   end
77 
78   ##
79   # An array of requirement pairs. The first element of the pair is
80   # the op, and the second is the Gem::Version.
81 
82   attr_reader :requirements #:nodoc:
83 
84   ##
85   # Constructs a requirement from +requirements+. Requirements can be
86   # Strings, Gem::Versions, or Arrays of those. +nil+ and duplicate
87   # requirements are ignored. An empty set of +requirements+ is the
88   # same as <tt>">= 0"</tt>.
89 
90   def initialize *requirements
91     requirements = requirements.flatten
92     requirements.compact!
93     requirements.uniq!
94 
95     requirements << ">= 0" if requirements.empty?
96     @none = (requirements == ">= 0")
97     @requirements = requirements.map! { |r| self.class.parse r }
98   end
99 
100   def none?
101     @none ||= (to_s == ">= 0")
102   end
103 
104   def as_list # :nodoc:
105     requirements.map { |op, version| "#{op} #{version}" }
106   end
107 
108   def hash # :nodoc:
109     requirements.hash
110   end
111 
112   def marshal_dump # :nodoc:
113     [@requirements]
114   end
115 
116   def marshal_load array # :nodoc:
117     @requirements = array[0]
118   end
119 
120   def prerelease?
121     requirements.any? { |r| r.last.prerelease? }
122   end
123 
124   def pretty_print q # :nodoc:
125     q.group 1, 'Gem::Requirement.new(', ')' do
126       q.pp as_list
127     end
128   end
129 
130   ##
131   # True if +version+ satisfies this Requirement.
132 
133   def satisfied_by? version
134     requirements.all? { |op, rv| OPS[op].call version, rv }
135   end
136 
137   def to_s # :nodoc:
138     as_list.join ", "
139   end
140 
141   def <=> other # :nodoc:
142     to_s <=> other.to_s
143   end
144 end
145 
146 # :stopdoc:
147 # Gem::Version::Requirement is used in a lot of old YAML specs. It's aliased
148 # here for backwards compatibility. I'd like to remove this, maybe in RubyGems
149 # 2.0.
150 
151 ::Gem::Version::Requirement = ::Gem::Requirement
152 # :startdoc:
153 

Generated on Mon May 10 23:40:28 -0700 2010 with rcov 0.9.8