1 | fs = require "fs"
|
2 | path = require "path"
|
3 | step = require "stepc"
|
4 | outcome = require "outcome"
|
5 | Commands = require "./commands"
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | module.exports = class Factory
|
14 |
|
15 | |
16 |
|
17 |
|
18 | constructor: () ->
|
19 | @_classes = []
|
20 | @commands = new Commands @
|
21 |
|
22 | |
23 |
|
24 |
|
25 |
|
26 | add: (clazz) ->
|
27 |
|
28 | clazz.priority = 0 if not clazz.priority
|
29 |
|
30 | @_classes.push clazz
|
31 |
|
32 | @_classes = @_classes.sort (a, b) ->
|
33 | if a.priority > b.priority
|
34 | return -1
|
35 | else
|
36 | return 1
|
37 |
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 | newTask: (route, ops, parent) ->
|
44 |
|
45 |
|
46 | for clazz in @_classes
|
47 |
|
48 | if clazz.test ops
|
49 |
|
50 |
|
51 | task = new clazz route, @, parent
|
52 |
|
53 |
|
54 | task.load ops
|
55 |
|
56 |
|
57 | return task
|
58 |
|
59 |
|
60 | null |
\ | No newline at end of file |