Ruby 3.0 compatibility

This commit is contained in:
karel.picman@lbcfree.net 2021-05-21 08:59:52 +02:00
parent a6f6245b69
commit d95a37814a

View File

@ -56,52 +56,14 @@ module DAV4Rack
end end
end end
def render_lockdiscovery(options={})
def render_lockdiscovery(*args) render_xml ox_element(D_PROP, ox_element(D_LOCKDISCOVERY, activelock(options)))
render_xml ox_element(D_PROP,
ox_element(D_LOCKDISCOVERY,
activelock(*args))
)
end end
# #
# helpers for creating single elements # helpers for creating single elements
# #
# returns an activelock Ox::Element for the given lock data
def activelock(time: nil, token:, depth:,
scope: nil, type: nil, owner: nil, root: nil)
Ox::Element.new(D_ACTIVELOCK).tap do |activelock|
if scope
scope = Ox::Element.new("#{DAV_NAMESPACE_NAME}:#{scope}")
activelock << ox_element(D_LOCKSCOPE, scope)
end
if type
type = Ox::Element.new("#{DAV_NAMESPACE_NAME}:#{type}")
activelock << ox_element(D_LOCKTYPE)
end
activelock << ox_element(D_DEPTH, depth)
activelock << ox_element(D_TIMEOUT,
(time ? "Second-#{time}" : INFINITY))
token = ox_element(D_HREF, token)
activelock << ox_element(D_LOCKTOKEN, token)
if owner
activelock << ox_element(D_OWNER, owner)
end
if root
root = ox_element(D_HREF, root)
activelock << ox_element(D_LOCKROOT, root)
end
end
end
def response(href, status) def response(href, status)
r = Ox::Element.new(D_RESPONSE) r = Ox::Element.new(D_RESPONSE)
r << ox_element(D_HREF, href) r << ox_element(D_HREF, href)
@ -117,6 +79,29 @@ module DAV4Rack
ox_element D_STATUS, "#{@http_version} #{status.status_line}" ox_element D_STATUS, "#{@http_version} #{status.status_line}"
end end
private
def activelock(options)
Ox::Element.new(D_ACTIVELOCK).tap do |activelock|
if options[:scope]
scope = Ox::Element.new("#{DAV_NAMESPACE_NAME}:#{options[:scope]}")
activelock << ox_element(D_LOCKSCOPE, scope)
end
if options[:type]
type = Ox::Element.new("#{DAV_NAMESPACE_NAME}:#{options[:type]}")
activelock << ox_element(D_LOCKTYPE, type)
end
activelock << ox_element(D_DEPTH, options[:depth])
activelock << ox_element(D_TIMEOUT, (options[:time] ? "Second-#{options[:time]}" : INFINITY))
token = ox_element(D_HREF, options[:token])
activelock << ox_element(D_LOCKTOKEN, token)
activelock << ox_element(D_OWNER, options[:owner]) if options[:owner]
if options[:root]
root = ox_element(D_HREF, options[:root])
activelock << ox_element(D_LOCKROOT, root)
end
end
end
end end
end end