Module: SessionCountdown
Constant Summary
collapse
- @@default_name =
"default"
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
sanity checkpoint for some methods, checking for existing countdown
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/session_countdown.rb', line 25
def method_missing(method, *args)
method = "_#{method}"
raise NoMethodError unless respond_to?(method)
insist_countdown_exists(*args)
send(method, *args)
end
|
Instance Method Details
#_countdown_abort(name = @@default_name) ⇒ Object
these methods all require a sanity check for existing countdown
42
43
44
|
# File 'lib/session_countdown.rb', line 42
def _countdown_abort(name = @@default_name)
self[get_zero_key(name)] = nil
end
|
#_countdown_count(name = @@default_name) ⇒ Object
50
51
52
53
|
# File 'lib/session_countdown.rb', line 50
def _countdown_count(name = @@default_name)
remaining = (self[get_zero_key(name)] - Time.now)
(remaining > 0) ? remaining : 0
end
|
#_countdown_restart(name = @@default_name) ⇒ Object
46
47
48
|
# File 'lib/session_countdown.rb', line 46
def _countdown_restart(name = @@default_name)
self[get_zero_key(name)] = Time.now + self[get_zero_delta_key(name)]
end
|
#countdown_expired?(name = @@default_name) ⇒ Boolean
20
21
22
|
# File 'lib/session_countdown.rb', line 20
def countdown_expired?(name = @@default_name)
self[get_zero_key(name)] && ! countdown_running?(name)
end
|
#countdown_running?(name = @@default_name) ⇒ Boolean
16
17
18
|
# File 'lib/session_countdown.rb', line 16
def countdown_running?(name = @@default_name)
self[get_zero_key(name)] && self[get_zero_key(name)] > Time.now
end
|
#countdown_start(delta, name = @@default_name) ⇒ Object
11
12
13
14
|
# File 'lib/session_countdown.rb', line 11
def countdown_start(delta, name = @@default_name)
self[get_zero_key(name)] = Time.now + delta
self[get_zero_delta_key(name)] = delta end
|