chores_kit 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57e00f3e3593a294b34065a8b782ce8b372b731c2144f1bde908b6b09045dcb7
4
- data.tar.gz: 23f17d66edd7779450dbcc775bc62690efde2ae323b4f8ad5bca317e59cd72c9
3
+ metadata.gz: 8f8d0d9332511a0b3ea54f12041a0d4817480a5241555171a4f4e04d52844b3c
4
+ data.tar.gz: 021ca51509f4f48b92ab4f9464078e336526358d8d23d1574c68137cf1fa7afe
5
5
  SHA512:
6
- metadata.gz: 6a0b9107cb1cbc7ef7027d2ab85c5f7f3903c7050267b471e790a2e263ba3ebfa528ca83c6be9de5fb72f750b136021cd6f1bd723263a35af72723d1c4dc15d7
7
- data.tar.gz: 1aaca6ff7a5a524af95fe57298130f520362d40cab85f7db08e6206cd9d00f712e03ffb8bd6afb40e1e789953c2cef096b6b624c6d1feef92a2eb31b0667418a
6
+ metadata.gz: 71262510387093914fef6573c7dc562711f0be156ddaf8f720e50a72fd49f7fd694af63f3918a5fa93ba3cdcec9bc01eb30dff78658fbb70d68c8817741cb255
7
+ data.tar.gz: b1c5acbe208b916732fb12a1162895fda63f7c3decb6941daa5a1ab0d80b619e71421c2424632cb26d4546cba3e84a2e949962f6d18cec2667a49e8a88395a7b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chores_kit (0.2.2)
4
+ chores_kit (0.2.3)
5
5
  as-duration (~> 0.1.1)
6
6
  dag (~> 0.0.9)
7
7
 
@@ -56,12 +56,31 @@ module ChoresKit
56
56
  raise "Couldn't create task without a name" if name.nil?
57
57
  raise "Couldn't create task without a block" unless block_given?
58
58
 
59
- @dag.add_vertex(task: Task.new(name, params, &block))
59
+ @dag.add_vertex(name: name, task: Task.new(name, params, &block))
60
60
  end
61
61
 
62
- def run(task, options)
62
+ def run(task, options = {})
63
63
  from = options[:triggered_by] || options[:upstream] || task
64
64
  to = options[:triggers] || options[:downstream] || task
65
+
66
+ tasks = @tasks.map(&:name)
67
+ direction = options[:upstream] || options[:triggered_by] ? 'upstream' : 'downstream'
68
+
69
+ # Throw an error if either up- or downstream task doesn't exist
70
+ non_existing_tasks = ([from, to] - tasks).uniq
71
+ raise "Couldn't set #{direction} dependency for non-existing task #{non_existing_tasks.first}" if non_existing_tasks.any?
72
+
73
+ # Throw an error if unsupported dependencies are set
74
+ raise "Multiple upstream tasks aren't supported" if from.is_a?(Array)
75
+ raise "Multiple downstream tasks aren't supported" if to.is_a?(Array)
76
+
77
+ # Skip any processing if there is just one task
78
+ return if tasks.one?
79
+
80
+ v1 = @dag.vertices.detect { |vertex| vertex[:name] == from }
81
+ v2 = @dag.vertices.detect { |vertex| vertex[:name] == to }
82
+
83
+ @dag.add_edge(from: v1, to: v2)
65
84
  end
66
85
 
67
86
  # After-run callbacks
@@ -1,8 +1,6 @@
1
1
  module ChoresKit
2
2
  class DAG
3
3
  class Vertex < ::DAG::Vertex
4
- attr_reader :task
5
-
6
4
  def name
7
5
  task.name
8
6
  end
@@ -1,3 +1,3 @@
1
1
  module ChoresKit
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chores_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lennard Timm
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-16 00:00:00.000000000 Z
11
+ date: 2018-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: as-duration