File: active_support/base64.rb

Overview
Module Structure
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: ActiveSupport#6
has properties
constant: Base64 #8
  module: Base64#14
has properties
module method: encode64 / 1 #20
module method: decode64 / 1 #28

Code

   1  begin
   2    require 'base64'
   3  rescue LoadError
   4  end
   5 
   6  module ActiveSupport
   7    if defined? ::Base64
   8      Base64 = ::Base64
   9    else
  10      # Base64 provides utility methods for encoding and de-coding binary data 
  11      # using a base 64 representation. A base 64 representation of binary data
  12      # consists entirely of printable US-ASCII characters. The Base64 module
  13      # is included in Ruby 1.8, but has been removed in Ruby 1.9.
  14      module Base64
  15        # Encodes a string to its base 64 representation. Each 60 characters of
  16        # output is separated by a newline character.
  17        #
  18        #  ActiveSupport::Base64.encode64("Original unencoded string") 
  19        #  # => "T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw==\n"
  20        def self.encode64(data)
  21          [data].pack("m")
  22        end
  23 
  24        # Decodes a base 64 encoded string to its original representation.
  25        #
  26        #  ActiveSupport::Base64.decode64("T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw==") 
  27        #  # => "Original unencoded string"
  28        def self.decode64(data)
  29          data.unpack("m").first
  30        end
  31      end
  32    end
  33  end