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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3310d89eada814ea6146a796ad78267d592b81b2cf7bdc002e765dfb9eb35e20
4
- data.tar.gz: 7e2aa3b6a63d8e0f4d9c7291e1c1eecb7103374fa87302c5c4ad4ff1498f05a0
3
+ metadata.gz: ed2624dde9bf79c8dd70a430474613a591b647ba78c67cb04078da5ddfb64940
4
+ data.tar.gz: 42ea21e12bdea8fc767aee5e30c4d9c32a82ab83c786ea7bb101fcc3f7b1d154
5
5
  SHA512:
6
- metadata.gz: ff438b38489fc1d26111448873640973e25a9ffb02b4e498bff78919eb4d21bf3a954729c2296f673df218b324c07cc9d9635a0d24081f9b0bef1aa12cd04895
7
- data.tar.gz: c5d9e71047c5bbced7129b429144ff9b5b110083e84c5efe8681920b6c0d20948f1445162708e2ba658b9d86ac8a2abb1734a4cd73b4a08e2ec5bd65212f4832
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
@@ -8,6 +8,7 @@ module Mushy
8
8
  attr_accessor :subscribed_to
9
9
  attr_accessor :config
10
10
  attr_accessor :masher
11
+ attr_accessor :flow
11
12
 
12
13
  def initialize
13
14
  guard
@@ -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: 'id',
15
- value: { url: 'a|@href' },
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
- event[config[:id]]
35
+ config[:id]
38
36
  end
39
37
 
40
38
  def all event, config
41
- self.collection.values
39
+ the_collection(config).values
42
40
  end
43
41
 
44
42
  def delete event, config
45
- self.collection.delete get_the_id(event, config)
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 self.collection[get_the_id(event, config)]
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 = self.collection[get_the_id(event, config)]
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
- self.collection[get_the_id(event, config)] = event
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.9.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.'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mushy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Cauthon