Sha256: 3fba12595bb89529f4d3bef6b048abe182f71f0b0878192dfef53bac04ef97cb

Contents?: true

Size: 609 Bytes

Versions: 8

Compression:

Stored size: 609 Bytes

Contents

unless Object.new.respond_to? :to_query and Object.new.respond_to? :to_param
  class Object
    def to_param
      to_s
    end

    def to_query(key)
      require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
      "#{CGI.escape(key.to_s)}=#{CGI.escape(to_param.to_s)}"
    end
  end

  class Array
    def to_param
      map(&:to_param).join('/')
    end

    def to_query(key)
      prefix = "#{key}[]"
      collect { |value| value.to_query(prefix) }.join '&'
    end
  end

  class Hash
    def to_param
      map do |key, value|
        value.to_query(key)
      end.sort * '&'
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
riak-client-0.9.4 lib/riak/core_ext/to_param.rb
riak-client-0.9.3 lib/riak/core_ext/to_param.rb
riak-client-0.9.2 lib/riak/core_ext/to_param.rb
riak-client-0.9.1 lib/riak/core_ext/to_param.rb
riak-client-0.9.0 lib/riak/core_ext/to_param.rb
riak-client-0.9.0.beta2 lib/riak/core_ext/to_param.rb
riak-client-0.9.0.beta lib/riak/core_ext/to_param.rb
riak-client-0.8.3 lib/riak/core_ext/to_param.rb