mushy 0.15.0 → 0.17.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.
@@ -7,14 +7,42 @@ module Mushy
7
7
  def self.details
8
8
  {
9
9
  name: 'FileWatch',
10
+ title: 'File Watcher',
10
11
  description: 'Watch for file changes.',
11
12
  config: {
12
13
  directory: {
13
- description: 'The directory to watch.',
14
+ description: 'The directory to watch, defaults to the current directory.',
14
15
  type: 'text',
16
+ shrink: true,
15
17
  value: '',
16
18
  },
17
19
  },
20
+ examples: {
21
+ "Files Added" => {
22
+ description: 'When a file is added, this type of result will be returned.',
23
+ result: {
24
+ modified: [],
25
+ added: ["/home/pi/Desktop/mushy/bin/hey.txt"],
26
+ removed:[]
27
+ }
28
+ },
29
+ "Files Removed" => {
30
+ description: 'When a file is deleted, this type of result will be returned.',
31
+ result: {
32
+ modified: [],
33
+ added: [],
34
+ removed:["/home/pi/Desktop/mushy/mushy-0.15.3.gem"]
35
+ }
36
+ },
37
+ "Files Modified" => {
38
+ description: 'When a file is modified, this type of result will be returned.',
39
+ result: {
40
+ modified: ["/home/pi/Desktop/mushy/lib/mushy/fluxs/environment.rb"],
41
+ added: [],
42
+ removed:[]
43
+ }
44
+ },
45
+ }
18
46
  }
19
47
  end
20
48
 
@@ -21,13 +21,53 @@ module Mushy
21
21
  type: 'keyvalue',
22
22
  value: {},
23
23
  },
24
+ contains: {
25
+ description: 'Provide key/value pairs that must be contained.',
26
+ shrink: true,
27
+ label: 'Contains',
28
+ type: 'keyvalue',
29
+ value: {},
30
+ },
31
+ notcontains: {
32
+ description: 'Provide key/value pairs that must NOT be contained.',
33
+ shrink: true,
34
+ label: 'Not Contains',
35
+ type: 'keyvalue',
36
+ value: {},
37
+ },
24
38
  },
39
+ examples: {
40
+ "Match On A Value" => {
41
+ description: 'The input is returned if it matches on a value.',
42
+ input: {
43
+ name: "John",
44
+ },
45
+ config: {
46
+ matches: { name: "John" }
47
+ },
48
+ result: {
49
+ name: "John",
50
+ }
51
+ },
52
+ "Contains A Value" => {
53
+ description: 'The input is returned if it contains a value.',
54
+ input: {
55
+ name: "John",
56
+ },
57
+ config: {
58
+ contains: { name: "H" }
59
+ },
60
+ result: {
61
+ name: "John",
62
+ }
63
+ },
64
+ }
25
65
  }
26
66
  end
27
67
 
28
68
  def process event, config
29
69
 
30
- differences = [:equal, :notequal]
70
+ differences = [:equal, :notequal, :contains, :notcontains]
31
71
  .select { |x| config[x].is_a? Hash }
32
72
  .map { |x| config[x].map { |k, v| { m: x, k: k, v1: v } } }
33
73
  .flatten
@@ -42,7 +82,7 @@ module Mushy
42
82
  def equal a, b
43
83
  [a, b]
44
84
  .map { |x| numeric?(x) ? x.to_f : x }
45
- .map { |x| x.to_s.strip.downcase }
85
+ .map { |x| nice_string x }
46
86
  .group_by { |x| x }
47
87
  .count == 1
48
88
  end
@@ -51,10 +91,23 @@ module Mushy
51
91
  equal(a, b) == false
52
92
  end
53
93
 
94
+ def contains a, b
95
+ return false unless b
96
+ nice_string(b).include? a.downcase
97
+ end
98
+
99
+ def notcontains a, b
100
+ contains(a, b) == false
101
+ end
102
+
54
103
  def numeric? value
55
104
  Float(value) != nil rescue false
56
105
  end
57
106
 
107
+ def nice_string value
108
+ value.to_s.strip.downcase
109
+ end
110
+
58
111
  end
59
112
 
60
113
  end
@@ -5,8 +5,47 @@ module Mushy
5
5
  def self.details
6
6
  {
7
7
  name: 'Format',
8
- description: 'Return the event passed to it. This opens the opportunity to further alter results.',
8
+ description: 'Return the event passed to it. This opens the opportunity to use the common fluxing to alter the event.',
9
9
  config: {},
10
+ examples: {
11
+ "Simplest Example" => {
12
+ description: 'It only returns what is passed to it.',
13
+ input: {
14
+ hello: 'world',
15
+ },
16
+ config: {
17
+ },
18
+ result: {
19
+ hello: 'world',
20
+ }
21
+ },
22
+ "Changing The Event" => {
23
+ description: 'The common fluxing can still be used to alter the event.',
24
+ input: {
25
+ things: [
26
+ { name: "Elephant", type: "Mammal" },
27
+ { name: "Alligator", type: "Reptile" },
28
+ { name: "Giraffe", type: "Mammal" }
29
+ ]
30
+ },
31
+ config: { outgoing_split:"things",group:"type|animal_type" },
32
+ result: [
33
+ {
34
+ animal_type: [
35
+ {
36
+ name: "Elephant",
37
+ type: "Mammal"
38
+ },
39
+ {
40
+ name: "Giraffe",
41
+ type: "Mammal"
42
+ }
43
+ ]
44
+ },
45
+ { animal_type:[ { name:"Alligator",type:"Reptile" } ] }
46
+ ]
47
+ },
48
+ }
10
49
  }
11
50
  end
12
51
 
@@ -7,7 +7,8 @@ module Mushy
7
7
  def self.details
8
8
  {
9
9
  name: 'GlobalVariables',
10
- description: 'Add global variables.',
10
+ title: 'Global Variables',
11
+ description: 'Add global variables to use in any future flux. Returns what was passed to it.',
11
12
  config: {
12
13
  values: {
13
14
  description: 'Provide key/value pairs that will be set as global variables.',
@@ -16,6 +17,20 @@ module Mushy
16
17
  value: {},
17
18
  },
18
19
  },
20
+ examples: {
21
+ "Setting Config Variables" => {
22
+ description: 'Set a variable to use in any flux. Here, I can use {{api_key}} anywhere.',
23
+ input: {
24
+ hey: 'you'
25
+ },
26
+ config: {
27
+ values: { api_key: 'my api key' }
28
+ },
29
+ result: {
30
+ hey: 'you',
31
+ }
32
+ },
33
+ }
19
34
  }
20
35
  end
21
36
 
@@ -20,6 +20,114 @@ module Mushy
20
20
  shrink: true,
21
21
  value: '',
22
22
  }
23
+ end.tap do |c|
24
+ c[:examples] = {
25
+ "Run In A Directory" => {
26
+ description: 'This will run the ls command in the specified directory.',
27
+ config: {
28
+ directory: '/home/pi/Desktop/mushy'
29
+ },
30
+ result: [{
31
+ inode: "416921",
32
+ hard_links: 1,
33
+ owner: "pi",
34
+ group: "pi",
35
+ size: 1270,
36
+ date: {
37
+ year: 2021,
38
+ month: 10,
39
+ day: 1,
40
+ hour: 10,
41
+ minute: 43,
42
+ second: 35,
43
+ nanosecond: 664409766,
44
+ utc_offset: -18000,
45
+ weekday: 5,
46
+ day_of_month: 1,
47
+ day_of_year: 274,
48
+ string: "2021-10-01 10:43:35 -0500",
49
+ epoch_integer: 1633103015,
50
+ epoch_float: 1633103015.6644099,
51
+ seconds_ago: 454725.436212074
52
+ },
53
+ name: "mushy.gemspec",
54
+ type: "-",
55
+ owner_permission: "rw-",
56
+ group_permission: "r--",
57
+ other_permission: "r--",
58
+ directory: "/home/pi/Desktop/mushy",
59
+ path: "/home/pi/Desktop/mushy/mushy.gemspec"
60
+ },
61
+ {
62
+ inode: "403479",
63
+ hard_links: 3,
64
+ owner: "pi",
65
+ group: "pi",
66
+ size: 4096,
67
+ date: {
68
+ year: 2021,
69
+ month: 3,
70
+ day: 18,
71
+ hour: 8,
72
+ minute: 58,
73
+ second: 51,
74
+ nanosecond: 149096220,
75
+ utc_offset: -18000,
76
+ weekday: 4,
77
+ day_of_month: 18,
78
+ day_of_year: 77,
79
+ string: "2021-03-18 08:58:51 -0500",
80
+ epoch_integer: 1616075931,
81
+ epoch_float: 1616075931.1490963,
82
+ seconds_ago: 17482042.0544623
83
+ },
84
+ name: "test",
85
+ type: "d",
86
+ owner_permission: "rwx",
87
+ group_permission: "r-x",
88
+ other_permission: "r-x",
89
+ directory: "test"
90
+ }
91
+ ]
92
+ },
93
+ "Run For a Specific File" => {
94
+ description: 'This will run the ls command in the specified directory.',
95
+ config: {
96
+ path: 'mushy.gemspec'
97
+ },
98
+ result: {
99
+ inode: "416921",
100
+ hard_links: 1,
101
+ owner: "pi",
102
+ group: "pi",
103
+ size: 1270,
104
+ date: {
105
+ year: 2021,
106
+ month: 10,
107
+ day: 1,
108
+ hour: 10,
109
+ minute: 43,
110
+ second: 35,
111
+ nanosecond: 664409766,
112
+ utc_offset: -18000,
113
+ weekday: 5,
114
+ day_of_month: 1,
115
+ day_of_year: 274,
116
+ string: "2021-10-01 10:43:35 -0500",
117
+ epoch_integer: 1633103015,
118
+ epoch_float: 1633103015.6644099,
119
+ seconds_ago: 454725.436212074
120
+ },
121
+ name: "mushy.gemspec",
122
+ type: "-",
123
+ owner_permission: "rw-",
124
+ group_permission: "r--",
125
+ other_permission: "r--",
126
+ directory: "/home/pi/Desktop/mushy",
127
+ path: "/home/pi/Desktop/mushy/mushy.gemspec"
128
+ }
129
+ }
130
+ }
23
131
  end
24
132
  end
25
133
 
@@ -129,6 +237,8 @@ module Mushy
129
237
  name_segments = result[:name].split "\/"
130
238
  result[:name] = name_segments.pop
131
239
  result[:directory] = name_segments.join "\/"
240
+ elsif result[:type] == 'd'
241
+ result[:directory] = result[:name]
132
242
  else
133
243
  result[:path] = File.join result[:directory], result[:name]
134
244
  end
@@ -7,7 +7,8 @@ module Mushy
7
7
  def self.details
8
8
  {
9
9
  name: 'ParseHtml',
10
- description: 'Parses HTML.',
10
+ title: 'Parse HTML',
11
+ description: 'Extract data from HTML.',
11
12
  config: {
12
13
  path: {
13
14
  description: 'The path to the HTML in the incoming event.',
@@ -20,6 +21,40 @@ module Mushy
20
21
  value: { url: 'a|@href' },
21
22
  }
22
23
  },
24
+ examples: {
25
+ "Example 1" => {
26
+ description: 'Pulling all links out of HTML.',
27
+ input: {
28
+ html: '<a href="one">First</a><a href="two">Second</a>'
29
+ },
30
+ config: {
31
+ path: 'html',
32
+ extract: {
33
+ url: "a|@href",
34
+ name: "a"
35
+ },
36
+ },
37
+ result: [
38
+ { url: 'one', name: 'First' },
39
+ { url: 'two', name: 'Second' }
40
+ ]
41
+ },
42
+ "Example 2" => {
43
+ description: 'Pulling the contents of a single div.',
44
+ input: {
45
+ html: "<div class=\"main\" data-this=\"you\">HEY</a>"
46
+ },
47
+ config: {
48
+ path: 'html',
49
+ extract: {
50
+ content: "div.main",
51
+ class: "div|@class",
52
+ "data-this" => "div|@data-this",
53
+ },
54
+ },
55
+ result: { content: 'HEY', class: 'main', "data-this" => "you" },
56
+ },
57
+ }
23
58
  }
24
59
  end
25
60
 
@@ -5,6 +5,7 @@ module Mushy
5
5
  def self.details
6
6
  details = Browser.details
7
7
  details[:name] = 'Pdf'
8
+ details[:title] = 'PDF'
8
9
  details[:description] = 'Turn a URL into a PDF.'
9
10
 
10
11
  details[:config][:path] = {
@@ -20,7 +21,76 @@ module Mushy
20
21
  value: '',
21
22
  }
22
23
 
23
- details
24
+ details.tap do |config|
25
+ config[:examples] = {
26
+ "PDF of google.com" => {
27
+ description: 'This will open https://www.google.com and take a screenshot.',
28
+ config: {
29
+ url: "https://www.google.com",
30
+ file: 'file.pdf'
31
+ },
32
+ result: {
33
+ url: "https://www.google.com/",
34
+ status: 200,
35
+ title: "Google",
36
+ cookies: [
37
+ {
38
+ name: "1P_JAR",
39
+ value: "2021-10-07-21",
40
+ domain: ".google.com",
41
+ path: "/",
42
+ expires: 1636232420.005369,
43
+ size: 19,
44
+ httpOnly: false,
45
+ secure: true,
46
+ session: false,
47
+ sameSite: "None",
48
+ priority: "Medium"
49
+ }
50
+ ],
51
+ headers: {},
52
+ time: 1.520785498,
53
+ body: "...",
54
+ options: {
55
+ path: "file.pdf",
56
+ full: true,
57
+ quality: 100
58
+ },
59
+ file: {
60
+ inode: "439545",
61
+ hard_links: 1,
62
+ owner: "pi",
63
+ group: "pi",
64
+ size: 54269,
65
+ date: {
66
+ year: 2021,
67
+ month: 10,
68
+ day: 7,
69
+ hour: 16,
70
+ minute: 0,
71
+ second: 20,
72
+ nanosecond: 444437482,
73
+ utc_offset: -18000,
74
+ weekday: 4,
75
+ day_of_month: 7,
76
+ day_of_year: 280,
77
+ string: "2021-10-07 16:00:20 -0500",
78
+ epoch_integer: 1633640420,
79
+ epoch_float: 1633640420.4444375,
80
+ seconds_ago: 0.016297478
81
+ },
82
+ name: "file.pdf",
83
+ type: "-",
84
+ owner_permission: "rw-",
85
+ group_permission: "r--",
86
+ other_permission: "r--",
87
+ directory: "/home/pi/Desktop/mushy",
88
+ path: "/home/pi/Desktop/mushy/file.pdf"
89
+ }
90
+ }
91
+ },
92
+ }
93
+ end
24
94
  end
25
95
 
26
96
  def adjust input
@@ -7,7 +7,46 @@ module Mushy
7
7
  name: 'Pwd',
8
8
  description: 'Run the "pwd" command.',
9
9
  config: Mushy::Bash.details[:config].tap { |c| c.delete :command },
10
- }
10
+ }.tap do |c|
11
+ c[:examples] = {
12
+ "Example" => {
13
+ description: 'This will run the pwd command and return the directory information.',
14
+ result: {
15
+ pwd: {
16
+ inode: "403091",
17
+ hard_links: 5,
18
+ owner: "pi",
19
+ group: "pi",
20
+ size: 4095,
21
+ date: {
22
+ year: 2020,
23
+ month: 9,
24
+ day: 5,
25
+ hour: 10,
26
+ minute: 43,
27
+ second: 36,
28
+ nanosecond: 325720074,
29
+ utc_offset: -18001,
30
+ weekday: 2,
31
+ day_of_month: 5,
32
+ day_of_year: 278,
33
+ string: "2020-10-06 11:44:37 -0500",
34
+ epoch_integer: 1633538676,
35
+ epoch_float: 1633538676.32572,
36
+ seconds_ago: 17558.38995246
37
+ },
38
+ name: "mushy",
39
+ type: "d",
40
+ owner_permission: "rwx",
41
+ group_permission: "r-x",
42
+ other_permission: "r-x",
43
+ directory: "/home/pi/Desktop",
44
+ path: "/home/pi/Desktop/mushy"
45
+ }
46
+ }
47
+ }
48
+ }
49
+ end
11
50
  end
12
51
 
13
52
  def process event, config
@@ -7,6 +7,7 @@ module Mushy
7
7
  def self.details
8
8
  {
9
9
  name: 'ReadCsv',
10
+ title: 'Read CSV',
10
11
  description: 'Read CSV content into events.',
11
12
  config: {
12
13
  data: {
@@ -21,6 +22,31 @@ module Mushy
21
22
  value: '',
22
23
  },
23
24
  },
25
+ examples: {
26
+ "With Headers" => {
27
+ description: 'Using this Flux to read a CSV into many events.',
28
+ input: {
29
+ csv: "first,last,height\njane,doe,short"
30
+ },
31
+ config: {
32
+ data: '{{csv}}'
33
+ },
34
+ result: { "first": "jane", "last": "doe", "height": "short" }
35
+ },
36
+ "No Headers" => {
37
+ description: 'Using this Flux to read a CSV into many events.',
38
+ input: {
39
+ csv: "john,doe,tall\njane,doe,short"
40
+ },
41
+ config: {
42
+ data: '{{csv}}'
43
+ },
44
+ result: [
45
+ { "a": "john", "b": "doe", "c": "tall" },
46
+ { "a": "jane", "b": "doe", "c": "short" }
47
+ ]
48
+ },
49
+ }
24
50
  }
25
51
  end
26
52
 
@@ -5,10 +5,11 @@ module Mushy
5
5
  def self.details
6
6
  {
7
7
  name: 'ReadFile',
8
+ title: 'Read File',
8
9
  description: 'Read a file.',
9
10
  config: {
10
- name: {
11
- description: 'The name of the file to read.',
11
+ file: {
12
+ description: 'The file to read.',
12
13
  type: 'text',
13
14
  value: 'file.csv',
14
15
  },
@@ -18,24 +19,37 @@ module Mushy
18
19
  shrink: true,
19
20
  value: '',
20
21
  },
21
- path: {
22
- description: 'The path in the event to return the contents of the file.',
23
- type: 'text',
24
- value: 'content',
25
- },
22
+ key: {
23
+ description: 'The key in the resulting event to return the contents of the file.',
24
+ type: 'text',
25
+ value: 'content',
26
+ },
26
27
  },
28
+ examples: {
29
+ "Example" => {
30
+ description: 'Using this Flux to read the contents of a text file.',
31
+ input: {
32
+ file: "data.csv"
33
+ },
34
+ config: {
35
+ file: '{{file}}',
36
+ key: 'csvdata'
37
+ },
38
+ result: { csvdata: 'a,b,c\nd\n\e\f'}
39
+ },
40
+ }
27
41
  }
28
42
  end
29
43
 
30
44
  def process event, config
31
- file = config[:name]
45
+ file = config[:file]
32
46
 
33
47
  file = File.join(config[:directory], file) if config[:directory].to_s != ''
34
48
 
35
49
  content = File.open(file).read
36
50
 
37
51
  {
38
- config[:path] => content
52
+ config[:key] => content
39
53
  }
40
54
  end
41
55
 
@@ -7,20 +7,33 @@ module Mushy
7
7
  def self.details
8
8
  {
9
9
  name: 'ReadJson',
10
+ title: 'Deserialize JSON',
10
11
  description: 'Read JSON and output it as an event.',
11
12
  config: {
12
- json: {
13
- description: 'The JSON contents that will be returned as an event.',
14
- type: 'text',
15
- value: 'json',
16
- },
13
+ key: {
14
+ description: 'The JSON contents that will be returned as an event.',
15
+ type: 'text',
16
+ value: 'json',
17
+ },
17
18
  },
19
+ examples: {
20
+ "Example" => {
21
+ description: 'Using this Flux to deserialize a JSON string.',
22
+ input: {
23
+ orange: "{\"people\":[{\"name\":\"John\"},{\"name\":\"Jane\"}]}"
24
+ },
25
+ config: {
26
+ key: 'orange'
27
+ },
28
+ result: { people: [ { name: "John" }, { name: "Jane" } ] }
29
+ },
30
+ }
18
31
  }
19
32
  end
20
33
 
21
34
  def process event, config
22
- return nil unless config[:json].to_s != ''
23
- JSON.parse config[:json]
35
+ return nil unless event[config[:key]].to_s != ''
36
+ JSON.parse event[config[:key]]
24
37
  end
25
38
 
26
39
  end