aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/base64.rb
diff options
context:
space:
mode:
authorSergey Nartimov <just.lest@gmail.com>2012-01-03 00:55:42 +0300
committerSergey Nartimov <just.lest@gmail.com>2012-01-03 00:57:03 +0300
commit5f09414f85edfa60ab54ce8b9f8b03874e0670dc (patch)
treec130e4279ffee79d0cd6a69610480ff9eb9ca0d1 /activesupport/lib/active_support/base64.rb
parent6e9cd3846811718611543dae049c000076319587 (diff)
downloadrails-5f09414f85edfa60ab54ce8b9f8b03874e0670dc.tar.gz
rails-5f09414f85edfa60ab54ce8b9f8b03874e0670dc.tar.bz2
rails-5f09414f85edfa60ab54ce8b9f8b03874e0670dc.zip
deprecate ActiveSupport::Base64
extend and define ::Base64 if needed
Diffstat (limited to 'activesupport/lib/active_support/base64.rb')
-rw-r--r--activesupport/lib/active_support/base64.rb57
1 files changed, 31 insertions, 26 deletions
diff --git a/activesupport/lib/active_support/base64.rb b/activesupport/lib/active_support/base64.rb
index 35014cb3d5..8ffbb77108 100644
--- a/activesupport/lib/active_support/base64.rb
+++ b/activesupport/lib/active_support/base64.rb
@@ -1,42 +1,47 @@
begin
require 'base64'
rescue LoadError
-end
-
-module ActiveSupport
- if defined? ::Base64
- Base64 = ::Base64
- else
- # 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
+ # The Base64 module isn't available in ealier versions of 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
+ # 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
end
+end
+unless Base64.respond_to?(:strict_encode64)
+ # Included in Ruby 1.9
+ def Base64.strict_encode64(value)
+ encode64(value).gsub(/\n/, '')
+ end
+end
+
+module ActiveSupport
+ Base64 = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('ActiveSupport::Base64', '::Base64')
+
+ # *DEPRECATED*: Use +Base64.strict_encode64+ instead.
+ #
# 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 Base64.encode64s(value)
+ ActiveSupport::Deprecation.warn "encode64s " \
+ "is deprecated. Use Base64.strict_encode64 instead", caller
encode64(value).gsub(/\n/, '')
end
end