Dex 0.4.2 → 0.4.3
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/lib/Dex.rb +32 -27
- data/lib/Dex/version.rb +1 -1
- data/spec/Dex.rb +16 -0
- metadata +1 -1
data/lib/Dex.rb
CHANGED
@@ -86,41 +86,46 @@ class Dex
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def insert e, other=Hash[]
|
89
|
-
|
90
|
-
|
89
|
+
msg = :message
|
90
|
+
bt = :backtrace
|
91
|
+
ex = :exception
|
92
|
+
stat = :status
|
93
|
+
|
94
|
+
final = Hash[ msg => 'Unknown', ex => 'Unknown', stat => 0, :created_at=>Time.now.utc ]
|
95
|
+
if e.respond_to?(:exception)
|
96
|
+
final[ msg ] = e.message
|
97
|
+
final[ bt ] = e.backtrace
|
98
|
+
final[ ex ] = e.exception.class.name
|
99
|
+
else
|
100
|
+
final.update e
|
91
101
|
end
|
92
102
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
103
|
+
final.update other
|
104
|
+
|
105
|
+
keys = final.keys.map(&:to_sym)
|
106
|
+
new_keys = keys - fields
|
107
|
+
|
108
|
+
unless new_keys.empty?
|
109
|
+
db.alter_table table_name do
|
110
|
+
new_keys.each { |k|
|
111
|
+
add_column k, :string
|
112
|
+
}
|
102
113
|
end
|
103
114
|
end
|
104
115
|
|
105
|
-
|
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")) || "",
|
109
|
-
:status => 0,
|
110
|
-
:created_at => Time.now.utc
|
111
|
-
]
|
116
|
+
final[ bt ] = (final[bt] || []).join("\n")
|
112
117
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
118
|
+
final.keys.each { |k|
|
119
|
+
v = final[k]
|
120
|
+
case v
|
121
|
+
when Array, Hash
|
122
|
+
final[k] = v.inspect
|
123
|
+
else
|
124
|
+
final[k] = v
|
125
|
+
end
|
121
126
|
}
|
122
127
|
|
123
|
-
table.insert
|
128
|
+
table.insert final
|
124
129
|
end
|
125
130
|
|
126
131
|
def remove_field name
|
data/lib/Dex/version.rb
CHANGED
data/spec/Dex.rb
CHANGED
@@ -139,6 +139,22 @@ describe "Dex :insert" do
|
|
139
139
|
}
|
140
140
|
end
|
141
141
|
|
142
|
+
it "accepts a single Hash with an overriding :created_at" do
|
143
|
+
dex = new_dex "custom hash"
|
144
|
+
rollback(dex) {
|
145
|
+
dex.insert :exception=>"Nginx Error", :message=>"upstream not found", :backtrace=>["file:12:txt"], :created_at=>Time.parse("2001/01/01 01:01:01")
|
146
|
+
last(dex)[:created_at].to_s.should == Time.parse("2001/01/01 01:01:01").to_s
|
147
|
+
}
|
148
|
+
end
|
149
|
+
|
150
|
+
it "accepts a single Hash with an overriding :status" do
|
151
|
+
dex = new_dex "custom hash"
|
152
|
+
rollback(dex) {
|
153
|
+
dex.insert :exception=>"Nginx Error", :message=>"upstream not found", :backtrace=>["file:12:txt"], :status=>1
|
154
|
+
last(dex)[:status].should == 1
|
155
|
+
}
|
156
|
+
end
|
157
|
+
|
142
158
|
end # === Dex :insert
|
143
159
|
|
144
160
|
describe "Dex :keep_only" do
|