~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to lib/rubygems/requirement.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
require "rubygems/version"
2
2
 
 
3
# :stopdoc:
 
4
 
 
5
# Hack to handle syck's DefaultKey bug with psych
 
6
#
 
7
# Quick note! If/when psych loads in 1.9, it will redefine
 
8
# YAML to point to Psych by removing the YAML constant.
 
9
# Thusly, over in Gem.load_yaml, we define DefaultKey again
 
10
# after proper yaml library has been loaded.
 
11
#
 
12
# All this is so that there is always a YAML::Syck::DefaultKey
 
13
# class no matter if the full yaml library has loaded or not.
 
14
#
 
15
module YAML
 
16
  if !defined? Syck
 
17
    module Syck
 
18
      class DefaultKey
 
19
        def to_s
 
20
          '='
 
21
        end
 
22
      end
 
23
    end
 
24
  end
 
25
end
 
26
 
 
27
# :startdoc:
 
28
 
3
29
##
4
30
# A Requirement is a set of one or more version restrictions. It supports a
5
31
# few (<tt>=, !=, >, <, >=, <=, ~></tt>) different restriction operators.
14
40
    "<"  =>  lambda { |v, r| v < r  },
15
41
    ">=" =>  lambda { |v, r| v >= r },
16
42
    "<=" =>  lambda { |v, r| v <= r },
17
 
    "~>" =>  lambda { |v, r| v = v.release; v >= r && v < r.bump }
 
43
    "~>" =>  lambda { |v, r| v >= r && v.release < r.bump }
18
44
  }
19
45
 
20
46
  quoted  = OPS.keys.map { |k| Regexp.quote k }.join "|"
102
128
  end
103
129
 
104
130
  def as_list # :nodoc:
105
 
    requirements.map { |op, version| "#{op} #{version}" }
 
131
    requirements.map { |op, version| "#{op} #{version}" }.sort
106
132
  end
107
133
 
108
134
  def hash # :nodoc:
110
136
  end
111
137
 
112
138
  def marshal_dump # :nodoc:
 
139
    fix_syck_default_key_in_requirements
 
140
 
113
141
    [@requirements]
114
142
  end
115
143
 
116
144
  def marshal_load array # :nodoc:
117
145
    @requirements = array[0]
 
146
 
 
147
    fix_syck_default_key_in_requirements
118
148
  end
119
149
 
120
150
  def prerelease?
131
161
  # True if +version+ satisfies this Requirement.
132
162
 
133
163
  def satisfied_by? version
134
 
    requirements.all? { |op, rv| OPS[op].call version, rv }
 
164
    # #28965: syck has a bug with unquoted '=' YAML.loading as YAML::DefaultKey
 
165
    requirements.all? { |op, rv| (OPS[op] || OPS["="]).call version, rv }
 
166
  end
 
167
 
 
168
  alias :=== :satisfied_by?
 
169
  alias :=~ :satisfied_by?
 
170
 
 
171
  ##
 
172
  # True if the requirement will not always match the latest version.
 
173
 
 
174
  def specific?
 
175
    return true if @requirements.length > 1 # GIGO, > 1, > 2 is silly
 
176
 
 
177
    not %w[> >=].include? @requirements.first.first # grab the operator
135
178
  end
136
179
 
137
180
  def to_s # :nodoc:
141
184
  def <=> other # :nodoc:
142
185
    to_s <=> other.to_s
143
186
  end
 
187
 
 
188
  private
 
189
 
 
190
  def fix_syck_default_key_in_requirements
 
191
    # Fixup the Syck DefaultKey bug
 
192
    @requirements.each do |r|
 
193
      if r[0].kind_of? YAML::Syck::DefaultKey
 
194
        r[0] = "="
 
195
      end
 
196
    end
 
197
  end
144
198
end
145
199
 
146
200
# :stopdoc: