mushy 0.21.2 → 0.22.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,96 @@
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
+ },
24
+ examples: {
25
+ 'Files Added' => {
26
+ description: 'When a file is added, this type of result will be returned.',
27
+ result: {
28
+ modified: [],
29
+ added: [{ path: '/home/pi/Desktop/mushy/bin/hey.txt', directory: '/home/pi/Desktop/mushy/bin', name: 'hey.txt' }],
30
+ removed: []
31
+ }
32
+ },
33
+ 'Files Removed' => {
34
+ description: 'When a file is deleted, this type of result will be returned.',
35
+ result: {
36
+ modified: [],
37
+ added: [],
38
+ removed: [{ path: '/home/pi/Desktop/mushy/mushy-0.15.3.gem', directory: '/home/pi/Desktop/mushy', name: 'mushy-0.15.3.gem'}]
39
+ }
26
40
  },
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
- },
41
+ 'Files Modified' => {
42
+ description: 'When a file is modified, this type of result will be returned.',
43
+ result: {
44
+ modified: [{ path: '/home/pi/Desktop/mushy/lib/mushy/fluxs/environment.rb', directory: '/home/pi/Desktop/mushy/lib/mushy/fluxs/environment.rb', name: 'environment.rb' }],
45
+ added: [],
46
+ removed: []
47
+ }
52
48
  }
53
49
  }
54
- end
55
-
56
- def loop(&block)
57
- directory = config[:directory].to_s != '' ? config[:directory] : Dir.pwd
50
+ }
51
+ end
58
52
 
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
53
+ def loop(&block)
54
+ directory = config[:directory].to_s != '' ? config[:directory] : Dir.pwd
67
55
 
68
- listener.start
56
+ listener = Listen.to(directory) do |modified, added, removed|
57
+ block.call convert_changes_to_event(modified, added, removed, config)
58
+ end
69
59
 
70
- sleep
60
+ listener.start
71
61
 
72
- end
62
+ sleep
63
+ end
73
64
 
74
- def process event, config
75
- event
76
- end
65
+ def process(event, _)
66
+ event
67
+ end
77
68
 
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
69
+ def test(_, config)
70
+ modified = [Mushy::Ls.new.process({}, {}).select { |x| x[:type] == '-' }.sample]
71
+ .compact
72
+ .map { |x| x[:path] }
73
+ convert_changes_to_event(modified, [], [], config)
74
+ end
90
75
 
76
+ def convert_changes_to_event(modified, added, removed, config)
77
+ {
78
+ modified: modified.map { |f| get_the_details_for(f, config) },
79
+ added: added.map { |f| get_the_details_for(f, config) },
80
+ removed: removed.map { |f| get_the_details_for(f, config) }
81
+ }
91
82
  end
92
83
 
93
- end
84
+ def get_the_details_for(file, config)
85
+ if config[:include_all_file_details].to_s == 'true'
86
+ Mushy::Ls.new.process({}, { path: file })[0]
87
+ else
88
+ segments = file.split("\/")
89
+ {
90
+ path: file,
91
+ name: segments.pop,
92
+ directory: segments.join("\/")
93
+ }
94
+ end
95
+ end
96
+ 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.22.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.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Cauthon