lib/firebug.rb in firebug-0.1.10 vs lib/firebug.rb in firebug-0.2.0
- old
+ new
@@ -8,68 +8,83 @@
require_relative 'action_dispatch/session/code_igniter_store'
module Firebug
class << self
attr_writer :configuration
- end
- # @return [Firebug::Configuration]
- def self.configuration
- @configuration ||= Configuration.new
- end
+ # Firebug configuration
+ #
+ # @return [Firebug::Configuration]
+ def configuration
+ @configuration ||= Configuration.new
+ end
+ alias config configuration
- # @yieldparam [Firebug::Configuration] config
- def self.configure
- yield configuration
- end
+ # Configure Firebug inside a block.
+ #
+ # @example
+ # Firebug.configure do |config|
+ # config.key = 'password'
+ # end
+ #
+ # @yieldparam [Firebug::Configuration] config
+ def configure
+ yield configuration
+ end
- # Serialize a ruby object into a PHP serialized string.
- #
- # @param [Object] value
- # @return [String]
- def self.serialize(value)
- Serializer.parse(value)
- end
+ # Serialize a ruby object into a PHP serialized string.
+ #
+ # @see Firebug::Serializer.parse
+ #
+ # @param [Object] value
+ # @return [String]
+ def serialize(value)
+ Serializer.parse(value)
+ end
- # Unserialize a PHP serialized string into a ruby object.
- #
- # @param [String] value
- # @return [Object]
- def self.unserialize(value)
- Unserializer.parse(value)
- end
+ # Unserialize a PHP serialized string into a ruby object.
+ #
+ # @see Firebug::Unserializer.parse
+ #
+ # @param [String] value
+ # @return [Object]
+ def unserialize(value)
+ Unserializer.parse(value)
+ end
- # Encrypt data the way CodeIgniter does.
- #
- # @param [Object] data
- # @param [String] key if `nil` use +Firebug::Configuration.key+
- def self.encrypt(data, key=nil)
- key = configuration.key if key.nil?
- Crypto.new(key).encrypt(data)
- end
+ # Encrypt data the way CodeIgniter does.
+ #
+ # @see Firebug::Crypto#encrypt
+ #
+ # @param [Object] data
+ # @param [String] key if `nil` use +Firebug::Configuration.key+
+ def encrypt(data, key=nil)
+ Crypto.new(key.nil? ? config.key : key).encrypt(data)
+ end
- # Decrypt data encrypted using CodeIgniters encryption.
- #
- # @param [Object] data
- # @param [String] key if `nil` use +Firebug::Configuration.key+
- def self.decrypt(data, key=nil)
- key = configuration.key if key.nil?
- Crypto.new(key).decrypt(data)
- end
+ # Decrypt data encrypted using CodeIgniters encryption.
+ #
+ # @see Firebug::Crypto#decrypt
+ #
+ # @param [Object] data
+ # @param [String] key If `nil` use +Firebug::Configuration.key+
+ def decrypt(data, key=nil)
+ Crypto.new(key.nil? ? config.key : key).decrypt(data)
+ end
- # Serializes, encrypts, and base64 encodes the data.
- #
- # @param [Object] data
- # @return [String] a base64 encoded string
- def self.encrypt_cookie(data)
- Base64.strict_encode64(Firebug.encrypt(Firebug.serialize(data)))
- end
+ # Serializes, encrypts, and base64 encodes the data.
+ #
+ # @param [Object] data
+ # @return [String] A base64 encoded string.
+ def encrypt_cookie(data)
+ Base64.strict_encode64(Firebug.encrypt(Firebug.serialize(data)))
+ end
- # Decodes the base64 encoded string, decrypts, and unserializes.
- #
- # @param [String] data a base64 encoded encrypted string
- # @return [Object] the unserialized data
- def self.decrypt_cookie(data)
- return {} if data.nil?
- Firebug.unserialize(Firebug.decrypt(Base64.strict_decode64(data)))
+ # Decodes the base64 encoded string, decrypts, and unserializes.
+ #
+ # @param [String] data A base64 encoded encrypted string.
+ # @return [Object] The unserialized data.
+ def decrypt_cookie(data)
+ data.nil? ? {} : Firebug.unserialize(Firebug.decrypt(Base64.strict_decode64(data)))
+ end
end
end