mushy 0.4.0 → 0.5.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: 7fdb340186745a43f2930f3b0e60a6538076593f3cb8cf3464fba209ac90d409
4
- data.tar.gz: cbe1b085e5844c4facabd43d5451f6f34b0fc21cba4909460028dd5bab007c5f
3
+ metadata.gz: 06d11ce2fc1a5da26f1272caf5b4b8a5bc7e8ff110b0169932778b9bdb7bb2bc
4
+ data.tar.gz: 96b68f95bff616ff46084d97630d0eab8d1496a99e902efae7fad965a16485dd
5
5
  SHA512:
6
- metadata.gz: 85af2b856ca023cef5a65fba574b615683b9898c20aea0a87f3aa24c2061382ebfb14eb9a7aee40e6267c7cb34666c12f8c1c939f3a4207a8a7fc90c6114817b
7
- data.tar.gz: 7f21edc8cd3e5f256dc038e16569a402f4d104a81060e08601b65afd325e7c71f2d22e5bdf39b895121034a8551025cbf7db9da62a6d4af1d2724d1ee706247f
6
+ metadata.gz: efc7c6b028efa5c75033b92ff9db8b422c6d81aae240a48178371b4208c1231ac63d8a2e437acfaccddb9e8a233c263b0284c85b16678036f99125f6ed757f6c
7
+ data.tar.gz: 5d19241ba64eddd10937f09aeb19d5c3d809d68e8ca100b7d94e64362e8a1a32fc0da56fabf7aeebd6f6303be5cce00db382333400f8e000c408535f63ad64f1
data/bin/mushy CHANGED
@@ -10,7 +10,8 @@ class MushyCLI < Thor
10
10
 
11
11
  desc "start FILE", "Run this workflow file."
12
12
  def start
13
- Mushy::Builder::Api.start file, values
13
+ v = values || {}
14
+ Mushy::Builder::Api.start file, v
14
15
  end
15
16
 
16
17
  desc "build FILE", 'Build a flow.'
@@ -93,8 +93,17 @@ module Mushy
93
93
  details[:config][:limit] = { type: 'integer', shrink: true, description: 'Limit the number of events to this number.', default: '' }
94
94
  details[:config][:join] = { type: 'text', shrink: true, description: 'Join all of the events from this flux into one event, under this name.', default: '' }
95
95
  details[:config][:sort] = { type: 'text', shrink: true, description: 'Sort by this key.', default: '' }
96
+ details[:config][:ignore] = { type: 'text', shrink: true, description: 'Ignore these keys.', value: '', default: '' }
96
97
  details[:config][:model] = { type: 'keyvalue', shrink: true, description: 'Reshape the outgoing events.', value: {}, default: {} }
97
98
 
99
+ details[:config][:error_strategy] = {
100
+ description: 'Error strategy. (return to return an event with "exception" returning the error, or ignore to ignore the exception)',
101
+ type: 'select',
102
+ options: ['', 'return', 'ignore'],
103
+ value: '',
104
+ shrink: true,
105
+ }
106
+
98
107
  details[:config]
99
108
  .select { |_, v| v[:type] == 'keyvalue' }
100
109
  .select { |_, v| v[:editors].nil? }
data/lib/mushy/flux.rb CHANGED
@@ -77,6 +77,10 @@ module Mushy
77
77
 
78
78
  returned_one_result ? results.first : results
79
79
 
80
+ rescue Exception => e
81
+ raise e if config[:error_strategy].to_s == ''
82
+ return [] if config[:error_strategy] == 'ignore'
83
+ { exception: e.message }
80
84
  end
81
85
 
82
86
  def standardize_these results
@@ -87,7 +91,7 @@ module Mushy
87
91
  end
88
92
 
89
93
  def shape_these results, event, config
90
- supported_shaping = [:merge, :outgoing_split, :group, :model, :join, :sort, :limit]
94
+ supported_shaping = [:merge, :outgoing_split, :group, :model, :ignore, :join, :sort, :limit]
91
95
 
92
96
  shaping = supported_shaping
93
97
  if (config[:shaping])
@@ -132,6 +136,13 @@ module Mushy
132
136
  results.map { |x| masher.mash by, x }
133
137
  end
134
138
 
139
+ def ignore_these_results results, event, by
140
+ return results if by.to_s == ''
141
+ ignore_fields = by.split ','
142
+ results.each { |r| ignore_fields.each { |f| r.delete f } }
143
+ results
144
+ end
145
+
135
146
  def merge_these_results results, event, by
136
147
  keys_to_merge = convert_this_to_an_array by
137
148
  keys_to_merge = event.keys.map { |x| x.to_s } if (keys_to_merge[0] == '*')
@@ -15,6 +15,7 @@ module Mushy
15
15
  directory: {
16
16
  description: 'The working directory in which the command will be run.',
17
17
  type: 'text',
18
+ shrink: true,
18
19
  value: '',
19
20
  },
20
21
  },
@@ -18,7 +18,7 @@ module Mushy
18
18
  description: 'Run this browser headless.',
19
19
  type: 'boolean',
20
20
  shrink: true,
21
- value: 'true',
21
+ value: '',
22
22
  },
23
23
  timeout: {
24
24
  description: 'The default timeout (in seconds) before closing the browser. Default is 5 seconds.',
@@ -90,7 +90,9 @@ module Mushy
90
90
 
91
91
  browser.headers.add get_the_headers_from(event, config)
92
92
 
93
+ the_start = Time.now
93
94
  browser.goto config[:url]
95
+ time = Time.now - the_start
94
96
 
95
97
  browser.execute(config[:execute]) if config[:execute]
96
98
 
@@ -102,6 +104,7 @@ module Mushy
102
104
  title: browser.frames[0].title,
103
105
  cookies: browser.cookies.all.map { |k, v| v.instance_variable_get('@attributes') },
104
106
  headers: browser.headers.get,
107
+ time: time,
105
108
  body: browser.body
106
109
  }
107
110
 
@@ -0,0 +1,27 @@
1
+ module Mushy
2
+
3
+ class Document < Flux
4
+
5
+ def self.details
6
+ {
7
+ name: 'Document',
8
+ description: 'Create a multi-line document.',
9
+ config: {
10
+ document: {
11
+ description: 'The multi-line document you wish to create.',
12
+ type: 'textarea',
13
+ value: '',
14
+ },
15
+ },
16
+ }
17
+ end
18
+
19
+ def process event, config
20
+ {
21
+ document: config[:document],
22
+ }
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -14,31 +14,62 @@ module Mushy
14
14
  shrink: true,
15
15
  value: '',
16
16
  }
17
+ c[:config][:path] = {
18
+ description: 'Path, used to search for specific files.',
19
+ type: 'text',
20
+ shrink: true,
21
+ value: '',
22
+ }
17
23
  end
18
24
  end
19
25
 
20
26
  def process event, config
27
+ arguments = build_the_arguments_from config
21
28
 
29
+ config[:command] = build_the_command_from arguments
30
+ result = super event, config
31
+
32
+ things = turn_the_ls_output_to_events result, config, event
33
+ things
34
+ end
35
+
36
+ def build_the_command_from arguments
37
+ "ls #{arguments.join(' ')}"
38
+ end
39
+
40
+ def build_the_arguments_from config
22
41
  arguments = ['-A', '-l', '--full-time', '-i']
23
42
  arguments << '-R' if config[:recursive].to_s == 'true'
24
- config[:command] = "ls #{arguments.join(' ')}"
25
-
26
- result = super event, config
43
+ arguments << '-d' if config[:directory_only].to_s == 'true'
44
+ arguments << "'#{config[:path]}'" if config[:path].to_s != ''
45
+ arguments
46
+ end
27
47
 
28
- return result unless result[:success]
48
+ def turn_the_ls_output_to_events result, config, event
29
49
 
30
50
  lines = result[:text].split("\n")
31
- lines.shift
51
+
52
+ needs_special_work_for_path = config[:directory_only].to_s != 'true' &&
53
+ config[:path].to_s != '' &&
54
+ lines[0] &&
55
+ lines[0].start_with?('total ')
32
56
 
33
57
  origin = config[:directory] || Dir.pwd
34
- directory = origin
35
- lines.map do |x|
58
+ directory = needs_special_work_for_path ? '||DIRECTORY||' : origin
59
+
60
+ things = lines.map do |x|
36
61
  segments = x.split ' '
37
62
  result = if segments.count > 5
38
63
  pull_file segments, directory
39
64
  elsif segments.count == 1
40
65
  dir_segments = segments[0].split("\/")
41
- dir_segments[0] = origin if dir_segments[0] == '.'
66
+
67
+ if dir_segments[0] == '.'
68
+ dir_segments[0] = origin
69
+ else
70
+ dir_segments.unshift origin
71
+ end
72
+
42
73
  dir_segments[-1] = dir_segments[-1].sub ':', ''
43
74
  directory = dir_segments.join("\/")
44
75
  nil
@@ -47,6 +78,19 @@ module Mushy
47
78
  end
48
79
  end.select { |x| x }
49
80
 
81
+ if needs_special_work_for_path
82
+ config[:directory_only] = true
83
+ special_name = process(event, config)[0][:name]
84
+ things.each do |x|
85
+ [:directory, :path].each do |key|
86
+ if x[key].include?('||DIRECTORY||')
87
+ x[key].sub!('||DIRECTORY||', File.join(Dir.pwd, special_name))
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ things
50
94
  end
51
95
 
52
96
  def pull_file segments, directory
@@ -63,7 +107,7 @@ module Mushy
63
107
  r[:date] = Time.parse r[:date]
64
108
  end
65
109
 
66
- result[:name] = segments.shift
110
+ result[:name] = segments.join ' '
67
111
 
68
112
  result.tap do |r|
69
113
  help_segments = r[:help].split ''
@@ -76,10 +120,18 @@ module Mushy
76
120
 
77
121
  [:hard_links, :size].each { |x| result[x] = result[x].to_i }
78
122
 
79
- result[:date_parts] = Mushy::DateParts.parse result[:date]
123
+ result[:date] = Mushy::DateParts.parse result[:date]
80
124
 
81
125
  result[:directory] = directory
82
- result[:path] = File.join result[:directory], result[:name]
126
+
127
+ if result[:type] == 'd' && result[:directory] == result[:name]
128
+ result[:path] = result[:directory]
129
+ name_segments = result[:name].split "\/"
130
+ result[:name] = name_segments.pop
131
+ result[:directory] = name_segments.join "\/"
132
+ else
133
+ result[:path] = File.join result[:directory], result[:name]
134
+ end
83
135
 
84
136
  result
85
137
  end
@@ -18,8 +18,10 @@ module Mushy
18
18
 
19
19
  return result unless result[:success]
20
20
 
21
+ pwd = result[:text].to_s.strip
22
+
21
23
  {
22
- pwd: result[:text].to_s.strip
24
+ pwd: Mushy::Ls.new.process({}, { path: pwd, directory_only: true })[0]
23
25
  }
24
26
 
25
27
  end
@@ -7,11 +7,10 @@ module Mushy
7
7
  details['name'] = 'Screenshot'
8
8
  details['description'] = 'Take a screenshot of the browser.'
9
9
 
10
- details[:config][:path] = {
11
- description: 'The path of the file to save.',
12
- type: 'text',
13
- value: 'picture.jpg',
14
- }
10
+ details[:config].merge!(Mushy::WriteFile.file_saving_config.tap do |x|
11
+ x[x.keys.first][:value] = 'file.jpg'
12
+ end)
13
+
15
14
  details[:config][:quality] = {
16
15
  description: 'The quality of the image, a value beteen 0-100. Only applies to jpg.',
17
16
  type: 'integer',
@@ -33,15 +32,19 @@ module Mushy
33
32
  the_result = input[:result]
34
33
  the_config = input[:config]
35
34
 
35
+ file = Mushy::WriteFile.get_file_from the_config
36
36
  options = {
37
- path: the_config[:path],
37
+ path: file,
38
38
  full: ['true', ''].include?(the_config[:full].to_s),
39
39
  quality: (the_config[:quality].to_s == '' ? '100' : the_config[:quality]).to_i
40
40
  }
41
41
 
42
42
  the_browser.screenshot options
43
43
 
44
- options
44
+ the_result[:options] = options
45
+ the_result[:file] = Mushy::Ls.new.process({}, { path: file })[0]
46
+
47
+ the_result
45
48
 
46
49
  end
47
50
 
@@ -6,34 +6,46 @@ module Mushy
6
6
  {
7
7
  name: 'WriteFile',
8
8
  description: 'Write a file.',
9
- config: {
10
- name: {
11
- description: 'The name of the file.',
12
- type: 'text',
13
- value: 'file.csv',
14
- },
15
- directory: {
16
- description: 'The directory in which to write the file. Leave blank for the current directory.',
17
- type: 'text',
18
- value: '',
19
- },
20
- data: {
21
- description: 'The text to write. You can use Liquid templating here to pull data from the event, or write hardcoded data.',
22
- type: 'text',
23
- value: '{{data}}',
24
- },
25
- },
9
+ config: file_saving_config.merge({
10
+ data: {
11
+ description: 'The text to write. You can use Liquid templating here to pull data from the event, or write hardcoded data.',
12
+ type: 'text',
13
+ value: '{{data}}',
14
+ },
15
+ }),
26
16
  }
27
17
  end
28
18
 
29
- def process event, config
30
- file = config[:name]
19
+ def self.file_saving_config
20
+ {
21
+ name: {
22
+ description: 'The name of the file.',
23
+ type: 'text',
24
+ value: 'file.csv',
25
+ },
26
+ directory: {
27
+ description: 'The directory in which to write the file. Leave blank for the current directory.',
28
+ shrink: true,
29
+ type: 'text',
30
+ value: '',
31
+ },
32
+ }
33
+ end
31
34
 
35
+ def self.get_file_from config
36
+ file = config[:name]
32
37
  file = File.join(config[:directory], file) if config[:directory].to_s != ''
38
+ file
39
+ end
40
+
41
+ def process event, config
42
+ file = self.class.get_file_from config
33
43
 
34
44
  File.open(file, 'w') { |f| f.write config[:data] }
35
45
 
36
- {}
46
+ {
47
+ file: Mushy::Ls.new.process({}, { path: file })[0]
48
+ }
37
49
  end
38
50
 
39
51
  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.4.0'
7
+ s.version = '0.5.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.4.0
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Cauthon
@@ -173,6 +173,7 @@ files:
173
173
  - lib/mushy/fluxs/build_csv.rb
174
174
  - lib/mushy/fluxs/cli.rb
175
175
  - lib/mushy/fluxs/collection.rb
176
+ - lib/mushy/fluxs/document.rb
176
177
  - lib/mushy/fluxs/environment.rb
177
178
  - lib/mushy/fluxs/filter.rb
178
179
  - lib/mushy/fluxs/format.rb