mushy 0.1.4 → 0.2.4

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: 2eaed069f8d37db0a6d58fea9c994e4a5135f43a18a7e7ad8421a601983bb954
4
- data.tar.gz: 3224715b652898edaac99ad89a8378ccc4d2aa4ba21b891ca33fec0b99252a85
3
+ metadata.gz: 1dffff192ce9f7784515f5b4c73a1ac15720cc2e8cb5a6a5836b34dd5049eb52
4
+ data.tar.gz: 247eeecec22765e28eb98e850982e8ef06ec3e969257da56e0923baadc237b9d
5
5
  SHA512:
6
- metadata.gz: df28cc21a604e023284ad3f88b2cd11a3ab4261c3cd9747a2033d07528203262de29daa2d12f82e404eb91109b79ee9a5e5a5bf71396c360e26ff270d08a2449
7
- data.tar.gz: 05410eb4c9fee4afd4aa31397409b6c794bc152257cf599aa4fb1502cb7009c518b9fac2eb76b3f78ca1e58e2a31e28e6dcd6c5266febb8bddd7ea7fbe7fdea1
6
+ metadata.gz: 1a85f196c4c86ad29b3a96d90356cd74264a443cdfaf58a4662a407f4ef01bb2cb7cbd1098f3a20c57a2d3f901160b5ddbf309f6c6d03fcc8d1c691ba08ed9d7
7
+ data.tar.gz: 386d48b9ba0aaa610dca7675f780ab186aedf15ae14b3a31e41c119d5e427b0bcd1f58b7f17d6395b6e6625cbdcd328861512507b14bbc3b5681648f1382ac4a
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,47 +264,64 @@ module Mushy
240
264
  for(var type in fluxTypes)
241
265
  options.push(fluxTypes[type]);
242
266
 
243
- var setup = {
244
- showFlux: false,
245
- id: { type: 'hide', value: '' },
246
- name: { type: 'text', value: '' },
247
- flux: { type: 'select', value: fluxdata.fluxs[0].name, options: options},
248
- parent: { type: 'selectrecord', label: 'Receive Events From', value: '', options: flowdata.fluxs },
249
- };
250
-
251
- var saveFlux = function(config, hey) {
252
- var nameOfTheSaveButton = hey.save.name;
253
- Vue.set(hey.save, 'name', 'Saving');
267
+ var saveTheFlux = function(input)
268
+ {
269
+ var theApp = input.app;
270
+ var config = input.config;
254
271
  delete config.test_event;
255
- var setup = thingToData(app.setup);
272
+ var setup = thingToData(theApp.setup);
256
273
  var flux = {
257
274
  id: setup.id,
258
275
  name: setup.name,
259
276
  flux: setup.flux,
260
- parent: setup.parent,
277
+ parents: setup.parents,
261
278
  config: config,
262
279
  };
263
280
  var index = -1;
264
- for(var i = 0; i < app.flow.fluxs.length; i++)
265
- if (app.flow.fluxs[i].id == flux.id)
281
+ for(var i = 0; i < theApp.flow.fluxs.length; i++)
282
+ if (theApp.flow.fluxs[i].id == flux.id)
266
283
  index = i;
267
284
 
268
285
  if (index < 0)
269
- app.flow.fluxs.push(flux);
286
+ theApp.flow.fluxs.push(flux);
270
287
  else
271
- app.flow.fluxs[index] = flux;
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
+ };
272
298
 
273
- setTimeout(function(){
274
- Vue.set(hey.save, 'name', nameOfTheSaveButton);
275
- app.setup.id.value = '';
299
+ var saveFlux = function(config) {
300
+ };
301
+
302
+ var ignoreFlux = function(config) {
303
+ };
276
304
 
277
- Vue.set(app.setup, 'showFlux', false);
278
- }, 500);
305
+ var setup = {
306
+ showFlux: false,
307
+ id: { type: 'hide', value: '' },
308
+ name: { type: 'text', value: '' },
309
+ flux: { type: 'select', value: fluxdata.fluxs[0].name, options: options},
310
+ parents: { type: 'selectmanyrecords', label: 'Receive Events From', value: '', options: flowdata.fluxs },
279
311
  };
280
312
 
281
313
  for (var key in configs)
282
314
  {
283
- configs[key].save = { type: 'button', name: 'Save This Flux', click: saveFlux };
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
+ }
324
+ };
284
325
 
285
326
  configs[key].test_event = { type: 'json', value: '{}', default: '{}' };
286
327
 
@@ -319,7 +360,7 @@ module Mushy
319
360
  Vue.set(setup.id, 'value', flux.id);
320
361
  Vue.set(setup.name, 'value', flux.name);
321
362
  Vue.set(setup.flux, 'value', flux.flux);
322
- Vue.set(setup.parent, 'value', flux.parent);
363
+ Vue.set(setup.parents, 'value', flux.parents);
323
364
 
324
365
  var applicable_config = configs[flux.flux];
325
366
  for(var key in applicable_config)
@@ -333,7 +374,7 @@ module Mushy
333
374
 
334
375
  options = flowdata.fluxs.filter(function(x){ return x.id != flux.id });
335
376
  options.unshift( { id: '', name: '' } );
336
- setup.parent.options = options;
377
+ setup.parents.options = options;
337
378
 
338
379
  Vue.set(setup, 'showFlux', true);
339
380
  app.results = [];
@@ -353,6 +394,7 @@ module Mushy
353
394
  flux = {
354
395
  id: uuidv4(),
355
396
  name: '',
397
+ parents: [],
356
398
  config: {}
357
399
  };
358
400
  loadThisFlux({ flux: flux, setup: x.setup, configs: x.configs });
@@ -377,9 +419,9 @@ module Mushy
377
419
  },
378
420
  configs: configs,
379
421
  setup: setup,
380
- flux_name_for: function(id, fluxes) {
381
- var flux = fluxes.filter(function(x){ return x.id == id })[0];
382
- 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(', ');
383
425
  },
384
426
  results: [],
385
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 = adjust( { browser: browser, result: result, config: config } )
109
+
108
110
  browser.quit
109
111
 
110
112
  result
111
113
  end
112
114
 
115
+ def adjust input
116
+ input[: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,50 @@
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 adjust input
31
+
32
+ the_browser = input[:browser]
33
+ the_result = input[:result]
34
+ the_config = input[:config]
35
+
36
+ options = {
37
+ path: the_config[:path],
38
+ full: ['true', ''].include?(the_config[:full].to_s),
39
+ quality: (the_config[:quality].to_s == '' ? '100' : the_config[:quality]).to_i
40
+ }
41
+
42
+ the_browser.screenshot options
43
+
44
+ options
45
+
46
+ end
47
+
48
+ end
49
+
50
+ 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.4'
7
+ s.version = '0.2.4'
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.4
4
+ version: 0.2.4
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