mushy 0.21.2 → 0.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/mushy +5 -9
- data/lib/mushy/builder/api.rb +146 -152
- data/lib/mushy/builder/index.rb +1 -0
- data/lib/mushy/flux.rb +2 -1
- data/lib/mushy/fluxs/bash.rb +50 -58
- data/lib/mushy/fluxs/browser.rb +232 -240
- data/lib/mushy/fluxs/build_csv.rb +60 -68
- data/lib/mushy/fluxs/cli.rb +22 -28
- data/lib/mushy/fluxs/document.rb +33 -39
- data/lib/mushy/fluxs/environment.rb +23 -36
- data/lib/mushy/fluxs/file_watch.rb +114 -77
- data/lib/mushy/fluxs/write_json.rb +30 -40
- data/lib/mushy.rb +6 -6
- data/mushy.gemspec +1 -1
- metadata +1 -1
data/lib/mushy/fluxs/cli.rb
CHANGED
@@ -1,32 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
{
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
25
|
-
|
26
|
-
def process event, config
|
27
|
-
event
|
28
|
-
end
|
29
|
-
|
20
|
+
}
|
30
21
|
end
|
31
22
|
|
32
|
-
|
23
|
+
def process(event, _)
|
24
|
+
event
|
25
|
+
end
|
26
|
+
end
|
data/lib/mushy/fluxs/document.rb
CHANGED
@@ -1,43 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
-
|
34
|
-
|
35
|
-
def process event, config
|
36
|
-
{
|
37
|
-
document: config[:document],
|
38
|
-
}
|
39
|
-
end
|
40
|
-
|
29
|
+
}
|
41
30
|
end
|
42
31
|
|
43
|
-
|
32
|
+
def process(_, config)
|
33
|
+
{
|
34
|
+
document: config[:document]
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
@@ -1,41 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
{
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
57
|
-
directory = config[:directory].to_s != '' ? config[:directory] : Dir.pwd
|
84
|
+
listener.start
|
58
85
|
|
59
|
-
|
60
|
-
|
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
|
-
|
89
|
+
def process(event, _)
|
90
|
+
event
|
91
|
+
end
|
69
92
|
|
70
|
-
|
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
|
-
|
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
|
-
|
75
|
-
|
76
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
42
|
-
|
27
|
+
}
|
43
28
|
end
|
44
29
|
|
45
|
-
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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]) ||
|
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.
|
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.'
|