Module: Pickle::Surprise

Defined in:
lib/pickle-surprise.rb,
lib/pickle-surprise/pickle.rb,
lib/pickle-surprise/version.rb

Defined Under Namespace

Classes: Pickle

Constant Summary collapse

VERSION =
"0.0.4"

Instance Method Summary collapse

Instance Method Details

#Pickle(params = {}, &block) ⇒ Object

The most important method in Pickle::Surprise. A pickle, by default, has these 3 attributes:

  • msg: a message

  • ns: a namespace

  • ts: a timestamp

Attribute __ts__ has a default value to Time.now.

As Pickle::Surprise use [mongodb](www.mongodb.org/) you can save extra attibutes of any type, but they can be serializable.

You can use block mode: if any exception is raised inside block, it creates a new pickle using exception message. If you pass a hash and a block, it merges hash with exception message and create a pickle.

Parameters:

  • attributes (Hash)

    for your pickle



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pickle-surprise.rb', line 44

def Pickle(params={},&block)
  if block
    begin
      yield
    rescue Exception => ex
      Pickle.factory ex, params
      raise
    end
  else
    Pickle.factory params
  end
end