Class: Params::Encoder

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/params/encoder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Base

#clean_params, #crypter?, #crypter_off!, #crypter_on!, #use_crypter?

Constructor Details

#initialize(*args) ⇒ Encoder

Returns a new instance of Encoder.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



5
6
7
# File 'lib/params/encoder.rb', line 5

def params
  @params
end

Instance Method Details

#encodedObject

encode after encryption to ensure Base64 compatibility in link



26
27
28
# File 'lib/params/encoder.rb', line 26

def encoded
	@encoded ||= use_crypter? ? Base64.encode64(encrypted_params) : Base64.encode64(params)
end