1 |
module Sprig |
13✔ |
2 |
class Planter |
13✔ |
3 |
def initialize(seeds) |
13✔ |
4 |
@seeds = seeds.to_a
|
507✔ |
5 |
end
|
|
6 |
|
|
7 |
def sprig |
13✔ |
8 |
dependency_sorted_seeds.each do |seed|
|
507✔ |
9 |
plant(seed) |
585✔ |
10 |
end
|
|
11 |
|
|
12 |
notifier.finished |
421✔ |
13 |
end
|
|
14 |
|
|
15 |
private |
13✔ |
16 |
|
|
17 |
attr_reader :seeds
|
13✔ |
18 |
|
|
19 |
def dependency_sorted_seeds |
13✔ |
20 |
DependencySorter.new(seeds).sorted_items
|
507✔ |
21 |
end
|
|
22 |
|
|
23 |
def notifier |
13✔ |
24 |
@notifier ||= ProcessNotifier.new |
1,557✔ |
25 |
end
|
|
26 |
|
|
27 |
def plant(seed) |
13✔ |
28 |
notifier.in_progress(seed) |
585✔ |
29 |
seed.before_save |
585✔ |
30 |
|
|
|
if Sprig.configuration.raise_on_error? |
577✔ |
|
seed.save_record! |
× |
|
elsif seed.save_record
|
577✔ |
34 |
seed.save_to_store |
525✔ |
35 |
notifier.success(seed) |
525✔ |
36 |
else
|
|
37 |
notifier.error(seed) |
26✔ |
38 |
end
|
|
39 |
end
|
|
40 |
end
|
|
41 |
end
|