mushy 0.21.2 → 0.24.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.
@@ -1,32 +1,26 @@
1
- module Mushy
2
-
3
- class Cli < Flux
4
-
5
- def self.details
6
- {
7
- name: 'Cli',
8
- title: 'Start a flow via command line',
9
- fluxGroup: { name: 'Starters', position: 0 },
10
- description: 'Accept CLI arguments from the run command.',
11
- config: {
12
- },
13
- examples: {
14
- "Calling From The Command Line" => {
15
- description: 'Calling the CLI with command-line arguments.',
16
- input: "mushy start file first:John last:Doe",
17
- result: {
18
- "first": "John",
19
- "last": "Doe"
20
- }
21
- },
1
+ class Mushy::Cli < Mushy::Flux
2
+ def self.details
3
+ {
4
+ name: 'Cli',
5
+ title: 'Start a flow via command line',
6
+ fluxGroup: { name: 'Starters', position: 0 },
7
+ description: 'Accept CLI arguments from the run command.',
8
+ config: {
9
+ },
10
+ examples: {
11
+ 'Calling From The Command Line' => {
12
+ description: 'Calling the CLI with command-line arguments.',
13
+ input: 'mushy start file first:John last:Doe',
14
+ result: {
15
+ first: 'John',
16
+ last: 'Doe'
22
17
  }
18
+ }
23
19
  }
24
- end
25
-
26
- def process event, config
27
- event
28
- end
29
-
20
+ }
30
21
  end
31
22
 
32
- end
23
+ def process(event, _)
24
+ event
25
+ end
26
+ end
@@ -1,43 +1,37 @@
1
- module Mushy
2
-
3
- class Document < Flux
4
-
5
- def self.details
6
- {
7
- name: 'Document',
8
- title: 'Make a multi-line liquid value',
9
- description: 'Create a multi-line document.',
10
- fluxGroup: { name: 'Flows' },
11
- config: {
12
- document: {
13
- description: 'The multi-line document you wish to create.',
14
- type: 'textarea',
15
- value: '',
16
- },
17
- },
18
- examples: {
19
- "Example" => {
20
- description: 'Using this Flux to build a document',
21
- input: {
22
- people: [ { name: "John" }, { name: "Jane" } ]
23
- },
24
- config: {
25
- document: '{% for person in people %} {{ person.name }} {% endfor %}'
26
- },
27
- result: {
28
- document: ' John Jane ',
29
- }
30
- },
1
+ class Mushy::Document < Mushy::Flux
2
+ def self.details
3
+ {
4
+ name: 'Document',
5
+ title: 'Make a multi-line liquid value',
6
+ description: 'Create a multi-line document.',
7
+ fluxGroup: { name: 'Flows' },
8
+ config: {
9
+ document: {
10
+ description: 'The multi-line document you wish to create.',
11
+ type: 'textarea',
12
+ value: ''
13
+ }
14
+ },
15
+ examples: {
16
+ 'Example' => {
17
+ description: 'Using this Flux to build a document',
18
+ input: {
19
+ people: [{ name: 'John' }, { name: 'Jane' }]
20
+ },
21
+ config: {
22
+ document: '{% for person in people %} {{ person.name }} {% endfor %}'
23
+ },
24
+ result: {
25
+ document: ' John Jane '
31
26
  }
27
+ }
32
28
  }
33
- end
34
-
35
- def process event, config
36
- {
37
- document: config[:document],
38
- }
39
- end
40
-
29
+ }
41
30
  end
42
31
 
43
- end
32
+ def process(_, config)
33
+ {
34
+ document: config[:document]
35
+ }
36
+ end
37
+ end
@@ -1,41 +1,28 @@
1
- module Mushy
2
-
3
- class Environment < Flux
4
-
5
- def self.details
6
- {
7
- name: 'Environment',
8
- title: 'Pull environment variables',
9
- description: 'Pull environment variables.',
10
- fluxGroup: { name: 'Environment' },
11
- config: {
12
- variables: {
13
- description: 'Map the environment variables to a new event.',
14
- type: 'keyvalue',
15
- value: {},
16
- },
17
- },
18
- examples: {
19
- "Example" => {
20
- description: 'Get environmental variables.',
21
- config: {
22
- variables: { text_domain: 'TEXTDOMAIN' }
23
- },
24
- result: {
25
- text_domain: 'Linux-PAM',
26
- }
27
- },
1
+ class Mushy::Environment < Mushy::Flux
2
+ def self.details
3
+ {
4
+ name: 'Environment',
5
+ title: 'Pull environment variables',
6
+ description: 'Pull environment variables.',
7
+ fluxGroup: { name: 'Environment' },
8
+ config: {
9
+ variables: {
10
+ description: 'Map the environment variables to a new event.',
11
+ type: 'keyvalue',
12
+ value: {}
13
+ }
14
+ },
15
+ examples: {
16
+ 'Example' => {
17
+ description: 'Get environmental variables.',
18
+ config: { variables: { text_domain: 'TEXTDOMAIN' } },
19
+ result: { text_domain: 'Linux-PAM' }
28
20
  }
29
21
  }
30
- end
31
-
32
- def process event, config
33
- config[:variables].reduce({}) do |t, i|
34
- t[i[0]] = ENV[i[1]]
35
- t
36
- end
37
- end
38
-
22
+ }
39
23
  end
40
24
 
25
+ def process(_, config)
26
+ config[:variables].each_with_object({}) { |t, i| t[i[0]] = ENV[i[1]] }
27
+ end
41
28
  end
@@ -1,93 +1,130 @@
1
1
  require 'listen'
2
2
 
3
- module Mushy
4
-
5
- class FileWatch < Flux
6
-
7
- def self.details
8
- {
9
- name: 'FileWatch',
10
- title: 'Start a flow when files change',
11
- fluxGroup: { name: 'Starters', position: 0 },
12
- description: 'Watch for file changes.',
13
- config: {
14
- directory: {
15
- description: 'The directory to watch, defaults to the current directory.',
16
- type: 'text',
17
- shrink: true,
18
- value: '',
19
- },
20
- include_all_file_details: {
21
- description: 'If true, returns all details for the file. If false, just path & name are returned',
22
- type: 'boolean',
23
- shrink: true,
24
- value: '',
25
- }
3
+ class Mushy::FileWatch < Mushy::Flux
4
+ def self.details
5
+ {
6
+ name: 'FileWatch',
7
+ title: 'Start a flow when files change',
8
+ fluxGroup: { name: 'Starters', position: 0 },
9
+ description: 'Watch for file changes.',
10
+ config: {
11
+ directory: {
12
+ description: 'The directory to watch, defaults to the current directory.',
13
+ type: 'text',
14
+ shrink: true,
15
+ value: ''
16
+ },
17
+ include_all_file_details: {
18
+ description: 'If true, returns all details for the file. If false, just path & name are returned.',
19
+ type: 'boolean',
20
+ shrink: true,
21
+ value: ''
22
+ },
23
+ merge_all_file_changes: {
24
+ description: 'If true, all changes are merged into one "files". If false, added/modified/removed are returned separately.',
25
+ type: 'boolean',
26
+ shrink: true,
27
+ value: ''
28
+ },
29
+ include_added: {
30
+ description: 'Include added fields, defaults to true.',
31
+ type: 'boolean',
32
+ shrink: true,
33
+ value: ''
26
34
  },
27
- examples: {
28
- "Files Added" => {
29
- description: 'When a file is added, this type of result will be returned.',
30
- result: {
31
- modified: [],
32
- added: [ { path: '/home/pi/Desktop/mushy/bin/hey.txt', directory: '/home/pi/Desktop/mushy/bin', name: 'hey.txt' } ],
33
- removed:[]
34
- }
35
- },
36
- "Files Removed" => {
37
- description: 'When a file is deleted, this type of result will be returned.',
38
- result: {
39
- modified: [],
40
- added: [],
41
- removed:[{ path: '/home/pi/Desktop/mushy/mushy-0.15.3.gem', directory: '/home/pi/Desktop/mushy', name: 'mushy-0.15.3.gem'} ]
42
- }
43
- },
44
- "Files Modified" => {
45
- description: 'When a file is modified, this type of result will be returned.',
46
- result: {
47
- modified: [ { path: '/home/pi/Desktop/mushy/lib/mushy/fluxs/environment.rb', directory: '/home/pi/Desktop/mushy/lib/mushy/fluxs/environment.rb', name: 'environment.rb' } ],
48
- added: [],
49
- removed:[]
50
- }
51
- },
35
+ include_modified: {
36
+ description: 'Include modified fields, defaults to true.',
37
+ type: 'boolean',
38
+ shrink: true,
39
+ value: ''
40
+ },
41
+ include_removed: {
42
+ description: 'Include removed fields, defaults to true.',
43
+ type: 'boolean',
44
+ shrink: true,
45
+ value: ''
46
+ }
47
+ },
48
+ examples: {
49
+ 'Files Added' => {
50
+ description: 'When a file is added, this type of result will be returned.',
51
+ result: {
52
+ modified: [],
53
+ added: [{ path: '/home/pi/Desktop/mushy/bin/hey.txt', directory: '/home/pi/Desktop/mushy/bin', name: 'hey.txt' }],
54
+ removed: []
55
+ }
56
+ },
57
+ 'Files Removed' => {
58
+ description: 'When a file is deleted, this type of result will be returned.',
59
+ result: {
60
+ modified: [],
61
+ added: [],
62
+ removed: [{ path: '/home/pi/Desktop/mushy/mushy-0.15.3.gem', directory: '/home/pi/Desktop/mushy', name: 'mushy-0.15.3.gem'}]
63
+ }
64
+ },
65
+ 'Files Modified' => {
66
+ description: 'When a file is modified, this type of result will be returned.',
67
+ result: {
68
+ modified: [{ path: '/home/pi/Desktop/mushy/lib/mushy/fluxs/environment.rb', directory: '/home/pi/Desktop/mushy/lib/mushy/fluxs/environment.rb', name: 'environment.rb' }],
69
+ added: [],
70
+ removed: []
71
+ }
52
72
  }
53
73
  }
74
+ }
75
+ end
76
+
77
+ def loop(&block)
78
+ directory = config[:directory].to_s != '' ? config[:directory] : Dir.pwd
79
+
80
+ listener = Listen.to(directory) do |modified, added, removed|
81
+ block.call convert_changes_to_event(modified, added, removed, config)
54
82
  end
55
83
 
56
- def loop(&block)
57
- directory = config[:directory].to_s != '' ? config[:directory] : Dir.pwd
84
+ listener.start
58
85
 
59
- listener = Listen.to(directory) do |modified, added, removed|
60
- the_event = {
61
- modified: modified.map { |f| get_the_details_for(f) },
62
- added: added.map { |f| get_the_details_for(f) },
63
- removed: removed.map { |f| get_the_details_for(f) }
64
- }
65
- block.call the_event
66
- end
86
+ sleep
87
+ end
67
88
 
68
- listener.start
89
+ def process(event, _)
90
+ event
91
+ end
69
92
 
70
- sleep
93
+ def test(_, config)
94
+ modified = [Mushy::Ls.new.process({}, {}).select { |x| x[:type] == '-' }.sample]
95
+ .compact
96
+ .map { |x| x[:path] }
97
+ convert_changes_to_event(modified, [], [], config)
98
+ end
71
99
 
72
- end
100
+ def convert_changes_to_event(modified, added, removed, config)
101
+ modified = [] if config[:include_modified].to_s == 'false'
102
+ added = [] if config[:include_added].to_s == 'false'
103
+ removed = [] if config[:include_removed].to_s == 'false'
73
104
 
74
- def process event, config
75
- event
76
- end
105
+ result = {
106
+ modified: modified.map { |f| get_the_details_for(f, config) },
107
+ added: added.map { |f| get_the_details_for(f, config) },
108
+ removed: removed.map { |f| get_the_details_for(f, config) }
109
+ }
77
110
 
78
- def get_the_details_for(file)
79
- if config[:include_all_file_details].to_s == 'true'
80
- Mushy::Ls.new.process({}, { path: file })[0]
81
- else
82
- segments = file.split("\/")
83
- {
84
- path: file,
85
- name: segments.pop,
86
- directory: segments.join("\/")
87
- }
88
- end
89
- end
111
+ return result unless config[:merge_all_file_changes].to_s == 'true'
90
112
 
113
+ {
114
+ files: [:added, :modified, :removed].map { |x| result[x] }.flatten
115
+ }
91
116
  end
92
117
 
93
- end
118
+ def get_the_details_for(file, config)
119
+ if config[:include_all_file_details].to_s == 'true'
120
+ Mushy::Ls.new.process({}, { path: file })[0]
121
+ else
122
+ segments = file.split("\/")
123
+ {
124
+ path: file,
125
+ name: segments.pop,
126
+ directory: segments.join("\/")
127
+ }
128
+ end
129
+ end
130
+ end
@@ -1,45 +1,35 @@
1
1
  require 'csv'
2
2
 
3
- module Mushy
4
-
5
- class WriteJson < Flux
6
-
7
- def self.details
8
- {
9
- name: 'WriteJson',
10
- title: 'Serialize as JSON',
11
- description: 'Write the incoming event as JSON.',
12
- fluxGroup: { name: 'JSON' },
13
- config: {
14
- key: {
15
- description: 'The key of the outgoing field that will contain the JSON.',
16
- type: 'text',
17
- value: 'json',
18
- },
19
- },
20
- examples: {
21
- "Example" => {
22
- description: 'Using this Flux to convert input to a JSON string.',
23
- input: {
24
- people: [ { name: "John" }, { name: "Jane" } ]
25
- },
26
- config: {
27
- key: 'apple'
28
- },
29
- result: {
30
- apple: "{\"people\":[{\"name\":\"John\"},{\"name\":\"Jane\"}]}"
31
- }
32
- },
33
- }
34
- }
35
- end
36
-
37
- def process event, config
38
- {
39
- config[:key] => event.to_json
3
+ class Mushy::WriteJson < Mushy::Flux
4
+ def self.details
5
+ {
6
+ name: 'WriteJson',
7
+ title: 'Serialize as JSON',
8
+ description: 'Write the incoming event as JSON.',
9
+ fluxGroup: { name: 'JSON' },
10
+ config: {
11
+ key: {
12
+ description: 'The key of the outgoing field that will contain the JSON.',
13
+ type: 'text',
14
+ value: 'json'
15
+ }
16
+ },
17
+ examples: {
18
+ 'Example' => {
19
+ description: 'Using this Flux to convert input to a JSON string.',
20
+ input: {
21
+ people: [{ name: 'John' }, { name: 'Jane' }]
22
+ },
23
+ config: { key: 'apple' },
24
+ result: { apple: '{"people":[{"name":"John"},{"name":"Jane"}]}' }
25
+ }
40
26
  }
41
- end
42
-
27
+ }
43
28
  end
44
29
 
45
- end
30
+ def process(event, config)
31
+ {
32
+ config[:key] => event.to_json
33
+ }
34
+ end
35
+ end
data/lib/mushy.rb CHANGED
@@ -4,15 +4,15 @@ require 'symbolized'
4
4
  Dir[File.dirname(__FILE__) + '/mushy/*.rb'].each { |f| require f }
5
5
 
6
6
  important_flux_files = [
7
- 'bash',
8
- 'browser',
9
- 'simple_python_program',
10
- ].map { |x| "#{x}.rb" }
7
+ :bash,
8
+ :browser,
9
+ :simple_python_program
10
+ ].map { |x| "#{x}.rb" }
11
11
 
12
12
  Dir[File.dirname(__FILE__) + '/mushy/fluxs/*.rb']
13
- .map { |x| [x, important_flux_files.find_index(x.split("\/")[-1]) || 9999999] }
13
+ .map { |x| [x, important_flux_files.find_index(x.split("\/")[-1]) || 9_999_999] }
14
14
  .sort_by { |x| x[1] }
15
15
  .map { |x| x[0] }
16
16
  .each { |f| require f }
17
17
 
18
- Dir[File.dirname(__FILE__) + '/mushy/builder/*.rb'].each { |f| require f }
18
+ Dir[File.dirname(__FILE__) + '/mushy/builder/*.rb'].each { |f| require f }
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.21.2'
7
+ s.version = '0.24.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.21.2
4
+ version: 0.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Cauthon