Sha256: 8fdceccecb94d35ea2f31a5a060cd5e5c8ee94630ea3f5c396ba8939f3c27f44

Contents?: true

Size: 938 Bytes

Versions: 4

Compression:

Stored size: 938 Bytes

Contents

gem 'addressable', '~>2.0'
require 'addressable/uri'

module DataObjects
  URI = Struct.new(:scheme, :user, :password, :host, :port, :path, :query, :fragment)

  class URI
    def self.parse(uri)
      return uri if uri.kind_of?(self)
      uri = Addressable::URI::parse(uri) unless uri.kind_of?(Addressable::URI)
      self.new(uri.scheme, uri.user, uri.password, uri.host, uri.port, uri.path, uri.query_values, uri.fragment)
    end

    def to_s
      string = ""
      string << "#{scheme}://"   if scheme
      if user
        string << "#{user}"
        string << ":#{password}" if password
        string << "@"
      end
      string << "#{host}"        if host
      string << ":#{port}"       if port
      string << path.to_s
      if query
        string << "?" << query.map do |key, value|
          "#{key}=#{value}"
        end.join("&")
      end
      string << "##{fragment}"   if fragment
      string
    end
  end
end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
data_objects-0.9.10 lib/data_objects/uri.rb
data_objects-0.9.10.1 lib/data_objects/uri.rb
mack-data_mapper-0.8.3 lib/gems/data_objects-0.9.10.1/lib/data_objects/uri.rb
mack-data_mapper-0.8.3.1 lib/gems/data_objects-0.9.10.1/lib/data_objects/uri.rb