aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorCody Fauser <cody@jadedpixel.com>2008-09-21 17:44:33 -0400
committerCody Fauser <cody@jadedpixel.com>2008-09-21 17:44:33 -0400
commitce8fded9bb75dca4ffcd88ba9de9b0a2e74493d6 (patch)
tree80fb7c3374adbbe61643fc9ade5e8599f27f2db8 /activesupport
parent7da89e9ae74b5f549c286f68c2fc2faba4958270 (diff)
downloadrails-ce8fded9bb75dca4ffcd88ba9de9b0a2e74493d6.tar.gz
rails-ce8fded9bb75dca4ffcd88ba9de9b0a2e74493d6.tar.bz2
rails-ce8fded9bb75dca4ffcd88ba9de9b0a2e74493d6.zip
Add some documentation and examples for Base64 encode64 and decode64, and encode64s.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/base64.rb15
-rw-r--r--activesupport/lib/active_support/core_ext/base64/encoding.rb3
2 files changed, 16 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/base64.rb b/activesupport/lib/active_support/base64.rb
index 602eef06b2..acb8e5a967 100644
--- a/activesupport/lib/active_support/base64.rb
+++ b/activesupport/lib/active_support/base64.rb
@@ -7,13 +7,24 @@ module ActiveSupport
if defined? ::Base64
Base64 = ::Base64
else
- # Ruby 1.9 doesn't provide base64, so we wrap this here
+ # Base64 provides utility methods for encoding and de-coding binary data
+ # using a base 64 representation. A base 64 representation of binary data
+ # consists entirely of printable US-ASCII characters. The Base64 module
+ # is included in Ruby 1.8, but has been removed in Ruby 1.9.
module Base64
-
+ # Encodes a string to its base 64 representation. Each 60 characters of
+ # output is separated by a newline character.
+ #
+ # ActiveSupport::Base64.encode64("Original unencoded string")
+ # # => "T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw==\n"
def self.encode64(data)
[data].pack("m")
end
+ # Decodes a base 64 encoded string to its original representation.
+ #
+ # ActiveSupport::Base64.decode64("T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw==")
+ # # => "Original unencoded string"
def self.decode64(data)
data.unpack("m").first
end
diff --git a/activesupport/lib/active_support/core_ext/base64/encoding.rb b/activesupport/lib/active_support/core_ext/base64/encoding.rb
index 1a40da8785..a9656c138e 100644
--- a/activesupport/lib/active_support/core_ext/base64/encoding.rb
+++ b/activesupport/lib/active_support/core_ext/base64/encoding.rb
@@ -4,6 +4,9 @@ module ActiveSupport #:nodoc:
module Encoding
# Encodes the value as base64 without the newline breaks. This makes the base64 encoding readily usable as URL parameters
# or memcache keys without further processing.
+ #
+ # ActiveSupport::Base64.encode64s("Original unencoded string")
+ # # => "T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw=="
def encode64s(value)
encode64(value).gsub(/\n/, '')
end