/
lang.rb
43 lines (40 loc) · 1.07 KB
/
lang.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require 'statuslang/ruby_lang_extensions'
module StatusLang
class Lang
def initialize(sentry_id)
@sentry_id = sentry_id
end
def last(amount=nil)
if amount
if amount.is_a?(Duration)
options[:after] = amount.ago
elsif amount.is_a?(Integer)
options[:limit] = amount
else
raise ArgumentError, "amount must be a Duration or an Integer!"
end
end
self
end
def posts
if @options[:after]
Event.find(:all, :conditions => {:recordable_type => "Sentry", :recordable_id => @sentry_id, :created_at.gte => @options[:after]})
elsif @options[:limit]
Event.find(:all, :conditions => {:recordable_type => "Sentry", :recordable_id => @sentry_id}, :limit => @options[:limit])
end
end
def post
Event.find(:last, :conditions => {:recordable_type => "Sentry", :recordable_id => @sentry_id})
end
def all_posts
posts.all
end
def any_post
posts.any
end
private
def options
@options ||= {}
end
end
end