gloo 0.6.1 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/gloo/app/args.rb +48 -6
  4. data/lib/gloo/app/engine.rb +58 -39
  5. data/lib/gloo/app/help.rb +126 -25
  6. data/lib/gloo/app/info.rb +3 -1
  7. data/lib/gloo/app/log.rb +23 -0
  8. data/lib/gloo/app/mode.rb +2 -0
  9. data/lib/gloo/app/settings.rb +75 -68
  10. data/lib/gloo/convert/converter.rb +35 -0
  11. data/lib/gloo/convert/string_to_datetime.rb +1 -1
  12. data/lib/gloo/convert/string_to_decimal.rb +1 -1
  13. data/lib/gloo/convert/string_to_integer.rb +1 -1
  14. data/lib/gloo/core/dictionary.rb +99 -22
  15. data/lib/gloo/core/error.rb +19 -8
  16. data/lib/gloo/core/event_manager.rb +4 -0
  17. data/lib/gloo/core/factory.rb +11 -0
  18. data/lib/gloo/core/gloo_system.rb +1 -1
  19. data/lib/gloo/core/heap.rb +11 -3
  20. data/lib/gloo/core/it.rb +6 -0
  21. data/lib/gloo/core/literal.rb +5 -0
  22. data/lib/gloo/core/obj.rb +14 -0
  23. data/lib/gloo/core/op.rb +7 -0
  24. data/lib/gloo/core/parser.rb +6 -0
  25. data/lib/gloo/core/pn.rb +36 -0
  26. data/lib/gloo/core/tokens.rb +66 -22
  27. data/lib/gloo/core/verb.rb +4 -0
  28. data/lib/gloo/exec/exec_env.rb +13 -1
  29. data/lib/gloo/expr/expression.rb +26 -4
  30. data/lib/gloo/expr/l_boolean.rb +6 -0
  31. data/lib/gloo/expr/l_decimal.rb +5 -0
  32. data/lib/gloo/expr/l_integer.rb +7 -0
  33. data/lib/gloo/expr/l_string.rb +7 -0
  34. data/lib/gloo/expr/op_div.rb +2 -0
  35. data/lib/gloo/expr/op_minus.rb +2 -0
  36. data/lib/gloo/expr/op_mult.rb +2 -0
  37. data/lib/gloo/expr/op_plus.rb +2 -0
  38. data/lib/gloo/help/app/application.txt +22 -0
  39. data/lib/gloo/help/app/configuration.txt +7 -0
  40. data/lib/gloo/help/app/default_help.txt +14 -0
  41. data/lib/gloo/help/app/logging.txt +16 -0
  42. data/lib/gloo/help/core/color.txt +31 -0
  43. data/lib/gloo/help/core/error.txt +33 -0
  44. data/lib/gloo/help/core/events.txt +21 -0
  45. data/lib/gloo/help/core/gloo_system.txt +54 -0
  46. data/lib/gloo/help/core/here.txt +30 -0
  47. data/lib/gloo/help/core/it.txt +23 -0
  48. data/lib/gloo/help/core/ops.txt +16 -0
  49. data/lib/gloo/help/core/pathname.txt +29 -0
  50. data/lib/gloo/help/objs/basic/alias.txt +36 -0
  51. data/lib/gloo/help/objs/basic/boolean.txt +28 -0
  52. data/lib/gloo/help/objs/basic/container.txt +33 -0
  53. data/lib/gloo/help/objs/basic/decimal.txt +28 -0
  54. data/lib/gloo/help/objs/basic/integer.txt +27 -0
  55. data/lib/gloo/help/objs/basic/script.txt +29 -0
  56. data/lib/gloo/help/objs/basic/string.txt +28 -0
  57. data/lib/gloo/help/objs/basic/text.txt +27 -0
  58. data/lib/gloo/help/objs/basic/untyped.txt +22 -0
  59. data/lib/gloo/help/objs/cli/banner.txt +49 -0
  60. data/lib/gloo/help/objs/cli/bar.txt +34 -0
  61. data/lib/gloo/help/objs/cli/colorize.txt +33 -0
  62. data/lib/gloo/help/objs/cli/confirm.txt +26 -0
  63. data/lib/gloo/help/objs/cli/menu.txt +44 -0
  64. data/lib/gloo/help/objs/cli/menu_item.txt +26 -0
  65. data/lib/gloo/help/objs/cli/pastel.txt +43 -0
  66. data/lib/gloo/help/objs/cli/prompt.txt +27 -0
  67. data/lib/gloo/help/objs/cli/select.txt +34 -0
  68. data/lib/gloo/help/objs/ctrl/each.txt +48 -0
  69. data/lib/gloo/help/objs/ctrl/repeat.txt +38 -0
  70. data/lib/gloo/help/objs/data/markdown.txt +25 -0
  71. data/lib/gloo/help/objs/data/table.txt +46 -0
  72. data/lib/gloo/help/objs/dev/git_repo.txt +35 -0
  73. data/lib/gloo/help/objs/dt/date.txt +23 -0
  74. data/lib/gloo/help/objs/dt/datetime.txt +24 -0
  75. data/lib/gloo/help/objs/dt/time.txt +23 -0
  76. data/lib/gloo/help/objs/ror/erb.txt +37 -0
  77. data/lib/gloo/help/objs/ror/eval.txt +24 -0
  78. data/lib/gloo/help/objs/snd/play.txt +23 -0
  79. data/lib/gloo/help/objs/snd/say.txt +28 -0
  80. data/lib/gloo/help/objs/system/file.txt +48 -0
  81. data/lib/gloo/help/objs/system/system.txt +32 -0
  82. data/lib/gloo/help/objs/web/http_get.txt +35 -0
  83. data/lib/gloo/help/objs/web/http_post.txt +32 -0
  84. data/lib/gloo/help/objs/web/json.txt +34 -0
  85. data/lib/gloo/help/objs/web/slack.txt +33 -0
  86. data/lib/gloo/help/objs/web/teams.txt +30 -0
  87. data/lib/gloo/help/objs/web/uri.txt +37 -0
  88. data/lib/gloo/help/verbs/alert.txt +33 -0
  89. data/lib/gloo/help/verbs/beep.txt +25 -0
  90. data/lib/gloo/help/verbs/cls.txt +24 -0
  91. data/lib/gloo/help/verbs/context.txt +43 -0
  92. data/lib/gloo/help/verbs/create.txt +33 -0
  93. data/lib/gloo/help/verbs/execute.txt +27 -0
  94. data/lib/gloo/help/verbs/help.txt +34 -0
  95. data/lib/gloo/help/verbs/if.txt +37 -0
  96. data/lib/gloo/help/verbs/list.txt +34 -0
  97. data/lib/gloo/help/verbs/load.txt +38 -0
  98. data/lib/gloo/help/verbs/move.txt +42 -0
  99. data/lib/gloo/help/verbs/put.txt +38 -0
  100. data/lib/gloo/help/verbs/quit.txt +25 -0
  101. data/lib/gloo/help/verbs/run.txt +41 -0
  102. data/lib/gloo/help/verbs/save.txt +26 -0
  103. data/lib/gloo/help/verbs/show.txt +30 -0
  104. data/lib/gloo/help/verbs/tell.txt +34 -0
  105. data/lib/gloo/help/verbs/unless.txt +38 -0
  106. data/lib/gloo/help/verbs/version.txt +32 -0
  107. data/lib/gloo/help/verbs/wait.txt +29 -0
  108. data/lib/gloo/objs/basic/alias.rb +0 -33
  109. data/lib/gloo/objs/basic/boolean.rb +6 -27
  110. data/lib/gloo/objs/basic/container.rb +0 -33
  111. data/lib/gloo/objs/basic/decimal.rb +8 -28
  112. data/lib/gloo/objs/basic/integer.rb +5 -26
  113. data/lib/gloo/objs/basic/script.rb +0 -26
  114. data/lib/gloo/objs/basic/string.rb +6 -26
  115. data/lib/gloo/objs/basic/text.rb +0 -25
  116. data/lib/gloo/objs/basic/untyped.rb +0 -26
  117. data/lib/gloo/objs/cli/banner.rb +0 -29
  118. data/lib/gloo/objs/cli/bar.rb +0 -29
  119. data/lib/gloo/objs/cli/colorize.rb +4 -34
  120. data/lib/gloo/objs/cli/confirm.rb +6 -36
  121. data/lib/gloo/objs/cli/menu.rb +4 -34
  122. data/lib/gloo/objs/cli/menu_item.rb +0 -33
  123. data/lib/gloo/objs/cli/pastel.rb +4 -27
  124. data/lib/gloo/objs/cli/prompt.rb +4 -28
  125. data/lib/gloo/objs/cli/select.rb +4 -31
  126. data/lib/gloo/objs/ctrl/each.rb +33 -33
  127. data/lib/gloo/objs/ctrl/repeat.rb +8 -29
  128. data/lib/gloo/objs/data/markdown.rb +0 -25
  129. data/lib/gloo/objs/data/table.rb +4 -32
  130. data/lib/gloo/objs/dev/git.rb +12 -30
  131. data/lib/gloo/objs/dt/date.rb +3 -25
  132. data/lib/gloo/objs/dt/datetime.rb +4 -26
  133. data/lib/gloo/objs/dt/time.rb +3 -25
  134. data/lib/gloo/objs/ror/erb.rb +11 -45
  135. data/lib/gloo/objs/ror/eval.rb +11 -38
  136. data/lib/gloo/objs/snd/play.rb +2 -25
  137. data/lib/gloo/objs/snd/say.rb +9 -31
  138. data/lib/gloo/objs/system/file_handle.rb +7 -36
  139. data/lib/gloo/objs/system/system.rb +16 -46
  140. data/lib/gloo/objs/web/http_get.rb +57 -83
  141. data/lib/gloo/objs/web/http_post.rb +8 -31
  142. data/lib/gloo/objs/web/json.rb +11 -31
  143. data/lib/gloo/objs/web/slack.rb +7 -34
  144. data/lib/gloo/objs/web/teams.rb +13 -48
  145. data/lib/gloo/objs/web/uri.rb +0 -29
  146. data/lib/gloo/persist/file_loader.rb +8 -0
  147. data/lib/gloo/persist/file_saver.rb +6 -0
  148. data/lib/gloo/persist/file_storage.rb +2 -0
  149. data/lib/gloo/persist/line_splitter.rb +2 -0
  150. data/lib/gloo/persist/persist_man.rb +6 -0
  151. data/lib/gloo/verbs/alert.rb +30 -44
  152. data/lib/gloo/verbs/beep.rb +0 -30
  153. data/lib/gloo/verbs/cls.rb +0 -30
  154. data/lib/gloo/verbs/context.rb +9 -39
  155. data/lib/gloo/verbs/create.rb +17 -32
  156. data/lib/gloo/verbs/execute.rb +56 -0
  157. data/lib/gloo/verbs/help.rb +151 -115
  158. data/lib/gloo/verbs/if.rb +46 -44
  159. data/lib/gloo/verbs/list.rb +36 -54
  160. data/lib/gloo/verbs/load.rb +8 -37
  161. data/lib/gloo/verbs/move.rb +12 -51
  162. data/lib/gloo/verbs/put.rb +28 -52
  163. data/lib/gloo/verbs/quit.rb +0 -31
  164. data/lib/gloo/verbs/run.rb +23 -39
  165. data/lib/gloo/verbs/save.rb +0 -33
  166. data/lib/gloo/verbs/show.rb +6 -31
  167. data/lib/gloo/verbs/tell.rb +31 -31
  168. data/lib/gloo/verbs/unless.rb +47 -46
  169. data/lib/gloo/verbs/version.rb +0 -30
  170. data/lib/gloo/verbs/wait.rb +0 -31
  171. metadata +74 -3
  172. data/lib/gloo/help/help.md +0 -16
@@ -8,39 +8,50 @@ module Gloo
8
8
  module Core
9
9
  class Error
10
10
 
11
- attr_accessor :value
11
+ attr_accessor :value, :error_count
12
12
 
13
+ #
13
14
  # Set up the error object.
15
+ #
14
16
  def initialize
15
- @value = nil
17
+ clear
18
+ end
19
+
20
+ #
21
+ # Clear out the error message.
22
+ #
23
+ def clear
16
24
  @error_count = 0
25
+ @value = nil
17
26
  end
18
27
 
28
+ #
19
29
  # Set the value of error.
30
+ #
20
31
  def set_to( new_value )
21
32
  @error_count += 1
22
33
  @value = new_value
23
34
  end
24
35
 
25
- # Clear out the error message.
26
- def clear
27
- @error_count = 0
28
- @value = nil
29
- end
30
-
36
+ #
31
37
  # Start counting errors.
32
38
  # We're looking to see if we get any new ones during
33
39
  # a script or an immediate command.
40
+ #
34
41
  def start_tracking
35
42
  @error_count = 0
36
43
  end
37
44
 
45
+ #
38
46
  # Clear out error if we didn't add any new ones.
47
+ #
39
48
  def clear_if_no_errors
40
49
  self.clear if @error_count.zero?
41
50
  end
42
51
 
52
+ #
43
53
  # Get the string representation of the error.
54
+ #
44
55
  def to_s
45
56
  return @value.to_s
46
57
  end
@@ -9,7 +9,9 @@ module Gloo
9
9
  module Core
10
10
  class EventManager
11
11
 
12
+ #
12
13
  # Set up the event manager.
14
+ #
13
15
  def initialize
14
16
  $log.debug 'event manager intialized...'
15
17
  end
@@ -21,6 +23,7 @@ module Gloo
21
23
  def on_load( obj = nil, in_heap = false )
22
24
  return unless obj || in_heap
23
25
 
26
+ $log.debug 'on_load event'
24
27
  arr = Gloo::Core::ObjFinder.by_name 'on_load', obj
25
28
  arr.each { |o| Gloo::Exec::Dispatch.message 'run', o }
26
29
  end
@@ -31,6 +34,7 @@ module Gloo
31
34
  def on_unload( obj )
32
35
  return unless obj
33
36
 
37
+ $log.debug 'on_unload event'
34
38
  arr = Gloo::Core::ObjFinder.by_name 'on_unload', obj
35
39
  arr.each { |o| Gloo::Exec::Dispatch.message 'run', o }
36
40
  end
@@ -45,6 +45,17 @@ module Gloo
45
45
  create params
46
46
  end
47
47
 
48
+ #
49
+ # Helper shortcut to create a text child object.
50
+ #
51
+ def create_text( name, value, parent )
52
+ params = { :name => name,
53
+ :type => 'text',
54
+ :value => value,
55
+ :parent => parent }
56
+ create params
57
+ end
58
+
48
59
  #
49
60
  # Helper shortcut to create an integer child object.
50
61
  #
@@ -166,7 +166,7 @@ module Gloo
166
166
  return $settings.user_root
167
167
  end
168
168
 
169
- # Get the Gloo home directory
169
+ # Get the Gloo configuration directory
170
170
  def msg_gloo_config
171
171
  return $settings.config_path
172
172
  end
@@ -14,12 +14,11 @@ module Gloo
14
14
  # The context will be the root by default.
15
15
  attr_reader :context
16
16
 
17
- # TODO: Do I need a running script context?
18
- # how to resolve relative reference.
19
-
20
17
  attr_reader :it, :root, :error
21
18
 
19
+ #
22
20
  # Set up the object heap.
21
+ #
23
22
  def initialize
24
23
  $log.debug 'object heap intialized...'
25
24
 
@@ -31,7 +30,9 @@ module Gloo
31
30
  @error = Error.new
32
31
  end
33
32
 
33
+ #
34
34
  # Unload the given obj--remove it from the heap.
35
+ #
35
36
  def unload( obj )
36
37
  can = obj.parent.nil? ? @root : obj.parent
37
38
  return unless can
@@ -39,6 +40,13 @@ module Gloo
39
40
  can.remove_child obj
40
41
  end
41
42
 
43
+ #
44
+ # Is there one or more errors?
45
+ #
46
+ def error?
47
+ return @error.error_count.positive?
48
+ end
49
+
42
50
  end
43
51
  end
44
52
  end
@@ -10,17 +10,23 @@ module Gloo
10
10
 
11
11
  attr_accessor :value
12
12
 
13
+ #
13
14
  # Set up the object.
15
+ #
14
16
  def initialize
15
17
  @value = nil
16
18
  end
17
19
 
20
+ #
18
21
  # Set the value of it.
22
+ #
19
23
  def set_to( new_value )
20
24
  @value = new_value
21
25
  end
22
26
 
27
+ #
23
28
  # Get the string representation of it.
29
+ #
24
30
  def to_s
25
31
  return @value.to_s
26
32
  end
@@ -2,6 +2,7 @@
2
2
  # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
3
  #
4
4
  # A Literal value.
5
+ # Base class for all literal values.
5
6
  #
6
7
 
7
8
  module Gloo
@@ -10,12 +11,16 @@ module Gloo
10
11
 
11
12
  attr_reader :value
12
13
 
14
+ #
13
15
  # Create the expression from a list of tokens.
16
+ #
14
17
  def initialize( value )
15
18
  set_value( value )
16
19
  end
17
20
 
21
+ #
18
22
  # Set the literal value.
23
+ #
19
24
  def set_value( value )
20
25
  @value = value
21
26
  end
@@ -12,14 +12,18 @@ module Gloo
12
12
  attr_accessor :value
13
13
  attr_reader :children, :parent
14
14
 
15
+ #
15
16
  # Set up the object.
17
+ #
16
18
  def initialize
17
19
  @value = ''
18
20
  @children = []
19
21
  @parent = nil
20
22
  end
21
23
 
24
+ #
22
25
  # Register object types when they are loaded.
26
+ #
23
27
  def self.inherited( subclass )
24
28
  Dictionary.instance.register_obj( subclass )
25
29
  end
@@ -45,7 +49,9 @@ module Gloo
45
49
  @parent = obj
46
50
  end
47
51
 
52
+ #
48
53
  # Is this the root object?
54
+ #
49
55
  def root?
50
56
  return false if @parent
51
57
  return false unless name.downcase == 'root'
@@ -149,18 +155,24 @@ module Gloo
149
155
  return $engine.factory.create params
150
156
  end
151
157
 
158
+ #
152
159
  # Add a child object to the container.
160
+ #
153
161
  def add_child( obj )
154
162
  @children << obj
155
163
  obj.set_parent self
156
164
  end
157
165
 
166
+ #
158
167
  # Get the number of children.
168
+ #
159
169
  def child_count
160
170
  return @children.count
161
171
  end
162
172
 
173
+ #
163
174
  # Does this object contain an object with the given name?
175
+ #
164
176
  def contains_child?( name )
165
177
  @children.each do |o|
166
178
  return true if name.downcase == o.name.downcase
@@ -168,7 +180,9 @@ module Gloo
168
180
  return false
169
181
  end
170
182
 
183
+ #
171
184
  # Find a child object with the given name.
185
+ #
172
186
  def find_child( name )
173
187
  if name.end_with?( Gloo::Objs::Alias::ALIAS_REFERENCE )
174
188
  name = name[ 0..-2 ]
@@ -2,18 +2,23 @@
2
2
  # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
3
  #
4
4
  # An Operator; part of an expression.
5
+ # A static helper class.
5
6
  #
6
7
 
7
8
  module Gloo
8
9
  module Core
9
10
  class Op
10
11
 
12
+ #
11
13
  # Is the token an operator?
14
+ #
12
15
  def self.op?( token )
13
16
  return [ '+', '-', '*', '/' ].include?( token.strip )
14
17
  end
15
18
 
19
+ #
16
20
  # Create the operator for the given token.
21
+ #
17
22
  def self.create_op( token )
18
23
  return Gloo::Expr::OpMinus.new if token == '-'
19
24
  return Gloo::Expr::OpMult.new if token == '*'
@@ -23,7 +28,9 @@ module Gloo
23
28
  return default_op
24
29
  end
25
30
 
31
+ #
26
32
  # Get the default operator (+).
33
+ #
27
34
  def self.default_op
28
35
  return Gloo::Expr::OpPlus.new
29
36
  end
@@ -9,12 +9,16 @@ module Gloo
9
9
  module Core
10
10
  class Parser
11
11
 
12
+ #
12
13
  # Set up the parser.
14
+ #
13
15
  def initialize
14
16
  $log.debug 'parser intialized...'
15
17
  end
16
18
 
19
+ #
17
20
  # Parse a command from the immediate execution context.
21
+ #
18
22
  def parse_immediate( cmd )
19
23
  cmd, params = split_params cmd
20
24
  params = Gloo::Core::Tokens.new( params ) if params
@@ -27,8 +31,10 @@ module Gloo
27
31
  return nil
28
32
  end
29
33
 
34
+ #
30
35
  # If additional params were provided, split them out
31
36
  # from the token list.
37
+ #
32
38
  def split_params( cmd )
33
39
  params = nil
34
40
  i = cmd.rindex( '(' )
@@ -15,43 +15,59 @@ module Gloo
15
15
 
16
16
  attr_reader :src, :elements
17
17
 
18
+ #
18
19
  # Set up the object given a source string,
19
20
  # ie: the full path and name.
21
+ #
20
22
  def initialize( src )
21
23
  set_to src
22
24
  end
23
25
 
26
+ #
24
27
  # Reference to the root object path.
28
+ #
25
29
  def self.root
26
30
  return Pn.new( ROOT )
27
31
  end
28
32
 
33
+ #
29
34
  # Reference to it.
35
+ #
30
36
  def self.it
31
37
  return Pn.new( IT )
32
38
  end
33
39
 
40
+ #
34
41
  # Reference to the error message.
42
+ #
35
43
  def self.error
36
44
  return Pn.new( ERROR )
37
45
  end
38
46
 
47
+ #
39
48
  # Does the pathname reference refer to the root?
49
+ #
40
50
  def root?
41
51
  return @src.downcase == ROOT
42
52
  end
43
53
 
54
+ #
44
55
  # Does the pathname reference refer to it?
56
+ #
45
57
  def it?
46
58
  return @src.downcase == IT
47
59
  end
48
60
 
61
+ #
49
62
  # Does the pathname reference refer to error?
63
+ #
50
64
  def error?
51
65
  return @src.downcase == ERROR
52
66
  end
53
67
 
68
+ #
54
69
  # Does the pathname reference refer to the gloo system object?
70
+ #
55
71
  def gloo_sys?
56
72
  return false unless @elements&.count&.positive?
57
73
 
@@ -62,40 +78,54 @@ module Gloo
62
78
  return false
63
79
  end
64
80
 
81
+ #
65
82
  # Get the string representation of the pathname.
83
+ #
66
84
  def to_s
67
85
  return @src
68
86
  end
69
87
 
88
+ #
70
89
  # Set the object pathname to the given value.
90
+ #
71
91
  def set_to( value )
72
92
  @src = value.nil? ? nil : value.strip
73
93
  @elements = @src.nil? ? [] : @src.split( '.' )
74
94
  end
75
95
 
96
+ #
76
97
  # Convert the raw string to a list of segments.
98
+ #
77
99
  def segments
78
100
  return @elements
79
101
  end
80
102
 
103
+ #
81
104
  # Get the name element.
105
+ #
82
106
  def name
83
107
  return '' unless self.named?
84
108
 
85
109
  return @elements.last
86
110
  end
87
111
 
112
+ #
88
113
  # Does the value include path elements?
114
+ #
89
115
  def named?
90
116
  return @elements.count.positive?
91
117
  end
92
118
 
119
+ #
93
120
  # Does the value include a name?
121
+ #
94
122
  def includes_path?
95
123
  return @elements.count > 1
96
124
  end
97
125
 
126
+ #
98
127
  # Get the parent that contains the object referenced.
128
+ #
99
129
  def get_parent
100
130
  o = $engine.heap.root
101
131
 
@@ -112,7 +142,9 @@ module Gloo
112
142
  return o
113
143
  end
114
144
 
145
+ #
115
146
  # Does the object at the path exist?
147
+ #
116
148
  def exists?
117
149
  return true if self.root?
118
150
  return true if self.it?
@@ -124,14 +156,18 @@ module Gloo
124
156
  return parent.contains_child? name
125
157
  end
126
158
 
159
+ #
127
160
  # Is the reference to a color?
161
+ #
128
162
  def named_color?
129
163
  colors = %w[red blue green white black yellow]
130
164
  return true if colors.include?( @src.downcase )
131
165
  end
132
166
 
167
+ #
133
168
  # Resolve the pathname reference.
134
169
  # Find the object referenced or return nil if it is not found.
170
+ #
135
171
  def resolve
136
172
  return $engine.heap.root if self.root?
137
173
  return $engine.heap.it if self.it?