mushy 0.5.0 → 0.7.0

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: 49ce2c989b79318911d3941f9733d582a5911e9b7c31e73fb50bae29d63ee5e0
4
- data.tar.gz: c9cff38e82362e8ec8299ae84884b1c1cfdc511f367c832697f6cb538143b505
3
+ metadata.gz: 32162cc00416efb4669436924df21b3cc80d59c2ec11b243f0210125e3bcb6dc
4
+ data.tar.gz: 0e6e74b96b1988ad3c8792d0e42fdc1dd4a095247e7517429454692b152ddc23
5
5
  SHA512:
6
- metadata.gz: ef122c23b39ef1ef6dbe3675b66f55840c243341403d5b22f31356c2d31b1dd9fdc66f6572ff6861cfb2ea2c43257c064ab8411e15f01da29a472d4612c8fa89
7
- data.tar.gz: 79a7708ce3fda3f0081d00a767ccc588967a2cbc44f37e27363a769234eb43a1fc53a0e50e1fa74e245497304ee6185b3160a14cac2216c71e09d09ed632f31e
6
+ metadata.gz: 7c89eaf89944c50a8478a8e0b0419ea8cad1f283bb18eb55edd9f38b59ad8c282895f94bac14b697a2e003225ec61cc169642cd1c1f6eeff009084f04094b3d9
7
+ data.tar.gz: dcb83c01e8da06d5d896c646a839b4e8b764fc3bba4d7d6393998c2670b7bd7c54d6bf2feeb9999cd85993cdf3afaa8ab778ebe57e37a84ec5a718f0246f984c
@@ -23,15 +23,15 @@ module Mushy
23
23
 
24
24
  def self.save file, data
25
25
 
26
- file = "#{file}.json" unless file.downcase.end_with?('.json')
26
+ file = "#{file}.mushy" unless file.downcase.end_with?('.mushy')
27
27
 
28
28
  data = SymbolizedHash.new JSON.parse(data)
29
- Mushy::WriteFile.new.process( {}, { name: file, data: data.to_json })
29
+ Mushy::WriteFile.new.process( {}, { name: file, data: JSON.pretty_generate(data) })
30
30
 
31
31
  end
32
32
 
33
33
  def self.start file, event
34
- file = "#{file}.json" unless file.downcase.end_with?('.json')
34
+ file = "#{file}.mushy" unless file.downcase.end_with?('.mushy')
35
35
  flow = File.open(file).read
36
36
  flow = Mushy::Flow.parse flow
37
37
 
@@ -40,16 +40,25 @@ module Mushy
40
40
  pwd = Dir.pwd
41
41
 
42
42
  if service_fluxes.any?
43
- calls = service_fluxes
43
+
44
+ things = service_fluxes
44
45
  .map { |s| { flux: s, proc: ->(e) do
45
46
  Dir.chdir pwd
46
47
  Mushy::Runner.new.start e, s, flow
47
- end } }
48
+ end,
49
+ run_method: (s.config[:run_strategy] == 'daemon' ? :run_this_as_a_daemon : :run_this_inline),
50
+ }
51
+ }.group_by { |x| x[:run_method] }
52
+
53
+ calls = (things[:run_this_as_a_daemon] || [])
48
54
  .map { |p| ->() { p[:flux].loop &p[:proc] } }
49
55
  .map { |x| ->() { loop &x } }
50
- .map { |x| run_as_a_daemon &x }
56
+ .map { |x| run_this_as_a_daemon &x }
51
57
 
52
- puts calls.inspect
58
+ (things[:run_this_inline] || [])
59
+ .map { |p| ->() { p[:flux].loop &p[:proc] } }
60
+ .map { |x| ->() { loop &x } }
61
+ .map { |x| run_this_inline &x }
53
62
 
54
63
  exit
55
64
  end
@@ -59,14 +68,17 @@ module Mushy
59
68
  Mushy::Runner.new.start event, cli_flux, flow
60
69
  end
61
70
 
62
- def self.run_as_a_daemon &block
63
- #block.call
71
+ def self.run_this_inline &block
72
+ block.call
73
+ end
74
+
75
+ def self.run_this_as_a_daemon &block
64
76
  Daemons.call(&block).pid.pid
65
77
  end
66
78
 
67
79
  def self.get_flow file
68
80
  puts "trying to get: #{file}"
69
- file = "#{file}.json" unless file.downcase.end_with?('.json')
81
+ file = "#{file}.mushy" unless file.downcase.end_with?('.mushy')
70
82
  data = JSON.parse File.open(file).read
71
83
  data['fluxs']
72
84
  .reject { |x| x['parents'] }
@@ -93,6 +105,7 @@ module Mushy
93
105
  details[:config][:limit] = { type: 'integer', shrink: true, description: 'Limit the number of events to this number.', default: '' }
94
106
  details[:config][:join] = { type: 'text', shrink: true, description: 'Join all of the events from this flux into one event, under this name.', default: '' }
95
107
  details[:config][:sort] = { type: 'text', shrink: true, description: 'Sort by this key.', default: '' }
108
+ details[:config][:ignore] = { type: 'text', shrink: true, description: 'Ignore these keys.', value: '', default: '' }
96
109
  details[:config][:model] = { type: 'keyvalue', shrink: true, description: 'Reshape the outgoing events.', value: {}, default: {} }
97
110
 
98
111
  details[:config][:error_strategy] = {
@@ -103,6 +116,16 @@ module Mushy
103
116
  shrink: true,
104
117
  }
105
118
 
119
+ if flux.new.respond_to? :loop
120
+ details[:config][:run_strategy] = {
121
+ description: 'Run this using this strategy. (select "daemon" if this should be run in the background)',
122
+ type: 'select',
123
+ options: ['', 'inline', 'daemon'],
124
+ value: '',
125
+ shrink: true,
126
+ }
127
+ end
128
+
106
129
  details[:config]
107
130
  .select { |_, v| v[:type] == 'keyvalue' }
108
131
  .select { |_, v| v[:editors].nil? }
@@ -114,7 +137,7 @@ module Mushy
114
137
  end
115
138
 
116
139
  details
117
- end
140
+ end.sort_by { |x| x[:name] }
118
141
  }
119
142
  end
120
143
 
@@ -22,6 +22,8 @@ module Mushy
22
22
  method = i[1] || i[0]
23
23
  t[i[0]] = now.send method
24
24
  t
25
+ end.tap do |hash|
26
+ hash[:seconds_ago] = Time.now - now
25
27
  end
26
28
  end
27
29
 
data/lib/mushy/flux.rb CHANGED
@@ -91,7 +91,7 @@ module Mushy
91
91
  end
92
92
 
93
93
  def shape_these results, event, config
94
- supported_shaping = [:merge, :outgoing_split, :group, :model, :join, :sort, :limit]
94
+ supported_shaping = [:merge, :outgoing_split, :group, :model, :ignore, :join, :sort, :limit]
95
95
 
96
96
  shaping = supported_shaping
97
97
  if (config[:shaping])
@@ -136,6 +136,13 @@ module Mushy
136
136
  results.map { |x| masher.mash by, x }
137
137
  end
138
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
+
139
146
  def merge_these_results results, event, by
140
147
  keys_to_merge = convert_this_to_an_array by
141
148
  keys_to_merge = event.keys.map { |x| x.to_s } if (keys_to_merge[0] == '*')
@@ -0,0 +1,46 @@
1
+ require 'listen'
2
+
3
+ module Mushy
4
+
5
+ class FileWatch < Flux
6
+
7
+ def self.details
8
+ {
9
+ name: 'FileWatch',
10
+ description: 'Watch for file changes.',
11
+ config: {
12
+ directory: {
13
+ description: 'The directory to watch.',
14
+ type: 'text',
15
+ value: '',
16
+ },
17
+ },
18
+ }
19
+ end
20
+
21
+ def loop &block
22
+
23
+ directory = config[:directory].to_s != '' ? config[:directory] : Dir.pwd
24
+
25
+ listener = Listen.to(directory) do |modified, added, removed|
26
+ the_event = {
27
+ modified: modified,
28
+ added: added,
29
+ removed: removed,
30
+ }
31
+ block.call the_event
32
+ end
33
+
34
+ listener.start
35
+
36
+ sleep
37
+
38
+ end
39
+
40
+ def process event, config
41
+ event
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -41,7 +41,7 @@ module Mushy
41
41
  arguments = ['-A', '-l', '--full-time', '-i']
42
42
  arguments << '-R' if config[:recursive].to_s == 'true'
43
43
  arguments << '-d' if config[:directory_only].to_s == 'true'
44
- arguments << config[:path] if config[:path].to_s != ''
44
+ arguments << "'#{config[:path]}'" if config[:path].to_s != ''
45
45
  arguments
46
46
  end
47
47
 
@@ -51,6 +51,7 @@ module Mushy
51
51
 
52
52
  needs_special_work_for_path = config[:directory_only].to_s != 'true' &&
53
53
  config[:path].to_s != '' &&
54
+ lines[0] &&
54
55
  lines[0].start_with?('total ')
55
56
 
56
57
  origin = config[:directory] || Dir.pwd
@@ -106,7 +107,7 @@ module Mushy
106
107
  r[:date] = Time.parse r[:date]
107
108
  end
108
109
 
109
- result[:name] = segments.shift
110
+ result[:name] = segments.join ' '
110
111
 
111
112
  result.tap do |r|
112
113
  help_segments = r[:help].split ''
@@ -37,7 +37,10 @@ module Mushy
37
37
 
38
38
  the_browser.pdf options
39
39
 
40
- options
40
+ {
41
+ options: options,
42
+ file: Mushy::Ls.new.process({}, { path: options[:path] })[0]
43
+ }
41
44
 
42
45
  end
43
46
 
@@ -32,7 +32,7 @@ module Mushy
32
32
  the_result = input[:result]
33
33
  the_config = input[:config]
34
34
 
35
- file = Mushy::WriteFile.get_file_from config
35
+ file = Mushy::WriteFile.get_file_from the_config
36
36
  options = {
37
37
  path: file,
38
38
  full: ['true', ''].include?(the_config[:full].to_s),
@@ -1,8 +1,50 @@
1
1
  require 'pony'
2
2
 
3
3
  module Mushy
4
+
5
+ class EmailBase < Flux
6
+
7
+ def process event, config
8
+ options = adjust(cleanup({
9
+ from: config[:from],
10
+ to: config[:to],
11
+ subject: config[:subject],
12
+ body: config[:body],
13
+ html_body: config[:html_body],
14
+ via_options: get_via_options_from(config)
15
+ }))
16
+
17
+ if (config[:attachment_file].to_s != '')
18
+ options[:attachments] = { config[:attachment_file].split("\/")[-1] => File.read(config[:attachment_file]) }
19
+ end
20
+
21
+ result = Pony.mail options
22
+ options.tap { |x| x.delete(:via_options) }
23
+ end
24
+
25
+ def adjust options
26
+ end
27
+
28
+ def cleanup options
29
+ options.tap do |hash|
30
+ hash.delete_if { |_, v| v.to_s == '' }
31
+ end
32
+ end
33
+
34
+ def get_via_options_from config
35
+ {
36
+ address: config[:address],
37
+ port: config[:port].to_s,
38
+ user_name: config[:username],
39
+ password: config[:password],
40
+ domain: config[:domain],
41
+ authentication: :plain,
42
+ enable_starttls_auto: true,
43
+ }
44
+ end
45
+ end
4
46
 
5
- class Smtp < Flux
47
+ class Smtp < EmailBase
6
48
 
7
49
  def self.details
8
50
  {
@@ -70,46 +112,10 @@ module Mushy
70
112
  }
71
113
  end
72
114
 
73
- def process event, config
74
- options = adjust(cleanup({
75
- from: config[:from],
76
- to: config[:to],
77
- subject: config[:subject],
78
- body: config[:body],
79
- html_body: config[:html_body],
80
- via_options: get_via_options_from(config)
81
- }))
82
-
83
- if (config[:attachment_file].to_s != '')
84
- options[:attachments] = { config[:attachment_file].split("\/")[-1] => File.read(config[:attachment_file]) }
85
- end
86
-
87
- result = Pony.mail options
88
- options.tap { |x| x.delete(:via_options) }
89
- end
90
-
91
115
  def adjust options
92
116
  options.tap { |x| x[:via] = 'smtp' }
93
117
  end
94
118
 
95
- def cleanup options
96
- options.tap do |hash|
97
- hash.delete_if { |_, v| v.to_s == '' }
98
- end
99
- end
100
-
101
- def get_via_options_from config
102
- {
103
- address: config[:address],
104
- port: config[:port].to_s,
105
- user_name: config[:username],
106
- password: config[:password],
107
- domain: config[:domain],
108
- authentication: :plain,
109
- enable_starttls_auto: true,
110
- }
111
- end
112
-
113
119
  end
114
120
 
115
121
  end
@@ -0,0 +1,29 @@
1
+ module Mushy
2
+
3
+ class Times < Flux
4
+
5
+ def self.details
6
+ {
7
+ name: 'Times',
8
+ description: 'Return the event passed to it, X times.',
9
+ config: {
10
+ times: {
11
+ description: 'The number of times this event should be returned.',
12
+ type: 'integer',
13
+ value: '1',
14
+ },
15
+ }
16
+ }
17
+ end
18
+
19
+ def process event, config
20
+ config[:times]
21
+ .to_i
22
+ .times
23
+ .each_with_index
24
+ .map { |x, i| event.dup.tap { |e| e[:index] = i } }
25
+ end
26
+
27
+ end
28
+
29
+ end
data/lib/site.rb CHANGED
@@ -2,7 +2,7 @@ require 'sinatra'
2
2
 
3
3
  require_relative 'mushy'
4
4
 
5
- the_file = 'hey.json'
5
+ the_file = 'hey.mushy'
6
6
 
7
7
  get '/' do
8
8
  Mushy::Builder::Index.file
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.5.0'
7
+ s.version = '0.7.0'
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.'
@@ -16,14 +16,15 @@ Gem::Specification.new do |s|
16
16
  s.homepage = 'https://cauthon.com'
17
17
  s.license = 'MIT'
18
18
 
19
- s.add_development_dependency 'minitest'
20
- s.add_runtime_dependency 'sinatra'
21
- s.add_runtime_dependency 'symbolized'
22
- s.add_runtime_dependency 'thor'
23
- s.add_runtime_dependency 'liquid'
24
- s.add_runtime_dependency 'ferrum'
25
- s.add_runtime_dependency 'nokogiri'
26
- s.add_runtime_dependency 'faraday'
27
- s.add_runtime_dependency 'pony'
28
- s.add_runtime_dependency 'daemons'
19
+ s.add_development_dependency 'minitest', '~> 5'
20
+ s.add_runtime_dependency 'sinatra', '~> 2.1'
21
+ s.add_runtime_dependency 'symbolized', '~> 0.0.1'
22
+ s.add_runtime_dependency 'thor', '~> 1.1'
23
+ s.add_runtime_dependency 'liquid', '~> 5'
24
+ s.add_runtime_dependency 'ferrum','~> 0.11'
25
+ s.add_runtime_dependency 'nokogiri', '~> 1'
26
+ s.add_runtime_dependency 'faraday', '~> 1'
27
+ s.add_runtime_dependency 'pony', '~> 1.13'
28
+ s.add_runtime_dependency 'daemons', '~> 1'
29
+ s.add_runtime_dependency 'listen', '~> 3.5'
29
30
  end
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.5.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Cauthon
@@ -14,142 +14,156 @@ dependencies:
14
14
  name: minitest
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sinatra
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '2.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '2.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: symbolized
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 0.0.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 0.0.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: thor
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '1.1'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '1.1'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: liquid
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '5'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '5'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: ferrum
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '0.11'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '0.11'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: nokogiri
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: '1'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: '1'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: faraday
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: '1'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: '1'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: pony
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '0'
131
+ version: '1.13'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '0'
138
+ version: '1.13'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: daemons
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '0'
145
+ version: '1'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '0'
152
+ version: '1'
153
+ - !ruby/object:Gem::Dependency
154
+ name: listen
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '3.5'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '3.5'
153
167
  description: This tool assists in the creation and processing of workflows.
154
168
  email: darren@cauthon.com
155
169
  executables:
@@ -175,6 +189,7 @@ files:
175
189
  - lib/mushy/fluxs/collection.rb
176
190
  - lib/mushy/fluxs/document.rb
177
191
  - lib/mushy/fluxs/environment.rb
192
+ - lib/mushy/fluxs/file_watch.rb
178
193
  - lib/mushy/fluxs/filter.rb
179
194
  - lib/mushy/fluxs/format.rb
180
195
  - lib/mushy/fluxs/get.rb
@@ -189,6 +204,7 @@ files:
189
204
  - lib/mushy/fluxs/read_file.rb
190
205
  - lib/mushy/fluxs/screenshot.rb
191
206
  - lib/mushy/fluxs/smtp.rb
207
+ - lib/mushy/fluxs/times.rb
192
208
  - lib/mushy/fluxs/write_file.rb
193
209
  - lib/mushy/masher.rb
194
210
  - lib/mushy/run.rb