Module: Dex::DSL
- Included in:
- Dex
- Defined in:
- lib/Dex.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &blok) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/Dex.rb', line 75
def method_missing *args, &blok
if table.respond_to?(args.first)
table.send *args, &blok
else
super
end
end
|
Instance Method Details
#db(name = :_RETURN_) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/Dex.rb', line 27
def db name = :_RETURN_
if name != :_RETURN_
@db = begin
db_file name
db = Sequel.sqlite db_file
db.create_table?(Dex.default_table) {
primary_key :id
String :message
String :exception
Text :backtrace
Integer :status
DateTime :created_at
}
db
end
@table = nil
end
@db ||= db(Dex.default_db)
end
|
#db_file(f = :_R_) ⇒ Object
16
17
18
19
|
# File 'lib/Dex.rb', line 16
def db_file f = :_R_
return @db_file if f == :_R_
@db_file = f
end
|
#insert(e) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/Dex.rb', line 57
def insert e
table.insert \
:message => e.message, \
:exception => e.exception.class.name, \
:backtrace => e.backtrace.join("\n"),
:status => 0,
:created_at => Time.now.utc
end
|
#keep_only(n = 250) ⇒ Object
21
22
23
24
25
|
# File 'lib/Dex.rb', line 21
def keep_only n = 250
c = table.count
return false unless c > 250
table.filter( :id=> Dex.table.select(:id).limit( c-n ) ).delete
end
|
#recent(n = 10) ⇒ Object
66
67
68
69
70
71
72
73
|
# File 'lib/Dex.rb', line 66
def recent n = 10
ds = table.reverse_order(:created_at, :id).limit(n)
if n < 2
ds.first
else
ds
end
end
|
#table(name = :_RETURN_) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/Dex.rb', line 50
def table name = :_RETURN_
if name != :_RETURN_
@table = db[name]
end
@table ||= table(:dex_exceptions)
end
|