Dex 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +12 -1
- data/lib/Dex.rb +8 -3
- data/lib/Dex/version.rb +1 -1
- data/spec/Dex.rb +20 -0
- data/spec/libs/main.rb +9 -0
- metadata +2 -2
data/README.md
CHANGED
@@ -26,10 +26,21 @@ Usage
|
|
26
26
|
begin
|
27
27
|
raise
|
28
28
|
rescue Object => e
|
29
|
-
Dex.
|
29
|
+
Dex.insert $!
|
30
30
|
raise e
|
31
31
|
end
|
32
32
|
|
33
|
+
You can also create your own fields:
|
34
|
+
|
35
|
+
Dex.insert $!, :HTTP_USER_AGENT=> the_agent
|
36
|
+
|
37
|
+
You can also override default fields like `:status` or `:created_at`:
|
38
|
+
|
39
|
+
Dex.insert $?, :created_at=>Time.now, :status=>1
|
40
|
+
|
41
|
+
Are you importing errors from log files? You can treat a Hash as an exception:
|
42
|
+
|
43
|
+
Dex.insert :exception=>"Nginx Error", :message=>"Upstream closed", :backtrace=>[]
|
33
44
|
|
34
45
|
Run Tests
|
35
46
|
---------
|
data/lib/Dex.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'Dex/version'
|
2
2
|
require 'sequel'
|
3
|
+
require 'ostruct'
|
3
4
|
|
4
5
|
class Dex
|
5
6
|
|
@@ -85,6 +86,10 @@ class Dex
|
|
85
86
|
end
|
86
87
|
|
87
88
|
def insert e, other=Hash[]
|
89
|
+
if e.is_a?(Hash)
|
90
|
+
e = OpenStruct.new(e)
|
91
|
+
end
|
92
|
+
|
88
93
|
unless other.keys.empty?
|
89
94
|
keys=other.keys.map(&:to_sym)
|
90
95
|
new_keys = keys - fields
|
@@ -98,9 +103,9 @@ class Dex
|
|
98
103
|
end
|
99
104
|
|
100
105
|
h = Hash[
|
101
|
-
:message => e.message,
|
102
|
-
:exception => e.exception.class.name,
|
103
|
-
:backtrace => e.backtrace.join("\n"),
|
106
|
+
:message => e.message || "Unknown",
|
107
|
+
:exception => e.exception.is_a?(String) ? e.exception : (e.exception ? e.exception.class.name : "Unknown"),
|
108
|
+
:backtrace => (e.backtrace && e.backtrace.join("\n")) || "",
|
104
109
|
:status => 0,
|
105
110
|
:created_at => Time.now.utc
|
106
111
|
]
|
data/lib/Dex/version.rb
CHANGED
data/spec/Dex.rb
CHANGED
@@ -119,6 +119,26 @@ describe "Dex :insert" do
|
|
119
119
|
}
|
120
120
|
end
|
121
121
|
|
122
|
+
it "allows :created_at to be overridden" do
|
123
|
+
dex = new_dex "created_at"
|
124
|
+
target = Time.now
|
125
|
+
|
126
|
+
rollback(dex) {
|
127
|
+
dex.insert( except("Optional Hash"), :created_at=>target )
|
128
|
+
last(dex)[:created_at].to_s.should == target.to_s
|
129
|
+
}
|
130
|
+
end
|
131
|
+
|
132
|
+
it "accepts a Hash instead of an exception" do
|
133
|
+
dex = new_dex "custom hash"
|
134
|
+
rollback(dex) {
|
135
|
+
dex.insert :exception=>"Nginx Error", :message=>"upstream not found", :backtrace=>["file:12:txt"]
|
136
|
+
last(dex)[:exception].should == "Nginx Error"
|
137
|
+
last(dex)[:message].should == "upstream not found"
|
138
|
+
last(dex)[:backtrace].should == "file:12:txt"
|
139
|
+
}
|
140
|
+
end
|
141
|
+
|
122
142
|
end # === Dex :insert
|
123
143
|
|
124
144
|
describe "Dex :keep_only" do
|
data/spec/libs/main.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Dex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
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-05-
|
12
|
+
date: 2012-05-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bacon
|