Class: Params::Decoder
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #as_clean_hash(mode = :str) ⇒ Object
-
#as_hash(mode = :str) ⇒ Object
fx decoder.as_hash returns value of a.
-
#decoded ⇒ Object
decode in reverse order!.
-
#initialize(*args) ⇒ Decoder
constructor
A new instance of Decoder.
Methods included from Base
#clean_params, #crypter?, #crypter_off!, #crypter_on!, #use_crypter?
Constructor Details
#initialize(*args) ⇒ Decoder
Returns a new instance of Decoder.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/params/decoder.rb', line 7 def initialize *args raise "Decoder needs params to encode" if !args || args.empty? args = args.flatten = args.last if .kind_of? Hash @crypter = .delete(:crypter) if end @params = args.first end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
5 6 7 |
# File 'lib/params/decoder.rb', line 5 def hash @hash end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
5 6 7 |
# File 'lib/params/decoder.rb', line 5 def params @params end |
Instance Method Details
#as_clean_hash(mode = :str) ⇒ Object
29 30 31 |
# File 'lib/params/decoder.rb', line 29 def as_clean_hash mode = :str clean_params(as_hash mode) end |
#as_hash(mode = :str) ⇒ Object
fx decoder.as_hash returns value of a
19 20 21 22 23 24 25 26 27 |
# File 'lib/params/decoder.rb', line 19 def as_hash mode = :str @hash ||= Hash[decoded.split('&').collect{|p| p.split("=")}] case mode when :sym Hash[hash.map{ |k, v| [k.to_sym, v] }] else hash end end |
#decoded ⇒ Object
decode in reverse order!
34 35 36 |
# File 'lib/params/decoder.rb', line 34 def decoded @decoded ||= use_crypter? ? crypter.decrypt(decoded_params) : decoded_params end |