-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathmodels.rb
More file actions
40 lines (32 loc) · 1.44 KB
/
models.rb
File metadata and controls
40 lines (32 loc) · 1.44 KB
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
module CloudCrowd
# Adds named scopes and query methods for every CloudCrowd status to
# both Jobs and WorkUnits.
module ModelStatus
def self.included(klass)
klass.class_eval do
# Note that COMPLETE and INCOMPLETE are unions of other states.
scope 'processing', :conditions => {:status => PROCESSING}
scope 'succeeded', :conditions => {:status => SUCCEEDED}
scope 'failed', :conditions => {:status => FAILED}
scope 'splitting', :conditions => {:status => SPLITTING}
scope 'merging', :conditions => {:status => MERGING}
scope 'complete', :conditions => {:status => COMPLETE}
scope 'incomplete', :conditions => {:status => INCOMPLETE}
end
end
def processing?; self.status == PROCESSING; end
def succeeded?; self.status == SUCCEEDED; end
def failed?; self.status == FAILED; end
def splitting?; self.status == SPLITTING; end
def merging?; self.status == MERGING; end
def complete?; COMPLETE.include?(self.status); end
def incomplete?; INCOMPLETE.include?(self.status); end
# Get the displayable status name of the model's status code.
def display_status
CloudCrowd.display_status(self.status)
end
end
end
require 'cloud_crowd/models/job'
require 'cloud_crowd/models/node_record'
require 'cloud_crowd/models/work_unit'