gloo 0.3.0 → 0.4.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.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +73 -0
  3. data/Gemfile +2 -2
  4. data/Gemfile.lock +3 -3
  5. data/Rakefile +6 -6
  6. data/bin/console +4 -4
  7. data/gloo.gemspec +19 -18
  8. data/lib/gloo.rb +6 -6
  9. data/lib/gloo/app/args.rb +30 -31
  10. data/lib/gloo/app/engine.rb +33 -28
  11. data/lib/gloo/app/help.rb +17 -11
  12. data/lib/gloo/app/info.rb +3 -3
  13. data/lib/gloo/app/log.rb +17 -17
  14. data/lib/gloo/app/mode.rb +4 -4
  15. data/lib/gloo/app/settings.rb +43 -40
  16. data/lib/gloo/core/baseo.rb +7 -7
  17. data/lib/gloo/core/dictionary.rb +30 -27
  18. data/lib/gloo/core/error.rb +50 -0
  19. data/lib/gloo/core/event_manager.rb +17 -19
  20. data/lib/gloo/core/factory.rb +92 -39
  21. data/lib/gloo/core/gloo_system.rb +49 -54
  22. data/lib/gloo/core/heap.rb +15 -13
  23. data/lib/gloo/core/it.rb +5 -5
  24. data/lib/gloo/core/literal.rb +7 -7
  25. data/lib/gloo/core/obj.rb +89 -79
  26. data/lib/gloo/core/obj_finder.rb +9 -14
  27. data/lib/gloo/core/op.rb +8 -8
  28. data/lib/gloo/core/parser.rb +25 -26
  29. data/lib/gloo/core/pn.rb +65 -50
  30. data/lib/gloo/core/runner.rb +26 -0
  31. data/lib/gloo/core/script.rb +7 -7
  32. data/lib/gloo/core/tokens.rb +39 -41
  33. data/lib/gloo/core/verb.rb +30 -19
  34. data/lib/gloo/expr/expression.rb +35 -43
  35. data/lib/gloo/expr/l_boolean.rb +7 -6
  36. data/lib/gloo/expr/l_integer.rb +5 -4
  37. data/lib/gloo/expr/l_string.rb +13 -15
  38. data/lib/gloo/expr/op_div.rb +3 -5
  39. data/lib/gloo/expr/op_minus.rb +3 -5
  40. data/lib/gloo/expr/op_mult.rb +3 -5
  41. data/lib/gloo/expr/op_plus.rb +5 -7
  42. data/lib/gloo/objs/basic/boolean.rb +63 -38
  43. data/lib/gloo/objs/basic/container.rb +40 -12
  44. data/lib/gloo/objs/basic/integer.rb +40 -16
  45. data/lib/gloo/objs/basic/script.rb +62 -38
  46. data/lib/gloo/objs/basic/string.rb +39 -15
  47. data/lib/gloo/objs/basic/text.rb +43 -20
  48. data/lib/gloo/objs/basic/untyped.rb +35 -10
  49. data/lib/gloo/objs/cli/colorize.rb +53 -23
  50. data/lib/gloo/objs/cli/confirm.rb +63 -29
  51. data/lib/gloo/objs/cli/prompt.rb +63 -29
  52. data/lib/gloo/objs/ctrl/each.rb +98 -60
  53. data/lib/gloo/objs/dev/git.rb +98 -64
  54. data/lib/gloo/objs/ror/erb.rb +81 -41
  55. data/lib/gloo/objs/ror/eval.rb +73 -31
  56. data/lib/gloo/objs/snd/play.rb +71 -0
  57. data/lib/gloo/objs/snd/say.rb +120 -0
  58. data/lib/gloo/objs/system/file_handle.rb +80 -48
  59. data/lib/gloo/objs/system/system.rb +84 -38
  60. data/lib/gloo/objs/web/http_get.rb +83 -46
  61. data/lib/gloo/objs/web/http_post.rb +69 -43
  62. data/lib/gloo/objs/web/slack.rb +89 -58
  63. data/lib/gloo/objs/web/teams.rb +88 -53
  64. data/lib/gloo/persist/file_loader.rb +81 -82
  65. data/lib/gloo/persist/file_saver.rb +12 -12
  66. data/lib/gloo/persist/file_storage.rb +15 -15
  67. data/lib/gloo/persist/line_splitter.rb +74 -0
  68. data/lib/gloo/persist/persist_man.rb +29 -29
  69. data/lib/gloo/utils/words.rb +2 -2
  70. data/lib/gloo/verbs/alert.rb +67 -16
  71. data/lib/gloo/verbs/beep.rb +70 -0
  72. data/lib/gloo/verbs/context.rb +61 -21
  73. data/lib/gloo/verbs/create.rb +52 -21
  74. data/lib/gloo/verbs/help.rb +177 -27
  75. data/lib/gloo/verbs/if.rb +54 -21
  76. data/lib/gloo/verbs/list.rb +55 -24
  77. data/lib/gloo/verbs/load.rb +46 -12
  78. data/lib/gloo/verbs/put.rb +90 -34
  79. data/lib/gloo/verbs/quit.rb +43 -12
  80. data/lib/gloo/verbs/run.rb +42 -11
  81. data/lib/gloo/verbs/save.rb +45 -10
  82. data/lib/gloo/verbs/show.rb +56 -22
  83. data/lib/gloo/verbs/tell.rb +44 -12
  84. data/lib/gloo/verbs/unless.rb +55 -21
  85. data/lib/gloo/verbs/version.rb +42 -12
  86. data/lib/run.rb +5 -5
  87. metadata +19 -12
@@ -12,50 +12,45 @@
12
12
  module Gloo
13
13
  module Objs
14
14
  class Each < Gloo::Core::Obj
15
-
16
- KEYWORD = 'each'
17
- KEYWORD_SHORT = 'each'
18
- WORD = 'word'
19
- LINE = 'line'
20
- FILE = 'file'
21
- REPO = 'repo'
22
- IN = 'IN'
23
- DO = 'do'
24
-
25
- #
15
+
16
+ KEYWORD = 'each'.freeze
17
+ KEYWORD_SHORT = 'each'.freeze
18
+ WORD = 'word'.freeze
19
+ LINE = 'line'.freeze
20
+ FILE = 'file'.freeze
21
+ REPO = 'repo'.freeze
22
+ IN = 'IN'.freeze
23
+ DO = 'do'.freeze
24
+
25
+ #
26
26
  # The name of the object type.
27
- #
27
+ #
28
28
  def self.typename
29
29
  return KEYWORD
30
30
  end
31
31
 
32
- #
32
+ #
33
33
  # The short name of the object type.
34
- #
34
+ #
35
35
  def self.short_typename
36
36
  return KEYWORD_SHORT
37
37
  end
38
-
39
- #
38
+
39
+ #
40
40
  # Get the URI from the child object.
41
41
  # Returns nil if there is none.
42
- #
43
- def get_in
42
+ #
43
+ def in_value
44
44
  o = find_child IN
45
- return nil unless o
46
- return o.value
45
+ return o ? o.value : nil
47
46
  end
48
-
47
+
49
48
  # Run the do script once.
50
49
  def run_do
51
50
  o = find_child DO
52
- if o.can_receive_message? "run"
53
- o.send_message "run"
54
- end
51
+ o.send_message( 'run' ) if o.can_receive_message? 'run'
55
52
  end
56
53
 
57
-
58
-
59
54
  # ---------------------------------------------------------------------
60
55
  # Children
61
56
  # ---------------------------------------------------------------------
@@ -66,29 +61,37 @@ module Gloo
66
61
  def add_children_on_create?
67
62
  return true
68
63
  end
69
-
64
+
70
65
  # Add children to this object.
71
- # This is used by containers to add children needed
66
+ # This is used by containers to add children needed
72
67
  # for default configurations.
73
68
  def add_default_children
74
69
  fac = $engine.factory
75
- fac.create "word", "string", "", self
76
- fac.create "in", "string", "", self
77
- fac.create "do", "script", "", self
70
+ fac.create( { :name => 'word',
71
+ :type => 'string',
72
+ :value => '',
73
+ :parent => self } )
74
+ fac.create( { :name => 'in',
75
+ :type => 'string',
76
+ :value => '',
77
+ :parent => self } )
78
+ fac.create( { :name => 'do',
79
+ :type => 'script',
80
+ :value => '',
81
+ :parent => self } )
78
82
  end
79
83
 
80
-
81
84
  # ---------------------------------------------------------------------
82
85
  # Messages
83
86
  # ---------------------------------------------------------------------
84
87
 
85
- #
88
+ #
86
89
  # Get a list of message names that this object receives.
87
- #
90
+ #
88
91
  def self.messages
89
- return super + [ "run" ]
92
+ return super + [ 'run' ]
90
93
  end
91
-
94
+
92
95
  # Run the system command.
93
96
  def msg_run
94
97
  if each_word?
@@ -99,8 +102,7 @@ module Gloo
99
102
  run_each_repo
100
103
  end
101
104
  end
102
-
103
-
105
+
104
106
  # ---------------------------------------------------------------------
105
107
  # Word
106
108
  # ---------------------------------------------------------------------
@@ -109,28 +111,29 @@ module Gloo
109
111
  # If there is a child object by the name "word"
110
112
  # then we will loop for each word in the string.
111
113
  def each_word?
112
- o = find_child WORD
113
- return true if o
114
+ return true if find_child WORD
115
+
114
116
  return false
115
117
  end
116
118
 
117
119
  # Run for each word.
118
120
  def run_each_word
119
- str = get_in
121
+ str = in_value
120
122
  return unless str
121
- str.split( " " ).each do |word|
123
+
124
+ str.split( ' ' ).each do |word|
122
125
  set_word word
123
126
  run_do
124
127
  end
125
128
  end
126
-
129
+
127
130
  # Set the value of the word.
128
- def set_word word
131
+ def set_word( word )
129
132
  o = find_child WORD
130
133
  return unless o
134
+
131
135
  o.set_value word
132
136
  end
133
-
134
137
 
135
138
  # ---------------------------------------------------------------------
136
139
  # Line
@@ -140,30 +143,30 @@ module Gloo
140
143
  # If there is a child object by the name "line"
141
144
  # then we will loop for each line in the string.
142
145
  def each_line?
143
- o = find_child LINE
144
- return true if o
146
+ return true if find_child LINE
147
+
145
148
  return false
146
149
  end
147
-
150
+
148
151
  # Run for each line.
149
152
  def run_each_line
150
- str = get_in
153
+ str = in_value
151
154
  return unless str
152
- str.split( "\n" ).each do |line|
155
+
156
+ str.split( '\n' ).each do |line|
153
157
  set_line line
154
158
  run_do
155
159
  end
156
160
  end
157
-
161
+
158
162
  # Set the value of the word.
159
- def set_line line
163
+ def set_line( line )
160
164
  o = find_child LINE
161
165
  return unless o
166
+
162
167
  o.set_value line
163
168
  end
164
169
 
165
-
166
-
167
170
  # ---------------------------------------------------------------------
168
171
  # Git Repo
169
172
  # ---------------------------------------------------------------------
@@ -172,11 +175,11 @@ module Gloo
172
175
  # If there is a child object by the name "repo"
173
176
  # then we will loop for each repo in the directory.
174
177
  def each_repo?
175
- o = find_child REPO
176
- return true if o
178
+ return true if find_child REPO
179
+
177
180
  return false
178
181
  end
179
-
182
+
180
183
  def find_all_git_projects( path )
181
184
  path.children.collect do |f|
182
185
  if f.directory? && ( File.basename( f ) == '.git' )
@@ -189,8 +192,9 @@ module Gloo
189
192
 
190
193
  # Run for each line.
191
194
  def run_each_repo
192
- path = get_in
195
+ path = in_value
193
196
  return unless path
197
+
194
198
  path = Pathname.new( path )
195
199
  repos = find_all_git_projects( path )
196
200
  repos.each do |o|
@@ -198,15 +202,49 @@ module Gloo
198
202
  run_do
199
203
  end
200
204
  end
201
-
205
+
202
206
  # Set the value of the repo.
203
207
  # This is a path to the repo.
204
- def set_repo path
208
+ def set_repo( path )
205
209
  o = find_child REPO
206
210
  return unless o
211
+
207
212
  o.set_value path
208
213
  end
209
214
 
215
+ # ---------------------------------------------------------------------
216
+ # Help
217
+ # ---------------------------------------------------------------------
218
+
219
+ #
220
+ # Get help for this object type.
221
+ #
222
+ def self.help
223
+ return <<~TEXT
224
+ EACH OBJECT TYPE
225
+ NAME: each
226
+ SHORTCUT: each
227
+
228
+ DESCRIPTION
229
+ Perform an action for each item in a collection.
230
+
231
+ CHILDREN
232
+ word | line | repo - string - none
233
+ The entity we want to loop for.
234
+ It will hold the current value while the script is running.
235
+ in - string - none
236
+ The collection we will iterate in.
237
+ In the case of <word> or <line> this will be a string or text.
238
+ In the case of <repo> this will be the root path.
239
+ do - script - none
240
+ The action we want to perform for each found item.
241
+
242
+ MESSAGES
243
+ run - Look through the collecion and perform this for each
244
+ found item.
245
+ TEXT
246
+ end
247
+
210
248
  end
211
249
  end
212
250
  end
@@ -7,106 +7,140 @@
7
7
  module Gloo
8
8
  module Objs
9
9
  class Git < Gloo::Core::Obj
10
-
11
- KEYWORD = 'git_repo'
12
- KEYWORD_SHORT = 'git'
13
10
 
14
- #
11
+ KEYWORD = 'git_repo'.freeze
12
+ KEYWORD_SHORT = 'git'.freeze
13
+
14
+ #
15
15
  # The name of the object type.
16
- #
16
+ #
17
17
  def self.typename
18
18
  return KEYWORD
19
19
  end
20
20
 
21
- #
21
+ #
22
22
  # The short name of the object type.
23
- #
23
+ #
24
24
  def self.short_typename
25
25
  return KEYWORD_SHORT
26
26
  end
27
-
28
- #
27
+
28
+ #
29
29
  # Get the path to the git repo (locally).
30
- #
31
- def get_path
30
+ #
31
+ def path_value
32
32
  return value
33
33
  end
34
34
 
35
-
36
35
  # ---------------------------------------------------------------------
37
36
  # Messages
38
37
  # ---------------------------------------------------------------------
39
38
 
40
- #
39
+ #
41
40
  # Get a list of message names that this object receives.
42
- #
41
+ #
43
42
  def self.messages
44
- return super + [ "validate", "check_changes", "get_changes",
45
- "commit", "get_branch" ]
43
+ return super + %w[validate check_changes get_changes commit get_branch]
46
44
  end
47
-
48
- # Get the current working branch.
49
- def msg_get_branch
50
- branch = ""
51
- path = get_path
52
- if path and File.directory?( path )
53
- branch = `cd #{path}; git rev-parse --abbrev-ref HEAD`
54
- branch = branch.strip
55
- end
56
45
 
57
- $engine.heap.it.set_to branch
58
- end
46
+ # Get the current working branch.
47
+ def msg_get_branch
48
+ branch = ''
49
+ path = path_value
50
+ if path_is_dir?( path )
51
+ branch = `cd #{path}; git rev-parse --abbrev-ref HEAD`
52
+ branch = branch.strip
53
+ end
59
54
 
55
+ $engine.heap.it.set_to branch
56
+ end
60
57
 
61
- # Check to see if the repo has changes.
58
+ # Commit pending changes.
62
59
  def msg_commit
63
- msg = "Commit"
64
- path = get_path
65
- if path && File.directory?( path )
66
- if @params && @params.token_count > 0
67
- expr = Gloo::Expr::Expression.new( @params.tokens )
68
- msg = expr.evaluate
69
- end
70
- branch = `cd #{path}; git rev-parse --abbrev-ref HEAD`
71
- branch = branch.strip
72
- result = `cd #{path}; git add .; git commit -m "#{msg}";git push origin #{branch}`
73
- end
74
- $engine.heap.it.set_to msg
60
+ msg = 'Commit'
61
+ path = path_value
62
+ if path_is_dir?( path )
63
+ if @params&.token_count&.positive?
64
+ expr = Gloo::Expr::Expression.new( @params.tokens )
65
+ msg = expr.evaluate
66
+ end
67
+ branch = `cd #{path}; git rev-parse --abbrev-ref HEAD`
68
+ branch = branch.strip
69
+ add = 'git add .'
70
+ cmt = 'git commit -m '
71
+ psh = 'git push origin '
72
+ `cd #{path};#{add};#{cmt}"#{msg}";#{psh}#{branch}`
73
+ end
74
+ $engine.heap.it.set_to msg
75
75
  end
76
76
 
77
- # Check to see if the repo has changes.
77
+ # Get the pending changes.
78
78
  def msg_get_changes
79
- path = get_path
80
- if path and File.directory?( path )
81
- result = `cd #{path}; git status -s`
82
- end
83
- result = result ? result : ""
84
- $engine.heap.it.set_to result
79
+ path = path_value
80
+ result = `cd #{path}; git status -s` if path_is_dir?( path )
81
+ result ||= ''
82
+ $engine.heap.it.set_to result
83
+ end
84
+
85
+ # Is the given path non nil and is it a directory?
86
+ def path_is_dir?( path )
87
+ return path && File.directory?( path )
85
88
  end
86
89
 
87
- # Check to see if the repo has changes.
90
+ # Check to see if the repo has changes.
88
91
  def msg_check_changes
89
- result = false
90
- path = get_path
91
- if path and File.directory?( path )
92
- data = `cd #{path}; git status -s`
93
- result = true unless ( data.strip.length == 0 )
94
- end
95
-
96
- $engine.heap.it.set_to result
92
+ result = false
93
+ path = path_value
94
+ if path_is_dir?( path )
95
+ data = `cd #{path}; git status -s`
96
+ result = true unless data.strip.empty?
97
+ end
98
+
99
+ $engine.heap.it.set_to result
97
100
  end
98
-
101
+
99
102
  # Check to make sure this is a valide git repo.
100
103
  def msg_validate
101
- result = false
102
- path = get_path
103
- if path and File.directory?( path )
104
- result = File.exists? File.join( path, '.git' )
105
- end
104
+ result = false
105
+ path = path_value
106
+ if path_is_dir?( path )
107
+ pn = File.join( path, '.git' )
108
+ result = File.exist? pn
109
+ end
110
+
111
+ $engine.heap.it.set_to result
112
+ end
113
+
114
+ # ---------------------------------------------------------------------
115
+ # Help
116
+ # ---------------------------------------------------------------------
106
117
 
107
- $engine.heap.it.set_to result
118
+ #
119
+ # Get help for this object type.
120
+ #
121
+ def self.help
122
+ return <<~TEXT
123
+ GIT OBJECT TYPE
124
+ NAME: git_repo
125
+ SHORTCUT: git
126
+
127
+ DESCRIPTION
128
+ Reference to a git repository in the file system.
129
+ The value of the git_repo objectd is a string.
130
+ There are no children needed.
131
+
132
+ CHILDREN
133
+ None
134
+
135
+ MESSAGES
136
+ validate - Validate that this is a git repo.
137
+ check_changes - Check to see if there are any pending changes.
138
+ get_changes - Get the list of pending changes.
139
+ commit - Commit changes.
140
+ get_branch - Get the current branch.
141
+ TEXT
108
142
  end
109
-
143
+
110
144
  end
111
145
  end
112
146
  end