Module: RackSessionManipulation::Utilities
- Included in:
- RackSessionManipulation
- Defined in:
- lib/rack_session_manipulation/utilities.rb
Overview
Various utility methods that will be module level functions for the parent namespace module.
Instance Method Summary collapse
- #decode(encoded_data) ⇒ void
- #encode(obj) ⇒ void
-
#random_path_prefix ⇒ String
SecureRandom raises a NotImplementedError if no random device is available in that case fallback on Kernel.rand.
Instance Method Details
#decode(encoded_data) ⇒ void
6 7 8 |
# File 'lib/rack_session_manipulation/utilities.rb', line 6 def decode(encoded_data) JSON.parse(encoded_data) end |
#encode(obj) ⇒ void
10 11 12 |
# File 'lib/rack_session_manipulation/utilities.rb', line 10 def encode(obj) JSON.generate(obj) end |
#random_path_prefix ⇒ String
SecureRandom raises a NotImplementedError if no random device is available in that case fallback on Kernel.rand. Shamelessly stolen from the Sinatra session secret generation code.
19 20 21 22 23 24 25 26 27 |
# File 'lib/rack_session_manipulation/utilities.rb', line 19 def random_path_prefix num = begin require 'securerandom' SecureRandom.random_number(2**64 - 1) rescue LoadError, NotImplementedError Kernel.rand(2**64 - 1) end format('/%016x', num) end |