mushy 0.1.0 → 0.2.2

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: 5b0ff90e9b20233f5744ec73d94137a2a117dc5bbdcb1962242caf5d3fdec8f3
4
- data.tar.gz: dd834f5294cf131393881c7647a25c27d54275e7c510c2b19bac233b9193be43
3
+ metadata.gz: 1e6ffdfb09e494e5ddbbf2a6dde4c33c2b29a0ac19af467bd00cb77b6f899067
4
+ data.tar.gz: 4835fd407a77f62612d629994f323d37d4ea1b8f2053fa10c2b47141898659fe
5
5
  SHA512:
6
- metadata.gz: 41b4cdfd6d24547838ba11b0bbdb3515ec8baee305ab5b97079d040019951354d29074d9a93c88cf94be9b70c0875220f3b76630097c9cc697ddf4ea4cef550f
7
- data.tar.gz: 1ec8aab8a0ac9281d1ed036b84add01be639c6223ef46db6f7132d4140f09c10d2ea0a6707bca99aa79b3db024efa2f4cf34ce5430c68e8838953be21f125dd2
6
+ metadata.gz: 236092d1c7ee52ec2f19815cd3e48f90d1178943b02ddfd8c966034599770ad4cadd43dace1ae2a66b960fadd75a5f382911eeb1d7667219d3bc65964d191a75
7
+ data.tar.gz: 4e5a52fed081e20c0096ad4e6df08c5c46236776ccb0d4d01a3c69ac1e9244e628525ba8328df2bd201ed711a5afec05d3e41aa2156c279e8b00f2c01ee7ac8b
data/bin/mushy CHANGED
@@ -3,18 +3,20 @@
3
3
  require 'thor'
4
4
  require 'mushy'
5
5
 
6
- class RailsCLI < Thor
6
+ class MushyCLI < Thor
7
+
8
+ argument :file, optional: true, type: :string
9
+ argument :values, optional: true, type: :hash
7
10
 
8
11
  desc "start FILE", "Run this workflow file."
9
- def start file
10
- content = File.open(file).read
11
- puts content
12
+ def start
13
+ Mushy::Builder::Api.start file, values
12
14
  end
13
15
 
14
16
  desc "build FILE", 'Build a flow.'
15
- def build file
17
+ def build
16
18
 
17
- RailsCLI.set_special( { method: 'build', file: file } )
19
+ MushyCLI.set_special( { method: 'build', file: file } )
18
20
 
19
21
  end
20
22
 
@@ -28,14 +30,14 @@ class RailsCLI < Thor
28
30
 
29
31
  end
30
32
 
31
- RailsCLI.start(ARGV)
33
+ MushyCLI.start(ARGV)
32
34
 
33
- exit unless RailsCLI.get_special
35
+ exit unless MushyCLI.get_special
34
36
 
35
37
  require 'sinatra'
36
38
  enable :run
37
39
 
38
- the_file = RailsCLI.get_special[:file]
40
+ the_file = MushyCLI.get_special[:file]
39
41
 
40
42
  get '/' do
41
43
  Mushy::Builder::Index.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 }
@@ -28,10 +28,29 @@ module Mushy
28
28
 
29
29
  end
30
30
 
31
+ def self.start file, event
32
+ file = "#{file}.json" unless file.downcase.end_with?('.json')
33
+ flow = File.open(file).read
34
+ flow = Mushy::Flow.parse flow
35
+ flux = flow.fluxs.select { |x| x.type == 'Cli' }.first
36
+
37
+ Mushy::Runner.new.start event, flux, flow
38
+ end
39
+
31
40
  def self.get_flow file
32
41
  puts "trying to get: #{file}"
33
42
  file = "#{file}.json" unless file.downcase.end_with?('.json')
34
- 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
35
54
  rescue
36
55
  { fluxs: [] }
37
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
@@ -18,8 +18,10 @@ module Mushy
18
18
  end
19
19
 
20
20
  def self.build_flux record
21
- flux = Object.const_get("Mushy::#{record[:type] || record['type'] || 'Flux'}").new
21
+ type = record[:type] || record['type'] || record[:flux] || record['flux'] || 'Flux'
22
+ flux = Object.const_get("Mushy::#{type}").new
22
23
  flux.id = record[:id] || record['id'] || flux.id
24
+ flux.type = type
23
25
  flux.config = SymbolizedHash.new(record[:config] || record['config'])
24
26
  flux
25
27
  end
@@ -28,14 +30,14 @@ module Mushy
28
30
  data = JSON.parse data
29
31
 
30
32
  data_fluxs = data['fluxs'] || []
31
- 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"]] }
32
34
 
33
35
  flow = new
34
36
 
35
37
  flow.fluxs = data_fluxs.map { |s| build_flux s }
36
38
 
37
39
  fluxs_with_parent_ids = flow.fluxs.reduce({}) { |t, i| t[i.id] = []; t }
38
- 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'] || [] }
39
41
 
40
42
  flow.fluxs.each do |flux|
41
43
  flux.parent_fluxs = flow.fluxs.select { |x| fluxs_with_parent_ids[flux.id].include?(x.id) }
data/lib/mushy/flux.rb CHANGED
@@ -3,6 +3,7 @@ module Mushy
3
3
  class Flux
4
4
 
5
5
  attr_accessor :id
6
+ attr_accessor :type
6
7
  attr_accessor :parent_fluxs
7
8
  attr_accessor :subscribed_to
8
9
  attr_accessor :config
@@ -20,6 +20,12 @@ module Mushy
20
20
  shrink: true,
21
21
  value: 'true',
22
22
  },
23
+ timeout: {
24
+ description: 'The default timeout (in seconds) before closing the browser. Default is 5 seconds.',
25
+ type: 'integer',
26
+ shrink: true,
27
+ value: '',
28
+ },
23
29
  execute: {
24
30
  description: 'Javascript to run after the page is loaded.',
25
31
  type: 'textarea',
@@ -74,7 +80,11 @@ module Mushy
74
80
 
75
81
  def process event, config
76
82
 
77
- browser = Ferrum::Browser.new(headless: (config[:headless].to_s != 'false'))
83
+ timeout = config[:timeout] ? config[:timeout].to_i : 5
84
+
85
+ browser = Ferrum::Browser.new(
86
+ headless: (config[:headless].to_s != 'false'),
87
+ timeout: timeout)
78
88
 
79
89
  get_the_cookies_from(event, config).each { |c| browser.cookies.set(c) }
80
90
 
@@ -88,16 +98,24 @@ module Mushy
88
98
 
89
99
  result = {
90
100
  url: browser.url,
101
+ status: browser.network.status,
102
+ title: browser.frames[0].title,
91
103
  cookies: browser.cookies.all.map { |k, v| v.instance_variable_get('@attributes') },
92
104
  headers: browser.headers.get,
93
105
  body: browser.body
94
106
  }
95
107
 
108
+ result = special_browser_action browser, result
109
+
96
110
  browser.quit
97
111
 
98
112
  result
99
113
  end
100
114
 
115
+ def special_browser_action browser, result
116
+ result
117
+ end
118
+
101
119
  def get_the_cookies_from event, config
102
120
  cookies = (event[config[:carry_cookies_from].to_sym])
103
121
  cookies = [] unless cookies.is_a?(Array)
@@ -0,0 +1,20 @@
1
+ module Mushy
2
+
3
+ class Cli < Flux
4
+
5
+ def self.details
6
+ {
7
+ name: 'Cli',
8
+ description: 'Accept CLI arguments from the run command.',
9
+ config: {
10
+ },
11
+ }
12
+ end
13
+
14
+ def process event, config
15
+ event
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -2,6 +2,29 @@ module Mushy
2
2
 
3
3
  class Filter < Flux
4
4
 
5
+ def self.details
6
+ {
7
+ name: 'Filter',
8
+ description: 'Filters events based on criteria.',
9
+ config: {
10
+ equal: {
11
+ description: 'Provide key/value pairs that must match in the event.',
12
+ shrink: true,
13
+ label: 'Equal To',
14
+ type: 'keyvalue',
15
+ value: {},
16
+ },
17
+ notequal: {
18
+ description: 'Provide key/value pairs that must NOT match in the event.',
19
+ shrink: true,
20
+ label: 'Not Equal To',
21
+ type: 'keyvalue',
22
+ value: {},
23
+ },
24
+ },
25
+ }
26
+ end
27
+
5
28
  def process event, config
6
29
 
7
30
  differences = [:equal, :notequal]
@@ -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
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.0'
7
+ s.version = '0.2.2'
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.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Cauthon
@@ -142,6 +142,7 @@ files:
142
142
  - lib/mushy/fluxs/bash.rb
143
143
  - lib/mushy/fluxs/browser.rb
144
144
  - lib/mushy/fluxs/build_csv.rb
145
+ - lib/mushy/fluxs/cli.rb
145
146
  - lib/mushy/fluxs/collection.rb
146
147
  - lib/mushy/fluxs/filter.rb
147
148
  - lib/mushy/fluxs/format.rb
@@ -149,6 +150,7 @@ files:
149
150
  - lib/mushy/fluxs/ls.rb
150
151
  - lib/mushy/fluxs/parse_html.rb
151
152
  - lib/mushy/fluxs/read_csv.rb
153
+ - lib/mushy/fluxs/screenshot.rb
152
154
  - lib/mushy/fluxs/write_file.rb
153
155
  - lib/mushy/masher.rb
154
156
  - lib/mushy/run.rb