This repository has been archived by the owner on Jun 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
default.rb
67 lines (60 loc) · 1.77 KB
/
default.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
module Cellect
module Server
module Adapters
class Default
# Return a list of workflows to load in the form:
# [{
# 'id' => 123,
# 'name' => 'foo',
# 'prioritized' => false,
# 'pairwise' => false,
# 'grouped' => false
# }, ...]
def workflow_list(*names)
raise NotImplementedError
end
# Load the data for a workflow, this method:
# Accepts a workflow
# Returns an array of hashes in the form:
# {
# 'id' => 123,
# 'priority' => 0.123,
# 'group_id' => 456
# }
def load_data_for(workflow_name)
raise NotImplementedError
end
# Load seen ids for a user, this method:
# Accepts a workflow_name, and a user id
# Returns an array in the form:
# [1, 2, 3]
def load_user(workflow_name, id)
raise NotImplementedError
end
# Report adapter status as a Hash
def status
{ }
end
def load_workflows(*names)
workflow_list(*names).each{ |workflow_info| load_workflow workflow_info }
end
def load_workflow(args)
info = if args.is_a?(Hash)
args
elsif args.is_a?(String)
workflow_list.select{ |h| h['name'] == args }.first
else
raise ArgumentError
end
workflow_for info
end
def workflow_for(opts = { })
workflow_klass = opts.fetch('grouped', false) ? GroupedWorkflow : Workflow
workflow_klass[opts['name']] = opts
workflow_klass[opts['name']].load_data
workflow_klass[opts['name']]
end
end
end
end
end