mushy 0.1.3 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f516df95fc3919dd7d02ffe32228fd96364c06a56595ae8a7e986d406abc3af
4
- data.tar.gz: c2dc07c4f8ad462134d674aeb4006eeabff5a07abee0d20d1ec5ff89312f80e7
3
+ metadata.gz: 8c7cd35133c18b25798aa2d8f41b917435e2eb2c766c8bd0798413bd86787d54
4
+ data.tar.gz: 06bf70b427dbb2ae5611cfe6d7fce4f6eff1910b291a768fc22ff6de67dd7330
5
5
  SHA512:
6
- metadata.gz: b2e8a4bc112300daeb8089a455c10ef7c6842524a0a8dc3a00aa0c8715ecee836eff17f89c461ead76ae4ba716c56e49e436be57e8f163de3a57d8fe8249e816
7
- data.tar.gz: ef23272c88796185deb60fd11ad9a326b3dd4a84d2df7aa86830727e72408811eda47a2fb13e59cb481b6a0fb0ad505a7ee4c606cf50b6478e7dc0d7303c0371
6
+ metadata.gz: 6b382bab1d6384c96b0c0b3da3e94fb6adb578103b8372509719288dcbb82b2b0e19d9b3a6711ad0dd678ded5af296d527d4142de9bfe2446d7dda464aeaf7ed
7
+ data.tar.gz: 00e17640e86de55782f0876318d8a1c18415c0a8f80f8c2891a79b28ddf7260ee8c199b67d3e78ea6ea7c2f710453df33297ccc10d58caab4bfcc47548c0ccad
data/bin/mushy CHANGED
@@ -5,7 +5,7 @@ require 'mushy'
5
5
 
6
6
  class MushyCLI < Thor
7
7
 
8
- argument :file
8
+ argument :file, optional: true, type: :string
9
9
  argument :values, optional: true, type: :hash
10
10
 
11
11
  desc "start FILE", "Run this workflow file."
data/lib/mushy.rb CHANGED
@@ -3,15 +3,9 @@ require 'symbolized'
3
3
 
4
4
  Dir[File.dirname(__FILE__) + '/mushy/*.rb'].each { |f| require f }
5
5
 
6
- important_flux_files = ['bash'].map { |x| "#{x}.rb" }
6
+ important_flux_files = ['bash', 'browser'].map { |x| "#{x}.rb" }
7
7
  Dir[File.dirname(__FILE__) + '/mushy/fluxs/*.rb']
8
8
  .sort_by { |f| important_flux_files.any? { |x| f.end_with?(x) } ? 0 : 1 }
9
9
  .each { |f| require f }
10
10
 
11
- Dir[File.dirname(__FILE__) + '/mushy/builder/*.rb'].each { |f| require f }
12
-
13
- module Mushy
14
- def self.hi
15
- puts 'hello'
16
- end
17
- end
11
+ Dir[File.dirname(__FILE__) + '/mushy/builder/*.rb'].each { |f| require f }
@@ -40,7 +40,17 @@ module Mushy
40
40
  def self.get_flow file
41
41
  puts "trying to get: #{file}"
42
42
  file = "#{file}.json" unless file.downcase.end_with?('.json')
43
- JSON.parse File.open(file).read
43
+ data = JSON.parse File.open(file).read
44
+ data['fluxs']
45
+ .reject { |x| x['parents'] }
46
+ .each { |x| x['parents'] = [x['parent']].select { |y| y } }
47
+ data['fluxs']
48
+ .select { |x| x['parent'] }
49
+ .each { |x| x.delete 'parent' }
50
+ data['fluxs']
51
+ .select { |x| x['parents'] }
52
+ .each { |x| x['parents'] = x['parents'].select { |y| y } }
53
+ data
44
54
  rescue
45
55
  { fluxs: [] }
46
56
  end
@@ -20,16 +20,14 @@ module Mushy
20
20
  </tr>
21
21
  <tr v-for="flux in flow.fluxs">
22
22
  <td>{{flux.name}}</td>
23
- <td>{{flux_name_for(flux.parent, flow.fluxs)}}</td>
23
+ <td>{{flux_name_for(flux.parents, flow.fluxs)}}</td>
24
24
  <td>
25
25
  <button v-on:click.prevent.stop="editFlux({ flux: flux, setup: setup, configs: configs })">Edit</button>
26
26
  <button v-on:click.prevent.stop="deleteFlux({ flux: flux, flow: flow })">Delete</button>
27
27
  </td>
28
28
  </tr>
29
29
  </table>
30
- <button v-if="setup.showFlux == false" v-on:click.prevent.stop="startNew({ setup: setup, configs: configs })">Start a New Flux</button>
31
- <button v-if="setup.showFlux == false" v-on:click.prevent.stop="saveFlow({ setup: setup, flow: flow })">Save This Flow</button>
32
- <button v-if="setup.showFlux" v-on:click.prevent.stop="setup.showFlux = false">&lt; Go Back To List</button>
30
+ <button v-if="setup.showFlux == false" v-on:click.prevent.stop="startNew({ setup: setup, configs: configs })">Add a New Flux To This Flow</button>
33
31
  <div v-if="setup.showFlux">
34
32
  <mip-heavy :data="setup"></mip-heavy>
35
33
  <mip-heavy v-for="(data, id) in configs" v-show="setup.flux.value === id" :data="data"></mip-heavy>
@@ -109,7 +107,7 @@ module Mushy
109
107
  };
110
108
  },
111
109
  props: ['label', 'placeholder', 'disabled', 'readonly', 'value', 'description', 'view'],
112
- template: '<div><mip-h4 :id="id" :label="label" :description="description"></mip-h4> <pre><code>{{show(view, value)}}</code></pre><button :disabled="view==\\'beautiful\\'" v-on:click.prevent.stop="view=toggle(view)">{{(view == \\'beautiful\\' ? \\'View Smaller\\' : \\'View Pretty\\')}}</button><button :disabled="view!=\\'beautiful\\'" v-on:click.prevent.stop="view=toggle(view)">View Smaller</button><button v-on:click.prevent.stop="copy(view, value)">Copy</button></div>'
110
+ template: '<div><mip-h4 :id="id" :label="label" :description="description"></mip-h4> <pre><code>{{show(view, value)}}</code></pre><button :disabled="view==\\'beautiful\\'" v-on:click.prevent.stop="view=toggle(view)">View Pretty</button><button :disabled="view!=\\'beautiful\\'" v-on:click.prevent.stop="view=toggle(view)">View Smaller</button><button v-on:click.prevent.stop="copy(view, value)">Copy</button></div>'
113
111
  },
114
112
  radio: {
115
113
  props: ['label', 'value', 'options', 'description', 'shrink'],
@@ -123,6 +121,32 @@ module Mushy
123
121
  props: ['label', 'value', 'options', 'description', 'shrink'],
124
122
  template: '<div><mip-label :id="id" :label="label" :description="description" :hide_description="shrink"></mip-label> <a href="#" v-on:click.prevent.stop="shrink=false" v-show="shrink && !value">[^]</a><select :name="id" v-if="value || !shrink" v-on:input="$emit(\\'update:value\\', $event.target.value)"><option v-for="option in options" v-bind:value="option.id" :selected="value == option.id">{{option.name}}</option></select></div>'
125
123
  },
124
+ selectmanyrecords: {
125
+ data: function() {
126
+ return {
127
+ selectedValue: '',
128
+ remove: function(value, set) {
129
+ if (set.includes(value) == false) return;
130
+ for(var i = 0; i < set.length; i++)
131
+ {
132
+ if (set[i] === value)
133
+ {
134
+ set.splice(i, 1);
135
+ i--;
136
+ }
137
+ }
138
+ return set;
139
+ },
140
+ doit: function(value, set) {
141
+ if (set.includes(value) == false)
142
+ set.push(value);
143
+ return set;
144
+ },
145
+ };
146
+ },
147
+ props: ['label', 'value', 'options', 'description', 'shrink'],
148
+ template: '<div><mip-label :id="id" :label="label" :description="description" :hide_description="shrink"></mip-label> <a href="#" v-on:click.prevent.stop="shrink=false" v-show="shrink && !value">[^]</a> <span v-for="option in options" v-if="value && value.includes(option.id)">{{option.name}} <a href="#" v-on:click.prevent.stop="remove(option.id, value);$emit(\\'update:value\\', value)">[X]</a> </span> <a href="#" v-on:click.prevent.stop="doit(selectedValue, value);$emit(\\'update:value\\', value)">ADD</a> <select :name="id" v-if="value || !shrink" v-on:input="selectedValue=$event.target.value;"><option v-for="option in options" v-bind:value="option.id">{{option.name}}</option></select></div>'
149
+ },
126
150
  boolean: {
127
151
  props: ['label', 'value', 'options', 'description', 'shrink'],
128
152
  template: '<div><mip-label :id="id" :label="label" :description="description" :hide_description="shrink"></mip-label> <a href="#" v-on:click.prevent.stop="shrink=false" v-show="shrink && !value">[^]</a><select :name="id" v-if="(value != undefined && value != null && value != \\'\\') || !shrink" v-on:input="$emit(\\'update:value\\', $event.target.value)"><option v-for="option in [true, false]" v-bind:value="option" :selected="value == option">{{option}}</option></select></div>'
@@ -240,44 +264,63 @@ module Mushy
240
264
  for(var type in fluxTypes)
241
265
  options.push(fluxTypes[type]);
242
266
 
267
+ var saveTheFlux = function(input)
268
+ {
269
+ var theApp = input.app;
270
+ var config = input.config;
271
+ delete config.test_event;
272
+ var setup = thingToData(theApp.setup);
273
+ var flux = {
274
+ id: setup.id,
275
+ name: setup.name,
276
+ flux: setup.flux,
277
+ parents: setup.parents,
278
+ config: config,
279
+ };
280
+ var index = -1;
281
+ for(var i = 0; i < theApp.flow.fluxs.length; i++)
282
+ if (theApp.flow.fluxs[i].id == flux.id)
283
+ index = i;
284
+
285
+ if (index < 0)
286
+ theApp.flow.fluxs.push(flux);
287
+ else
288
+ theApp.flow.fluxs[index] = flux;
289
+ };
290
+
291
+ var saveTheFlow = function(input)
292
+ {
293
+ var setup = input.setup;
294
+ var flow = input.flow;
295
+ axios.post('/save', flow)
296
+ .then(function(result){});
297
+ };
298
+
299
+ var saveFlux = function(config) {
300
+ };
301
+
302
+ var ignoreFlux = function(config) {
303
+ };
304
+
243
305
  var setup = {
244
306
  showFlux: false,
245
307
  id: { type: 'hide', value: '' },
246
308
  name: { type: 'text', value: '' },
247
309
  flux: { type: 'select', value: fluxdata.fluxs[0].name, options: options},
248
- parent: { type: 'selectrecord', label: 'Receive Events From', value: '', options: flowdata.fluxs },
310
+ parents: { type: 'selectmanyrecords', label: 'Receive Events From', value: '', options: flowdata.fluxs },
249
311
  };
250
312
 
251
313
  for (var key in configs)
252
314
  {
253
- configs[key].save = { type: 'button', name: 'Save This Flux', click: function(config, hey) {
254
- var nameOfTheSaveButton = hey.save.name;
255
- Vue.set(hey.save, 'name', 'Saving');
256
- delete config.test_event;
257
- var setup = thingToData(app.setup);
258
- var flux = {
259
- id: setup.id,
260
- name: setup.name,
261
- flux: setup.flux,
262
- parent: setup.parent,
263
- config: config,
264
- };
265
- var index = -1;
266
- for(var i = 0; i < app.flow.fluxs.length; i++)
267
- if (app.flow.fluxs[i].id == flux.id)
268
- index = i;
269
- if (index < 0)
270
- app.flow.fluxs.push(flux);
271
- else
272
- app.flow.fluxs[index] = flux;
273
-
274
- setTimeout(function(){
275
- Vue.set(hey.save, 'name', nameOfTheSaveButton);
276
- app.setup.id.value = '';
277
-
278
- Vue.set(app.setup, 'showFlux', false);
279
- }, 500);
280
- }
315
+ configs[key].save = { type: 'button', name: 'Save Changes', click: function(config) {
316
+ saveTheFlux({ app: app, config: config });
317
+ saveTheFlow({ setup: app.setup, flow: app.flow });
318
+ app.setup.showFlux = false;
319
+ }
320
+ };
321
+ configs[key].cancel = { type: 'button', name: 'Ignore Changes', click: function() {
322
+ app.setup.showFlux = false;
323
+ }
281
324
  };
282
325
 
283
326
  configs[key].test_event = { type: 'json', value: '{}', default: '{}' };
@@ -317,7 +360,7 @@ module Mushy
317
360
  Vue.set(setup.id, 'value', flux.id);
318
361
  Vue.set(setup.name, 'value', flux.name);
319
362
  Vue.set(setup.flux, 'value', flux.flux);
320
- Vue.set(setup.parent, 'value', flux.parent);
363
+ Vue.set(setup.parents, 'value', flux.parents);
321
364
 
322
365
  var applicable_config = configs[flux.flux];
323
366
  for(var key in applicable_config)
@@ -331,7 +374,7 @@ module Mushy
331
374
 
332
375
  options = flowdata.fluxs.filter(function(x){ return x.id != flux.id });
333
376
  options.unshift( { id: '', name: '' } );
334
- setup.parent.options = options;
377
+ setup.parents.options = options;
335
378
 
336
379
  Vue.set(setup, 'showFlux', true);
337
380
  app.results = [];
@@ -351,6 +394,7 @@ module Mushy
351
394
  flux = {
352
395
  id: uuidv4(),
353
396
  name: '',
397
+ parents: [],
354
398
  config: {}
355
399
  };
356
400
  loadThisFlux({ flux: flux, setup: x.setup, configs: x.configs });
@@ -375,9 +419,9 @@ module Mushy
375
419
  },
376
420
  configs: configs,
377
421
  setup: setup,
378
- flux_name_for: function(id, fluxes) {
379
- var flux = fluxes.filter(function(x){ return x.id == id })[0];
380
- return flux != undefined ? flux.name : '';
422
+ flux_name_for: function(ids, fluxes) {
423
+ var fluxs = fluxes.filter(function(x){ return ids.includes(x.id) });
424
+ return fluxs.map(function(x){ return x.name }).join(', ');
381
425
  },
382
426
  results: [],
383
427
  }
data/lib/mushy/flow.rb CHANGED
@@ -30,14 +30,14 @@ module Mushy
30
30
  data = JSON.parse data
31
31
 
32
32
  data_fluxs = data['fluxs'] || []
33
- data_fluxs.select { |x| x['parent'] }.map { |r| r["parent_fluxs"] = [r["parent"]] }
33
+ data_fluxs.select { |x| x['parent'] }.map { |r| r["parents"] = [r["parent"]] }
34
34
 
35
35
  flow = new
36
36
 
37
37
  flow.fluxs = data_fluxs.map { |s| build_flux s }
38
38
 
39
39
  fluxs_with_parent_ids = flow.fluxs.reduce({}) { |t, i| t[i.id] = []; t }
40
- data_fluxs.map { |r| fluxs_with_parent_ids[r['id']] = r['parent_fluxs'] || [] }
40
+ data_fluxs.map { |r| fluxs_with_parent_ids[r['id']] = r['parents'] || [] }
41
41
 
42
42
  flow.fluxs.each do |flux|
43
43
  flux.parent_fluxs = flow.fluxs.select { |x| fluxs_with_parent_ids[flux.id].include?(x.id) }
@@ -51,10 +51,10 @@ module Mushy
51
51
  ],
52
52
  },
53
53
  carry_cookies_from: {
54
- description: 'Carry the cookies from this path in the event.',
54
+ description: 'Carry the cookies from this path in the event. Defaults to "cookies".',
55
55
  type: 'text',
56
56
  shrink: true,
57
- value: 'cookies',
57
+ value: '',
58
58
  },
59
59
  headers: {
60
60
  description: 'Headers for the web request. These can be received from a previous browser event with {{headers}}, or can be typed manually.',
@@ -63,10 +63,10 @@ module Mushy
63
63
  value: {},
64
64
  },
65
65
  carry_headers_from: {
66
- description: 'Carry the headers from this path in the event.',
66
+ description: 'Carry the headers from this path in the event. Defaults to "headers".',
67
67
  type: 'text',
68
68
  shrink: true,
69
- value: 'headers',
69
+ value: '',
70
70
  },
71
71
  wait_before_closing: {
72
72
  description: 'Wait this many seconds before closing the browser.',
@@ -105,13 +105,20 @@ module Mushy
105
105
  body: browser.body
106
106
  }
107
107
 
108
+ result = special_browser_action browser, result
109
+
108
110
  browser.quit
109
111
 
110
112
  result
111
113
  end
112
114
 
115
+ def special_browser_action browser, result
116
+ result
117
+ end
118
+
113
119
  def get_the_cookies_from event, config
114
- cookies = (event[config[:carry_cookies_from].to_sym])
120
+ carry_cookies_from = config[:carry_cookies_from].to_s == '' ? 'cookies' : config[:carry_cookies_from]
121
+ cookies = event[carry_cookies_from.to_sym]
115
122
  cookies = [] unless cookies.is_a?(Array)
116
123
  config[:cookies] = [] unless config[:cookies].is_a?(Array)
117
124
  config[:cookies].each { |x| cookies << x }
@@ -119,7 +126,8 @@ module Mushy
119
126
  end
120
127
 
121
128
  def get_the_headers_from event, config
122
- headers = (event[config[:carry_headers_from].to_sym])
129
+ carry_headers_from = config[:carry_headers_from].to_s == '' ? 'headers' : config[:carry_headers_from]
130
+ headers = event[carry_headers_from.to_sym]
123
131
  headers = {} unless headers.is_a?(Hash)
124
132
  config[:headers] = {} unless config[:headers].is_a?(Hash)
125
133
  config[:headers].each { |k, v| headers[k] = v }
@@ -4,10 +4,30 @@ module Mushy
4
4
 
5
5
  class ReadCsv < Flux
6
6
 
7
+ def self.details
8
+ {
9
+ name: 'ReadCsv',
10
+ description: 'Read CSV content into events.',
11
+ config: {
12
+ data: {
13
+ description: 'The data to convert to a CSV.',
14
+ type: 'text',
15
+ value: '{{data}}',
16
+ },
17
+ headers: {
18
+ description: 'The CSV contains headers. Defaults to false.',
19
+ type: 'boolean',
20
+ shrink: true,
21
+ value: '',
22
+ },
23
+ },
24
+ }
25
+ end
26
+
7
27
  def process event, config
8
- data = event[config[:key]]
28
+ data = config[:data]
9
29
 
10
- headers = config[:headers].to_s.strip.downcase == 'true' ? true : false
30
+ headers = config[:headers].to_s.strip.downcase == 'true'
11
31
 
12
32
  rows = CSV.new data, headers: headers
13
33
 
@@ -0,0 +1,44 @@
1
+ module Mushy
2
+
3
+ class ReadFile < Flux
4
+
5
+ def self.details
6
+ {
7
+ name: 'ReadFile',
8
+ description: 'Read a file.',
9
+ config: {
10
+ name: {
11
+ description: 'The name of the file to read.',
12
+ type: 'text',
13
+ value: 'file.csv',
14
+ },
15
+ directory: {
16
+ description: 'The directory in which to read the file. Leave blank for the current directory.',
17
+ type: 'text',
18
+ shrink: true,
19
+ value: '',
20
+ },
21
+ path: {
22
+ description: 'The path in the event to return the contents of the file.',
23
+ type: 'text',
24
+ value: 'content',
25
+ },
26
+ },
27
+ }
28
+ end
29
+
30
+ def process event, config
31
+ file = config[:name]
32
+
33
+ file = File.join(config[:directory], file) if config[:directory].to_s != ''
34
+
35
+ content = File.open(file).read
36
+
37
+ {
38
+ config[:path] => content
39
+ }
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,46 @@
1
+ module Mushy
2
+
3
+ class Screenshot < Browser
4
+
5
+ def self.details
6
+ details = Browser.details
7
+ details['name'] = 'Screenshot'
8
+ details['description'] = 'Take a screenshot of the browser.'
9
+
10
+ details[:config][:path] = {
11
+ description: 'The path of the file to save.',
12
+ type: 'text',
13
+ value: 'picture.jpg',
14
+ }
15
+ details[:config][:quality] = {
16
+ description: 'The quality of the image, a value beteen 0-100. Only applies to jpg.',
17
+ type: 'integer',
18
+ shrink: true,
19
+ value: '',
20
+ }
21
+ details[:config][:full] = {
22
+ description: 'Take a screenshot of the entire page. If false, the screenshot is limited to the viewport.',
23
+ type: 'boolean',
24
+ shrink: true,
25
+ value: '',
26
+ }
27
+ details
28
+ end
29
+
30
+ def special_browser_action browser, result
31
+
32
+ options = {
33
+ path: config[:path],
34
+ full: ['true', ''].include?(config[:full].to_s),
35
+ quality: (config[:quality].to_s == '' ? '100' : config[:quality]).to_i
36
+ }
37
+
38
+ browser.screenshot options
39
+
40
+ options
41
+
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -27,12 +27,15 @@ module Mushy
27
27
  end
28
28
 
29
29
  def process event, config
30
+ file = config[:name]
30
31
 
31
- File.open(config[:name], 'w') { |f| f.write config[:data] }
32
+ file = File.join(config[:directory], file) if config[:directory].to_s != ''
33
+
34
+ File.open(file, 'w') { |f| f.write config[:data] }
32
35
 
33
36
  {}
34
37
  end
35
38
 
36
39
  end
37
40
 
38
- end
41
+ 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.1.3'
7
+ s.version = '0.2.3'
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.1.3
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Cauthon
@@ -150,6 +150,8 @@ files:
150
150
  - lib/mushy/fluxs/ls.rb
151
151
  - lib/mushy/fluxs/parse_html.rb
152
152
  - lib/mushy/fluxs/read_csv.rb
153
+ - lib/mushy/fluxs/read_file.rb
154
+ - lib/mushy/fluxs/screenshot.rb
153
155
  - lib/mushy/fluxs/write_file.rb
154
156
  - lib/mushy/masher.rb
155
157
  - lib/mushy/run.rb