pickle-surprise 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - ruby-head
5
+ services:
6
+ - mongodb
data/Gemfile CHANGED
@@ -4,4 +4,3 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'rb-fsevent', require: false if RUBY_PLATFORM =~ /darwin/i
7
- gem 'pry'
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
- # Pickle::Surprise
1
+ ![Pickle::Surprise](https://raw.github.com/dlibanori/pickle-surprise/master/pickle-surprise.jpg "That's the surprise!")
2
2
 
3
- TODO: Write a gem description
3
+ # Where is the Pickle? [![Build Status](https://secure.travis-ci.org/dlibanori/pickle-surprise.png)](http://travis-ci.org/dlibanori/pickle-surprise)
4
+
5
+ Wouldn't it be nice if you could save messages in production to see them later? Things like: “suspicious action”, “this request is taking too long” or “third part service is not working again”.
6
+
7
+ We use [Mongoid](https://github.com/mongoid/mongoid) as database, so you can save anything that is serializable.
4
8
 
5
9
  ## Installation
6
10
 
@@ -18,12 +22,66 @@ Or install it yourself as:
18
22
 
19
23
  ## Usage
20
24
 
21
- TODO: Write usage instructions here
25
+ This gem is intended to be very simple:
26
+
27
+ ```ruby
28
+ class Customer
29
+ include Pickle::Surprise
30
+
31
+ def suspicious
32
+ Pickle msg: "#{@name} is trying something…"
33
+ end
34
+ end
35
+ ```
36
+
37
+ _Pickle_ from any place in your source code:
38
+
39
+ ```ruby
40
+ include Pickle::Surprise
41
+
42
+ Pickle msg: "Something is strange"
43
+ ```
44
+
45
+ You can have a block that catches all exceptions, creates a _Pickle_ and reraise them:
46
+
47
+ ```ruby
48
+ Pickle do
49
+ raise 'FFFUUUUUU-'
50
+ end
51
+ ```
52
+
53
+ **Pickle** expects 3 fields:
54
+
55
+ * **msg** (String): message
56
+ * **ns** (String): namespace
57
+ * **ts** (Time): timestamp
58
+
59
+ But you can save anything that is serializable in a _Pickle_:
60
+
61
+ ```ruby
62
+ Pickle msg: 'some crazy exception', stack: [1,2,3]
63
+ ```
64
+
65
+ What if I want to build an interface for my _Pickles_?
66
+
67
+ ```ruby
68
+ puts "You have #{Pickle.count}"
69
+ puts "My last Pickle: #{Pickle.last}"
70
+
71
+ Pickle.all.each do |pickle|
72
+ puts pickle.msg
73
+ end
74
+
75
+ # Forget all my Pickles!
76
+ Pickle.reset
77
+ ```
22
78
 
23
79
  ## Contributing
24
80
 
25
81
  1. Fork it
26
82
  2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
83
+ 3. Commit your changes (`git commit -am "Added a new feature"`)
28
84
  4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
85
+ 5. Create new **Pull Request**
86
+ 6. ???
87
+ 7. PROFIT
data/examples/usage.rb CHANGED
@@ -1,6 +1,21 @@
1
- ENV['MONGOID_ENV'] = 'development'
2
- Mongoid.load! 'examples/config.yml'
1
+ require 'pickle-surprise'
3
2
 
4
- include Pickle::Surprise
3
+ class Some
4
+ include Pickle::Surprise
5
5
 
6
- Pickle msg: 'Fuuu'
6
+ def thing
7
+ raise "Where is the Pickle?"
8
+ rescue
9
+ Pickle msg: "That's the surprise!"
10
+ end
11
+
12
+ def raiser
13
+ # boring code
14
+
15
+ Pickle ns: 'my namespace' do
16
+ raise 'FFFUUUUU-'
17
+ end
18
+
19
+ # more boring code
20
+ end
21
+ end
@@ -6,6 +6,10 @@ module Pickle
6
6
  Surprise::Pickle.count
7
7
  end
8
8
 
9
+ def self.all
10
+ Surprise::Pickle.all
11
+ end
12
+
9
13
  def self.last
10
14
  Surprise::Pickle.last
11
15
  end
@@ -15,12 +19,12 @@ module Pickle
15
19
  end
16
20
 
17
21
  module Surprise
18
- def Pickle(params=nil,&block)
22
+ def Pickle(params={},&block)
19
23
  if block
20
24
  begin
21
25
  yield
22
26
  rescue Exception => ex
23
- Pickle.factory ex
27
+ Pickle.factory ex, params
24
28
  raise
25
29
  end
26
30
  else
@@ -6,14 +6,17 @@ module Pickle
6
6
  include Mongoid::Document
7
7
 
8
8
  store_in collection: 'pickles'
9
+ default_scope order_by(ts: 1)
9
10
 
10
11
  field :ns, type: String
11
12
  field :ts, type: Time, default: -> { Time.now }
12
13
  field :msg, type: String
13
14
 
14
- def self.factory(params)
15
+ index ts: 1
16
+
17
+ def self.factory(params, options={})
15
18
  params = { msg: params.to_s } unless params.respond_to? :to_hash
16
- create params.to_hash
19
+ create options.merge params
17
20
  end
18
21
  end
19
22
  end
@@ -1,5 +1,5 @@
1
1
  module Pickle
2
2
  module Surprise
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -8,9 +8,9 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Pickle::Surprise::VERSION
9
9
  gem.authors = ["Daniel Libanori"]
10
10
  gem.email = ["daniellibanori@gmail.com"]
11
- gem.description = %q{Save anything you don't expect at your database}
12
- gem.summary = %q{Where is the pickle? It is not a surprise anymore...}
13
- gem.homepage = "http://dlibanori.github.com"
11
+ gem.description = %q{Save stuff you do not expect, in your database.}
12
+ gem.summary = %q{Where is the pickle? It's not a surprise anymore}
13
+ gem.homepage = "https://github.com/dlibanori/pickle-surprise"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_dependency 'mongoid', '~> 3.0.0'
21
+ gem.add_development_dependency 'rake'
21
22
  gem.add_development_dependency 'rspec', '~> 2.11.0'
22
23
  gem.add_development_dependency 'guard-rspec'
23
24
  end
Binary file
@@ -1,5 +1,15 @@
1
+ require 'spec_helper'
1
2
  require 'pickle-surprise/pickle'
2
3
 
3
4
  describe Pickle::Surprise::Pickle do
4
- pending 'not implemented yet'
5
+ it 'should create a new Pickle' do
6
+ pickle = described_class.factory msg: 'where is the pickle?'
7
+ expect(pickle.msg).to eq('where is the pickle?')
8
+ end
9
+
10
+ it 'should accept default params' do
11
+ options = { ns: 'namespace' }
12
+ pickle = described_class.factory({ msg: 'where is the pickle?' }, options)
13
+ expect(pickle.ns).to eq('namespace')
14
+ end
5
15
  end
@@ -3,12 +3,7 @@ require 'pickle-surprise'
3
3
 
4
4
  class SomeException < Exception; end
5
5
 
6
- describe Pickle do
7
- pending 'not implemented yet'
8
- end
9
-
10
6
  describe Pickle::Surprise do
11
- use_mongoid
12
7
  use_pickle_surprise
13
8
  after { Pickle.reset }
14
9
 
@@ -22,14 +17,35 @@ describe Pickle::Surprise do
22
17
  expect(pickle.msg).to eq('hash')
23
18
  end
24
19
 
25
- it 'should accept a block' do
26
- expect {
27
- Pickle do
28
- raise SomeException, 'from an exception'
20
+ context 'with block' do
21
+ it 'should create a pickle' do
22
+ ignore do
23
+ Pickle do
24
+ raise SomeException, 'from an exception'
25
+ end
26
+ end
27
+
28
+ pickle = Pickle.last
29
+ expect(pickle.msg).to eq('from an exception')
30
+ end
31
+
32
+ it 'should reraise same expection' do
33
+ expect {
34
+ Pickle do
35
+ raise SomeException, 'from an exception'
36
+ end
37
+ }.to raise_error(SomeException)
38
+ end
39
+
40
+ it 'should accept params' do
41
+ ignore do
42
+ Pickle ns: 'namespace' do
43
+ raise SomeException, 'from an exception'
44
+ end
29
45
  end
30
- }.to raise_error(SomeException)
31
46
 
32
- pickle = Pickle.last
33
- expect(pickle.msg).to eq('from an exception')
47
+ pickle = Pickle.last
48
+ expect(pickle.ns).to eq('namespace')
49
+ end
34
50
  end
35
51
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,19 @@
1
- def use_mongoid
2
- require 'mongoid'
3
- ENV['MONGOID_ENV'] = 'development'
4
- Mongoid.load! 'examples/config.yml'
1
+ require 'mongoid'
2
+
3
+ def database_id
4
+ ENV['CI'] ? "mongoid_slug_#{Process.pid}" : 'pickle_surprise_test'
5
5
  end
6
6
 
7
7
  def use_pickle_surprise
8
8
  include Pickle::Surprise
9
9
  end
10
+
11
+ def ignore(type=Exception)
12
+ yield
13
+ rescue Exception => ex
14
+ raise unless ex.is_a? type
15
+ end
16
+
17
+ Mongoid.configure do |config|
18
+ config.connect_to database_id
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pickle-surprise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-11 00:00:00.000000000 Z
12
+ date: 2012-09-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: 3.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: rspec
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -59,7 +75,7 @@ dependencies:
59
75
  - - ! '>='
60
76
  - !ruby/object:Gem::Version
61
77
  version: '0'
62
- description: Save anything you don't expect at your database
78
+ description: Save stuff you do not expect, in your database.
63
79
  email:
64
80
  - daniellibanori@gmail.com
65
81
  executables: []
@@ -68,22 +84,22 @@ extra_rdoc_files: []
68
84
  files:
69
85
  - .gitignore
70
86
  - .rbenv-version
87
+ - .travis.yml
71
88
  - Gemfile
72
89
  - Guardfile
73
90
  - LICENSE.txt
74
91
  - README.md
75
92
  - Rakefile
76
- - examples/config.yml
77
- - examples/some.rb
78
93
  - examples/usage.rb
79
94
  - lib/pickle-surprise.rb
80
95
  - lib/pickle-surprise/pickle.rb
81
96
  - lib/pickle-surprise/version.rb
82
97
  - pickle-surprise.gemspec
98
+ - pickle-surprise.jpg
83
99
  - spec/pickle-surprise/pickle_spec.rb
84
100
  - spec/pickle-surprise_spec.rb
85
101
  - spec/spec_helper.rb
86
- homepage: http://dlibanori.github.com
102
+ homepage: https://github.com/dlibanori/pickle-surprise
87
103
  licenses: []
88
104
  post_install_message:
89
105
  rdoc_options: []
@@ -106,7 +122,7 @@ rubyforge_project:
106
122
  rubygems_version: 1.8.23
107
123
  signing_key:
108
124
  specification_version: 3
109
- summary: Where is the pickle? It is not a surprise anymore...
125
+ summary: Where is the pickle? It's not a surprise anymore
110
126
  test_files:
111
127
  - spec/pickle-surprise/pickle_spec.rb
112
128
  - spec/pickle-surprise_spec.rb
data/examples/config.yml DELETED
@@ -1,6 +0,0 @@
1
- development:
2
- sessions:
3
- default:
4
- database: pickle_surprise
5
- hosts:
6
- - localhost:27017
data/examples/some.rb DELETED
@@ -1,21 +0,0 @@
1
- require 'pickle-surprise'
2
-
3
- class Some
4
- include Pickle::Surprise
5
-
6
- def thing
7
- raise 'Where is the pickle?'
8
- rescue
9
- Pickle msg: 'That is surprise!'
10
- end
11
-
12
- def raiser
13
- # boring code
14
-
15
- Pickle ns: 'my namespace' do
16
- raise 'Fuuu...'
17
- end
18
-
19
- # more boring code
20
- end
21
- end