mushy 0.19.0 → 0.21.1

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: d783dd461abacb6686c2e131fc228d2640f1dda9836d1c49c1073f7e37054739
4
- data.tar.gz: 950f0fd45cb88001fe62d3f1541374c2df5a1f3ff931b19d3a40f4a6fd187fb3
3
+ metadata.gz: 32b68312119c9602d68480b2c6e3538cce109b048ddeb165f97f14486fd4e9a2
4
+ data.tar.gz: 9302ac7cdd00849d004c8cb37350b71b92e8fced73622bebfc084070168408ef
5
5
  SHA512:
6
- metadata.gz: 15b49ebac4c571ab8f2c34450516f0325b70a3e85e7bd909bdd800c29a74ee7377297fa5128f8d7b5458ec278768e92cafbd8af552321f372d26a9a743d8ebb1
7
- data.tar.gz: 8041bbd1b4f89af13edc858be699bc3903e4bea680ac68b0b2f26a744adc0b7230572034ade0367851b7f5201e3c51ca9a48095d7afd9300f5185ce2f2c0bd3f
6
+ metadata.gz: 5a9e8d98c36b36420885b8316064c3310d8138cb27f2997e7bae897e9dd428eb6c039f108c72fb5def15266353e98626457482390aa0c4952b59318d31583f39
7
+ data.tar.gz: 4ada310e71abae1317ed7ba7421244503f0107e0c751f362ad35c61ac5d20d967b654c666661174ec81e232b40581014529cdb7855647ed5817fc5fef301f338
@@ -17,6 +17,12 @@ module Mushy
17
17
  shrink: true,
18
18
  value: '',
19
19
  },
20
+ include_all_file_details: {
21
+ description: 'If true, returns all details for the file. If false, just path & name are returned',
22
+ type: 'boolean',
23
+ shrink: true,
24
+ value: '',
25
+ }
20
26
  },
21
27
  examples: {
22
28
  "Files Added" => {
@@ -47,15 +53,14 @@ module Mushy
47
53
  }
48
54
  end
49
55
 
50
- def loop &block
51
-
56
+ def loop(&block)
52
57
  directory = config[:directory].to_s != '' ? config[:directory] : Dir.pwd
53
58
 
54
59
  listener = Listen.to(directory) do |modified, added, removed|
55
60
  the_event = {
56
- modified: modified,
57
- added: added,
58
- removed: removed,
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) }
59
64
  }
60
65
  block.call the_event
61
66
  end
@@ -70,6 +75,19 @@ module Mushy
70
75
  event
71
76
  end
72
77
 
78
+ def get_the_details_for(file)
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
90
+
73
91
  end
74
92
 
75
93
  end
@@ -2,6 +2,24 @@ module Mushy
2
2
 
3
3
  class Ls < Bash
4
4
 
5
+ def self.the_ls_command
6
+ @the_ls_command ||= find_the_right_ls_command_to_use
7
+ end
8
+
9
+ def self.find_the_right_ls_command_to_use
10
+ commands = [
11
+ 'ls', # the normal method used to pull file information
12
+ 'gls' # BSD users don't get the version of ls this needs,
13
+ # so we might need to use gls after the user runs (brew install coreutils)
14
+ ]
15
+
16
+ the_command_to_use = nil
17
+ while the_command_to_use.nil? && (command = commands.shift) # keep trying till we find one that works
18
+ the_command_to_use = command if Mushy::Bash.new.process({}, { command: "#{command} --full-time" })[:success]
19
+ end
20
+ the_command_to_use || -1
21
+ end
22
+
5
23
  def self.details
6
24
  {
7
25
  name: 'Ls',
@@ -134,6 +152,8 @@ module Mushy
134
152
  end
135
153
 
136
154
  def process event, config
155
+ raise 'ls is not available' if self.class.the_ls_command == -1
156
+
137
157
  arguments = build_the_arguments_from config
138
158
 
139
159
  config[:command] = build_the_command_from arguments
@@ -144,7 +164,8 @@ module Mushy
144
164
  end
145
165
 
146
166
  def build_the_command_from arguments
147
- "ls #{arguments.join(' ')}"
167
+ command = self.class.the_ls_command
168
+ "#{command} #{arguments.join(' ')}"
148
169
  end
149
170
 
150
171
  def build_the_arguments_from config
@@ -232,6 +253,10 @@ module Mushy
232
253
 
233
254
  result[:date] = Mushy::DateParts.parse result[:date]
234
255
 
256
+ if File.exist?(result[:name]) && result[:name].start_with?(directory)
257
+ result[:name] = result[:name].split("\/")[-1]
258
+ end
259
+
235
260
  result[:directory] = directory
236
261
 
237
262
  if result[:type] == 'd' && result[:directory] == result[:name]
@@ -0,0 +1,64 @@
1
+ module Mushy
2
+ class RegexMatches < Flux
3
+ def self.details
4
+ {
5
+ name: 'RegexMatches',
6
+ title: 'Find regex matches',
7
+ description: 'Use a regex to search content.',
8
+ fluxGroup: { name: 'Regex' },
9
+ config: {
10
+ regex: { description: 'The regular expression to use.',
11
+ type: 'text',
12
+ value: '(\w+)' },
13
+ value: { description: 'The value against which to use the regular expression.',
14
+ type: 'text',
15
+ value: '{{value}}' }
16
+ },
17
+ examples: {
18
+ 'Simple Example' => {
19
+ description: 'The simplest regex.',
20
+ input: { text: 'apple orange' },
21
+ config: {
22
+ regex: '(\w+)',
23
+ value: 'apple orange'
24
+ },
25
+ result: [ { match1: 'apple' }, { match2: 'orange' } ]
26
+ },
27
+ 'Named Parameters' => {
28
+ description: 'Named Parameters.',
29
+ input: {
30
+ text: 'apple 1 orange 2'
31
+ },
32
+ config: {
33
+ regex: '(?&lt;name&gt;\w+) (?&lt;count&gt;\d+)',
34
+ value: '{{text}}'
35
+ },
36
+ result: [ { name: 'apple', count: '1' }, { name: 'orange', count: '2' } ]
37
+ },
38
+ }
39
+ }
40
+ end
41
+
42
+ def process(_, config)
43
+ return [] unless config[:value]
44
+ return [] if (config[:regex] || '').strip == ''
45
+
46
+ keys = config[:regex].scan(/\?<(\w+)>/).flatten
47
+
48
+ regex = Regexp.new config[:regex]
49
+
50
+ config[:value].scan(regex).map do |match|
51
+ convert_the_match_to_a_hash match, keys
52
+ end
53
+ end
54
+
55
+ def convert_the_match_to_a_hash(match, keys)
56
+ {}.tap do |hash|
57
+ match.each_with_index do |item, index|
58
+ key = (keys[index] || "match#{index + 1}").to_sym
59
+ hash[key] = item
60
+ end
61
+ end
62
+ end
63
+ end
64
+ 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.19.0'
7
+ s.version = '0.21.1'
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.19.0
4
+ version: 0.21.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Cauthon
@@ -172,7 +172,6 @@ extensions: []
172
172
  extra_rdoc_files: []
173
173
  files:
174
174
  - bin/mushy
175
- - hey.mushy
176
175
  - lib/mushy.rb
177
176
  - lib/mushy/builder/api.rb
178
177
  - lib/mushy/builder/axios.rb
@@ -206,6 +205,7 @@ files:
206
205
  - lib/mushy/fluxs/read_csv.rb
207
206
  - lib/mushy/fluxs/read_file.rb
208
207
  - lib/mushy/fluxs/read_json.rb
208
+ - lib/mushy/fluxs/regex_matches.rb
209
209
  - lib/mushy/fluxs/screenshot.rb
210
210
  - lib/mushy/fluxs/sense_hat_environmental_sensors.rb
211
211
  - lib/mushy/fluxs/sense_hat_led_matrix.rb
data/hey.mushy DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "fluxs": [
3
- {
4
- "id": "0294b0c4-296f-44cd-9891-95fe75ebe4d2",
5
- "name": "Start it up",
6
- "flux": "Cli",
7
- "parents": [
8
-
9
- ],
10
- "config": {
11
- "model": {
12
- }
13
- }
14
- },
15
- {
16
- "id": "7779dce1-1ce8-4241-8e94-ddcd5cb4f8df",
17
- "name": "Output something",
18
- "flux": "Stdout",
19
- "parents": [
20
- "0294b0c4-296f-44cd-9891-95fe75ebe4d2"
21
- ],
22
- "config": {
23
- "message": "Hello.",
24
- "model": {
25
- }
26
- }
27
- }
28
- ]
29
- }