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

Eagerly require date #695

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 0 deletions lib/psych.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# frozen_string_literal: true
require 'date'

require_relative 'psych/versions'
case RUBY_ENGINE
when 'jruby'
Expand Down
2 changes: 0 additions & 2 deletions lib/psych/scalar_scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ module Psych
###
# Scan scalars for built in types
class ScalarScanner
autoload :Date, "date"

# Taken from http://yaml.org/type/timestamp.html
TIME = /^-?\d{4}-\d{1,2}-\d{1,2}(?:[Tt]|\s+)\d{1,2}:\d\d:\d\d(?:\.\d*)?(?:\s*(?:Z|[-+]\d{1,2}:?(?:\d\d)?))?$/

Expand Down
1 change: 0 additions & 1 deletion lib/psych/visitors/to_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ def deserialize o
class_loader.big_decimal._load o.value
when "!ruby/object:DateTime"
class_loader.date_time
require 'date' unless defined? DateTime
t = @ss.parse_time(o.value)
DateTime.civil(*t.to_a[0, 6].reverse, Rational(t.utc_offset, 86400)) +
(t.subsec/86400)
Expand Down
2 changes: 2 additions & 0 deletions psych.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ DESCRIPTION
s.add_dependency 'stringio'
end

s.add_dependency 'date'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does that make sense for the stdlib?


s.metadata['msys2_mingw_dependencies'] = 'libyaml'
s.metadata['changelog_uri'] = s.homepage + '/releases'
end
1 change: 0 additions & 1 deletion test/psych/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
require 'test/unit'
require 'stringio'
require 'tempfile'
require 'date'

require 'psych'

Expand Down
1 change: 0 additions & 1 deletion test/psych/test_date_time.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true
require_relative 'helper'
require 'date'

module Psych
class TestDateTime < TestCase
Expand Down
1 change: 0 additions & 1 deletion test/psych/test_scalar_scanner.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true
require_relative 'helper'
require 'date'

module Psych
class TestScalarScanner < TestCase
Expand Down
10 changes: 10 additions & 0 deletions test/psych/test_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ def test_doublequotes_when_there_is_a_single
assert_equal str, Psych.load(yaml)
end

def test_single_quote_when_matching_date
pend "Failing on JRuby" if RUBY_PLATFORM =~ /java/

lib = File.expand_path("../../../lib", __FILE__)
assert_separately(["-I", lib, "-r", "psych"], __FILE__, __LINE__ + 1, <<~'RUBY')
yml = Psych.dump('2024-11-19')
assert_equal '2024-11-19', Psych.load(yml)
RUBY
end

def test_plain_when_shorten_than_line_width_and_no_final_line_break
str = "Lorem ipsum"
yaml = Psych.dump str, line_width: 12
Expand Down
Loading