summaryrefslogtreecommitdiffstats
path: root/lib/puppet/util/uri_helper.rb
blob: cb93203875ab7ef4000392e837c6f5e63a7f6824 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#
#  Created by Luke Kanies on 2007-10-16.
#  Copyright (c) 2007. All rights reserved.

require 'uri'
require 'puppet/util'

# Helper methods for dealing with URIs.
module Puppet::Util::URIHelper
    def key2uri(key)
        # Return it directly if it's fully qualified.
        if key =~ /^#{::File::SEPARATOR}/
            key = "file://" + key
        end

        begin
            uri = URI.parse(URI.escape(key))
        rescue => detail
            raise ArgumentError, "Could not understand URI %s: %s" % [key, detail.to_s]
        end
    end
end