lib/hyperdrive/utils.rb in hyperdrive-0.0.21 vs lib/hyperdrive/utils.rb in hyperdrive-0.0.22
- old
+ new
@@ -21,7 +21,24 @@
else value
end
])
end
end
+
+ def self.enforce_charset!(charset, params)
+ encoding = charset.value == '*' ? 'UTF-8' : find_encoding(charset.value)
+ params.each_value do |value|
+ value.encode!(encoding) if value.is_a? String
+ end
+ end
+
+ private
+
+ def self.find_encoding(charset_value)
+ begin
+ Encoding.find(charset_value)
+ rescue
+ raise Hyperdrive::Errors::NotAcceptable.new(charset_value)
+ end
+ end
end
end