class Params::Encoder

Attributes

params[R]

Public Class Methods

new(*args) click to toggle source
# File lib/params/encoder.rb, line 7
def initialize *args
        raise "Encoder needs params to encode" if !args || args.empty?
        args = args.flatten
        options = args.last 
        if options.kind_of? Hash                             
                @crypter = options.delete(:crypter)
        end
        arg = args.first
        @params = case arg
        when Hash
                create_from arg
        when String
                arg
        else
                raise "Must be a Hash or String, was #{arg}"
        end
end

Public Instance Methods

encoded() click to toggle source

encode after encryption to ensure Base64 compatibility in link

# File lib/params/encoder.rb, line 26
def encoded
        @encoded ||= use_crypter? ? Base64.encode64(encrypted_params) : Base64.encode64(params)
end

Protected Instance Methods

create_from(arg) click to toggle source

{:a => b, :c = 2} -> a=b&c=2

# File lib/params/encoder.rb, line 37
def create_from arg
        @params = arg.inject([]) do |res, hash| 
                res << [hash.first, hash.last].join('=')
                res
        end.join('&')
end
crypter() click to toggle source
# File lib/params/encoder.rb, line 44
def crypter
        Crypter.instance if crypter?
end
encrypted_params() click to toggle source
# File lib/params/encoder.rb, line 32
def encrypted_params
        crypter.encrypt(params)
end