Module: FakeWeb::Utility
- Defined in:
- lib/fake_web/utility.rb
Overview
:nodoc:
Class Method Summary collapse
- .decode_userinfo_from_header(header) ⇒ Object
- .encode_unsafe_chars_in_userinfo(userinfo) ⇒ Object
-
.simple_array_permutation(array) {|array| ... } ⇒ Object
Array#permutation wrapper for 1.8.6-compatibility.
- .strip_default_port_from_uri(uri) ⇒ Object
Class Method Details
.decode_userinfo_from_header(header) ⇒ Object
4 5 6 |
# File 'lib/fake_web/utility.rb', line 4 def self.decode_userinfo_from_header(header) header.sub(/^Basic /, "").unpack("m").first end |
.encode_unsafe_chars_in_userinfo(userinfo) ⇒ Object
8 9 10 11 |
# File 'lib/fake_web/utility.rb', line 8 def self.encode_unsafe_chars_in_userinfo(userinfo) unsafe_in_userinfo = /[^#{URI::REGEXP::PATTERN::UNRESERVED};&=+$,]|^(#{URI::REGEXP::PATTERN::ESCAPED})/ userinfo.split(":").map { |part| URI.escape(part, unsafe_in_userinfo) }.join(":") end |
.simple_array_permutation(array) {|array| ... } ⇒ Object
Array#permutation wrapper for 1.8.6-compatibility. It only supports the simple case that returns all permutations (so it doesn’t take a numeric argument).
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fake_web/utility.rb', line 24 def self.simple_array_permutation(array, &block) # use native implementation if it exists return array.permutation(&block) if array.respond_to?(:permutation) yield array if array.length <= 1 array.length.times do |i| rest = array.dup picked = rest.delete_at(i) next if rest.empty? simple_array_permutation(rest) do |part_of_rest| yield [picked] + part_of_rest end end array end |
.strip_default_port_from_uri(uri) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/fake_web/utility.rb', line 13 def self.strip_default_port_from_uri(uri) case uri when %r{^http://} then uri.sub(%r{:80(/|$)}, '\1') when %r{^https://} then uri.sub(%r{:443(/|$)}, '\1') else uri end end |