Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove thread-unsafe runtime requires #43

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/http/cookie_jar/mozilla_store.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# :markup: markdown
require 'sqlite3'
autoload :SQLite3, 'sqlite3'

class HTTP::CookieJar
# A store class that uses Mozilla compatible SQLite3 database as
Expand Down
15 changes: 5 additions & 10 deletions lib/http/cookie_jar/yaml_saver.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# :markup: markdown
require 'psych' if !defined?(YAML) && RUBY_VERSION == "1.9.2"
require 'yaml'
autoload :YAML, 'yaml'

# YAMLSaver saves and loads cookies in the YAML format. It can load a
# YAML file saved by Mechanize, but the saving format is not
Expand Down Expand Up @@ -73,13 +72,9 @@ def default_options
{}
end

if YAML.name == 'Psych' && Psych::VERSION >= '3.1'
def load_yaml(yaml)
YAML.safe_load(yaml, :permitted_classes => %w[Time HTTP::Cookie Mechanize::Cookie DomainName], :aliases => true)
end
else
def load_yaml(yaml)
YAML.load(yaml)
end
def load_yaml(yaml)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rewrote this method to avoid negating the requested introduction of autoload :YAML. It adds an extra level of indirection to every load, but only on extremely old and unsupported rubies.

YAML.safe_load(yaml, :permitted_classes => %w[Time HTTP::Cookie Mechanize::Cookie DomainName], :aliases => true)
rescue NoMethodError # ruby < 2.0, no safe_load
YAML.load(yaml)
end
end