Skip to content

Commit

Permalink
Make sure our YAML workarounds are loaded properly. Fixes rubygems#250.
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed Jan 5, 2012
1 parent b742ae2 commit 3715d78
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -639,10 +639,14 @@ def self.load_path_insert_index
index
end

@yaml_loaded = false

##
# Loads YAML, preferring Psych

def self.load_yaml
return if @yaml_loaded

begin
gem 'psych', '~> 1.2', '>= 1.2.1' unless ENV['TEST_SYCK']
rescue Gem::LoadError
Expand All @@ -661,6 +665,8 @@ def self.load_yaml
# Now that we're sure some kind of yaml library is loaded, pull
# in our hack to deal with Syck's DefaultKey ugliness.
require 'rubygems/syck_hack'

@yaml_loaded = true
end

##
Expand Down
15 changes: 15 additions & 0 deletions lib/rubygems/requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@
# A Requirement is a set of one or more version restrictions. It supports a
# few (<tt>=, !=, >, <, >=, <=, ~></tt>) different restriction operators.

# REFACTOR: The fact that a requirement is singular or plural is kind of
# awkward. Is Requirement the right name for this? Or should it be one
# [op, number] pair, and we call the list of requirements something else?
# Since a Requirement is held by a Dependency, maybe this should be made
# singular and the list aspect should be pulled up into Dependency?

require "rubygems/version"
require "rubygems/deprecate"

# If we're being loaded after yaml was already required, then
# load our yaml + workarounds now.
Gem.load_yaml if defined? ::YAML

class Gem::Requirement
include Comparable

Expand Down Expand Up @@ -174,6 +187,8 @@ def <=> other # :nodoc:
private

def fix_syck_default_key_in_requirements
Gem.load_yaml

# Fixup the Syck DefaultKey bug
@requirements.each do |r|
if r[0].kind_of? Gem::SyckDefaultKey
Expand Down
2 changes: 2 additions & 0 deletions lib/rubygems/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,8 @@ def self.find_in_unresolved_tree path
# +input+ can be anything that YAML.load() accepts: String or IO.

def self.from_yaml(input)
Gem.load_yaml

input = normalize_yaml_input input
spec = YAML.load input

Expand Down

0 comments on commit 3715d78

Please sign in to comment.