lib/sup.rb in sup-1.0 vs lib/sup.rb in sup-1.1
- old
+ new
@@ -24,11 +24,11 @@
class Module
def yaml_properties *props
props = props.map { |p| p.to_s }
path = name.gsub(/::/, "/")
- yaml_tag "!#{Redwood::YAML_DOMAIN},#{Redwood::YAML_DATE}/#{path}"
+ yaml_tag "tag:#{Redwood::YAML_DOMAIN},#{Redwood::YAML_DATE}/#{path}"
define_method :init_with do |coder|
initialize(*coder.map.values_at(*props))
end
@@ -36,13 +36,10 @@
coder.map = props.inject({}) do |hash, key|
hash[key] = instance_variable_get("@#{key}")
hash
end
end
-
- # Legacy
- Psych.load_tags["!#{Redwood::LEGACY_YAML_DOMAIN},#{Redwood::YAML_DATE}/#{path}"] = self
end
end
module Redwood
BASE_DIR = ENV["SUP_BASE"] || File.join(ENV["HOME"], ".sup")
@@ -137,15 +134,22 @@
end
end
def load_yaml_obj fn, compress=false
o = if File.exist? fn
- if compress
- Zlib::GzipReader.open(fn) { |f| YAML::load f }
+ raw_contents = if compress
+ Zlib::GzipReader.open(fn) { |f| f.read }
else
- YAML::load_file fn
+ File::open(fn) { |f| f.read }
end
+ ## fix up malformed tag URIs created by earlier versions of sup
+ raw_contents.gsub!(/!supmua.org,2006-10-01\/(\S*)$/) { |m| "!<tag:supmua.org,2006-10-01/#{$1}>" }
+ if YAML.respond_to?(:unsafe_load) # Ruby 3.1+
+ YAML::unsafe_load raw_contents
+ else
+ YAML::load raw_contents
+ end
end
if o.is_a?(Array)
o.each { |x| x.after_unmarshal! if x.respond_to?(:after_unmarshal!) }
else
o.after_unmarshal! if o.respond_to?(:after_unmarshal!)
@@ -347,10 +351,10 @@
require 'socket'
name = Etc.getpwnam(ENV["USER"]).gecos.split(/,/).first.force_encoding($encoding).fix_encoding! rescue nil
name ||= ENV["USER"]
email = ENV["USER"] + "@" +
begin
- Socket.gethostbyname(Socket.gethostname).first
+ Addrinfo.getaddrinfo(Socket.gethostname, 'smtp').first.getnameinfo.first
rescue SocketError
Socket.gethostname
end
config = {