Skip to content

Commit

Permalink
Add API docs for Urlencoded.encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
ixti committed Jun 1, 2018
1 parent 3bf2e83 commit 27cc40c
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion lib/http/form_data/urlencoded.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,51 @@ class Urlencoded
include Readable

class << self
attr_writer :encoder
# Set custom form data encoder implementation.
#
# @example
#
# module CustomFormDataEncoder
# UNESCAPED_CHARS = /[^a-z0-9\-\.\_\~]/i
#
# def self.escape(s)
# ::URI::DEFAULT_PARSER.escape(s.to_s, UNESCAPED_CHARS)
# end
#
# def self.call(data)
# parts = []
#
# data.each do |k, v|
# k = escape(k)
#
# if v.nil?
# parts << k
# elsif v.respond_to?(:to_ary)
# v.to_ary.each { |vv| parts << "#{k}=#{escape vv}" }
# else
# parts << "#{k}=#{escape v}"
# end
# end
#
# parts.join("&")
# end
# end
#
# HTTP::FormData::Urlencoded.encoder = CustomFormDataEncoder
#
# @raise [ArgumentError] if implementation deos not responds to `#call`.
# @param implementation [#call]
# @return [void]
def encoder=(implementation)
raise ArgumentError unless implementation.respond_to? :call
@encoder = implementation
end

# Returns form data encoder implementation.
# Default: `URI.encode_www_form`.
#
# @see .encoder=
# @return [#call]
def encoder
@encoder ||= ::URI.method(:encode_www_form)
end
Expand Down

0 comments on commit 27cc40c

Please sign in to comment.