summaryrefslogtreecommitdiff
path: root/lib/yaml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/yaml')
-rw-r--r--lib/yaml/dbm.rb31
-rw-r--r--lib/yaml/store.rb20
-rw-r--r--lib/yaml/yaml.gemspec30
3 files changed, 69 insertions, 12 deletions
diff --git a/lib/yaml/dbm.rb b/lib/yaml/dbm.rb
index e2508cd74b..a3cbaeccf6 100644
--- a/lib/yaml/dbm.rb
+++ b/lib/yaml/dbm.rb
@@ -1,6 +1,10 @@
# frozen_string_literal: false
require 'yaml'
-require 'dbm'
+
+begin
+ require 'dbm'
+rescue LoadError
+end
module YAML
@@ -16,7 +20,6 @@ module YAML
#
# See the documentation for ::DBM and ::YAML for more information.
class DBM < ::DBM
- VERSION = "0.1" # :nodoc:
# :call-seq:
# ydbm[key] -> value
@@ -56,7 +59,13 @@ class DBM < ::DBM
def fetch( keystr, ifnone = nil )
begin
val = super( keystr )
- return YAML.load( val ) if String === val
+ if String === val
+ if YAML.respond_to?(:safe_load)
+ return YAML.safe_load( val )
+ else
+ return YAML.load( val )
+ end
+ end
rescue IndexError
end
if block_given?
@@ -102,7 +111,11 @@ class DBM < ::DBM
def delete( key )
v = super( key )
if String === v
- v = YAML.load( v )
+ if YAML.respond_to?(:safe_load)
+ v = YAML.safe_load( v )
+ else
+ v = YAML.load( v )
+ end
end
v
end
@@ -149,7 +162,7 @@ class DBM < ::DBM
#
# Returns +self+.
def each_value # :yields: value
- super { |v| yield YAML.load( v ) }
+ super { |v| yield YAML.respond_to?(:safe_load) ? YAML.safe_load( v ) : YAML.load( v ) }
self
end
@@ -158,7 +171,7 @@ class DBM < ::DBM
#
# Returns an array of values from the database.
def values
- super.collect { |v| YAML.load( v ) }
+ super.collect { |v| YAML.respond_to?(:safe_load) ? YAML.safe_load( v ) : YAML.load( v ) }
end
# :call-seq:
@@ -204,7 +217,9 @@ class DBM < ::DBM
# The order in which values are removed/returned is not guaranteed.
def shift
a = super
- a[1] = YAML.load( a[1] ) if a
+ if a
+ a[1] = YAML.respond_to?(:safe_load) ? YAML.safe_load( a[1] ) : YAML.load( a[1] )
+ end
a
end
@@ -277,4 +292,4 @@ class DBM < ::DBM
alias :each :each_pair
end
-end
+end if defined?(DBM)
diff --git a/lib/yaml/store.rb b/lib/yaml/store.rb
index 3c9b8817e4..27c823b9f9 100644
--- a/lib/yaml/store.rb
+++ b/lib/yaml/store.rb
@@ -3,7 +3,11 @@
# YAML::Store
#
require 'yaml'
-require 'pstore'
+
+begin
+ require 'pstore'
+rescue LoadError
+end
# YAML::Store provides the same functionality as PStore, except it uses YAML
# to dump objects instead of Marshal.
@@ -65,8 +69,16 @@ class YAML::Store < PStore
end
def load(content)
- table = YAML.load(content)
- if table == false
+ table = if YAML.respond_to?(:safe_load)
+ if Psych::VERSION >= "3.1"
+ YAML.safe_load(content, permitted_classes: [Symbol])
+ else
+ YAML.safe_load(content, [Symbol])
+ end
+ else
+ YAML.load(content)
+ end
+ if table == false || table == nil
{}
else
table
@@ -83,4 +95,4 @@ class YAML::Store < PStore
def empty_marshal_checksum
CHECKSUM_ALGO.digest(empty_marshal_data)
end
-end
+end if defined?(::PStore)
diff --git a/lib/yaml/yaml.gemspec b/lib/yaml/yaml.gemspec
new file mode 100644
index 0000000000..17e1ce89e0
--- /dev/null
+++ b/lib/yaml/yaml.gemspec
@@ -0,0 +1,30 @@
+name = File.basename(__FILE__, ".gemspec")
+version = ["lib", Array.new(name.count("-")+1, "..").join("/")].find do |dir|
+ break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
+ /^\s*LOADER_VERSION\s*=\s*"(.*)"/ =~ line and break $1
+ end rescue nil
+end
+
+Gem::Specification.new do |spec|
+ spec.name = name
+ spec.version = version
+ spec.authors = ["Aaron Patterson", "SHIBATA Hiroshi"]
+ spec.email = ["aaron@tenderlovemaking.com", "hsbt@ruby-lang.org"]
+
+ spec.summary = "YAML Ain't Markup Language"
+ spec.description = spec.summary
+ spec.homepage = "https://github.com/ruby/yaml"
+ spec.licenses = ["Ruby", "BSD-2-Clause"]
+
+ spec.metadata["homepage_uri"] = spec.homepage
+ spec.metadata["source_code_uri"] = spec.homepage
+
+ # Specify which files should be added to the gem when it is released.
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
+ `git ls-files -z 2>#{IO::NULL}`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
+ end
+ spec.bindir = "exe"
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
+ spec.require_paths = ["lib"]
+end