mushy 0.9.0 → 0.10.0
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 +4 -4
- data/lib/mushy/flow.rb +8 -1
- data/lib/mushy/flux.rb +1 -0
- data/lib/mushy/fluxs/collection.rb +33 -15
- data/mushy.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed2624dde9bf79c8dd70a430474613a591b647ba78c67cb04078da5ddfb64940
|
4
|
+
data.tar.gz: 42ea21e12bdea8fc767aee5e30c4d9c32a82ab83c786ea7bb101fcc3f7b1d154
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b904acfb460d9e6e5515274d7b435700b7e26903dbcdcc69471f0bf521f50c67dd6a0fd4857e95de3836d1cbf40c7facc4968ead6cec4d70b8e47a4ac77d0cb7
|
7
|
+
data.tar.gz: 4b9ceca6ce17b561ec36c84ba31f9772beb0557b02b6da5f703b2699622c3de2b6a272c2a4627bee1a653283c988db4be4dc92a58fed181f6baf51c26cbdc7b0
|
data/lib/mushy/flow.rb
CHANGED
@@ -29,9 +29,16 @@ module Mushy
|
|
29
29
|
flux.id = record[:id] || record['id'] || flux.id
|
30
30
|
flux.type = type
|
31
31
|
flux.config = SymbolizedHash.new(record[:config] || record['config'])
|
32
|
+
flux.flow = Mushy::Flow.new
|
32
33
|
flux
|
33
34
|
end
|
34
35
|
|
36
|
+
def build_flux record
|
37
|
+
Mushy::Flow.build_flux(record).tap do |flux|
|
38
|
+
flux.flow = self
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
35
42
|
def self.parse data
|
36
43
|
data = JSON.parse data
|
37
44
|
|
@@ -40,7 +47,7 @@ module Mushy
|
|
40
47
|
|
41
48
|
flow = new
|
42
49
|
|
43
|
-
flow.fluxs = data_fluxs.map { |s| build_flux s }
|
50
|
+
flow.fluxs = data_fluxs.map { |s| flow.build_flux s }
|
44
51
|
|
45
52
|
fluxs_with_parent_ids = flow.fluxs.reduce({}) { |t, i| t[i.id] = []; t }
|
46
53
|
data_fluxs.map { |r| fluxs_with_parent_ids[r['id']] = r['parents'] || [] }
|
data/lib/mushy/flux.rb
CHANGED
@@ -2,8 +2,6 @@ module Mushy
|
|
2
2
|
|
3
3
|
class Collection < Flux
|
4
4
|
|
5
|
-
attr_accessor :collection
|
6
|
-
|
7
5
|
def self.details
|
8
6
|
{
|
9
7
|
name: 'Collection',
|
@@ -11,9 +9,14 @@ module Mushy
|
|
11
9
|
config: {
|
12
10
|
id: {
|
13
11
|
description: 'The path to the unique id in the body of the element.',
|
14
|
-
type: '
|
15
|
-
value: {
|
12
|
+
type: 'text',
|
13
|
+
value: '{{id}}',
|
16
14
|
},
|
15
|
+
collection_name: {
|
16
|
+
description: 'The name of the collection to interact with.',
|
17
|
+
type: 'text',
|
18
|
+
value: 'records',
|
19
|
+
},
|
17
20
|
operation: {
|
18
21
|
description: 'Perform this operation.',
|
19
22
|
type: 'select',
|
@@ -24,31 +27,26 @@ module Mushy
|
|
24
27
|
}
|
25
28
|
end
|
26
29
|
|
27
|
-
def initialize
|
28
|
-
self.collection = {}
|
29
|
-
super
|
30
|
-
end
|
31
|
-
|
32
30
|
def process event, config
|
33
31
|
self.send(config[:operation].to_sym, event, config)
|
34
32
|
end
|
35
33
|
|
36
34
|
def get_the_id event, config
|
37
|
-
|
35
|
+
config[:id]
|
38
36
|
end
|
39
37
|
|
40
38
|
def all event, config
|
41
|
-
|
39
|
+
the_collection(config).values
|
42
40
|
end
|
43
41
|
|
44
42
|
def delete event, config
|
45
|
-
|
43
|
+
the_collection(config).delete get_the_id(event, config)
|
46
44
|
event[config[:operation_performed]] = 'deleted' if config[:operation_performed]
|
47
45
|
event
|
48
46
|
end
|
49
47
|
|
50
48
|
def upsert event, config
|
51
|
-
if
|
49
|
+
if the_collection(config)[get_the_id(event, config)]
|
52
50
|
update event, config
|
53
51
|
else
|
54
52
|
insert event, config
|
@@ -56,18 +54,38 @@ module Mushy
|
|
56
54
|
end
|
57
55
|
|
58
56
|
def update event, config
|
59
|
-
item =
|
57
|
+
item = the_collection(config)[get_the_id(event, config)]
|
60
58
|
event.each { |k, v| item[k] = v } if item
|
61
59
|
event[config[:operation_performed]] = (item ? 'updated' : 'not exist') if config[:operation_performed]
|
62
60
|
event
|
63
61
|
end
|
64
62
|
|
65
63
|
def insert event, config
|
66
|
-
|
64
|
+
the_collection(config)[get_the_id(event, config)] = event
|
67
65
|
event[config[:operation_performed]] = 'inserted' if config[:operation_performed]
|
68
66
|
event
|
69
67
|
end
|
70
68
|
|
69
|
+
def the_collection config
|
70
|
+
Mushy::Collection.guard_the_flow self.flow
|
71
|
+
the_collection_name = config[:collection_name]
|
72
|
+
|
73
|
+
get_the_collection the_collection_name
|
74
|
+
end
|
75
|
+
|
76
|
+
def get_the_collection name
|
77
|
+
found_collection = self.flow.collection_data[name]
|
78
|
+
return found_collection if found_collection
|
79
|
+
self.flow.collection_data[name] = SymbolizedHash.new
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.guard_the_flow flow
|
83
|
+
return if flow.respond_to?(:collection_data)
|
84
|
+
|
85
|
+
flow.instance_eval { class << self; self end }.send(:attr_accessor, :collection_data)
|
86
|
+
flow.collection_data = {}
|
87
|
+
end
|
88
|
+
|
71
89
|
end
|
72
90
|
|
73
91
|
end
|
data/mushy.gemspec
CHANGED
@@ -4,7 +4,7 @@ require 'mushy/version'
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'mushy'
|
7
|
-
s.version = '0.
|
7
|
+
s.version = '0.10.0'
|
8
8
|
s.date = '2020-11-23'
|
9
9
|
s.summary = 'Process streams of work using common modules.'
|
10
10
|
s.description = 'This tool assists in the creation and processing of workflows.'
|