gloo 0.8.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.gitignore +2 -1
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/LICENSE.txt +1 -1
  7. data/gloo.gemspec +12 -4
  8. data/lib/VERSION +1 -1
  9. data/lib/dependencies.rb +4 -4
  10. data/lib/gloo/app/info.rb +3 -1
  11. data/lib/gloo/app/log.rb +1 -29
  12. data/lib/gloo/app/platform.rb +142 -0
  13. data/lib/gloo/objs/cli/banner.rb +2 -2
  14. data/lib/gloo/objs/cli/bar.rb +4 -4
  15. data/lib/gloo/objs/cli/colorize.rb +3 -3
  16. data/lib/gloo/objs/cli/confirm.rb +3 -3
  17. data/lib/gloo/objs/cli/menu.rb +9 -9
  18. data/lib/gloo/objs/cli/menu_item.rb +2 -2
  19. data/lib/gloo/objs/cli/pastel.rb +2 -2
  20. data/lib/gloo/objs/cli/prompt.rb +4 -4
  21. data/lib/gloo/objs/cli/select.rb +4 -4
  22. data/lib/gloo/objs/data/mysql.rb +9 -9
  23. data/lib/gloo/objs/data/sqlite.rb +10 -10
  24. data/lib/gloo/objs/dev/git.rb +7 -7
  25. data/lib/gloo/objs/dev/stats.rb +8 -5
  26. data/lib/gloo/objs/snd/play.rb +1 -1
  27. data/lib/gloo/objs/snd/say.rb +2 -2
  28. data/lib/gloo/objs/system/file_handle.rb +9 -9
  29. data/lib/gloo/objs/system/ssh_exec.rb +3 -3
  30. data/lib/gloo/objs/system/system.rb +2 -2
  31. data/lib/gloo/verbs/alert.rb +7 -7
  32. data/lib/gloo/verbs/beep.rb +1 -1
  33. data/lib/gloo/verbs/cls.rb +2 -2
  34. data/lib/gloo/verbs/help.rb +7 -189
  35. data/lib/gloo/verbs/version.rb +3 -3
  36. data/lib/gloo.rb +5 -1
  37. data/lib/run.rb +5 -1
  38. metadata +41 -177
  39. data/Gemfile.lock +0 -171
  40. data/lib/gloo/app/args.rb +0 -112
  41. data/lib/gloo/app/engine.rb +0 -230
  42. data/lib/gloo/app/help.rb +0 -156
  43. data/lib/gloo/app/mode.rb +0 -27
  44. data/lib/gloo/app/settings.rb +0 -186
  45. data/lib/gloo/convert/converter.rb +0 -35
  46. data/lib/gloo/convert/string_to_datetime.rb +0 -21
  47. data/lib/gloo/convert/string_to_decimal.rb +0 -20
  48. data/lib/gloo/convert/string_to_integer.rb +0 -20
  49. data/lib/gloo/core/baseo.rb +0 -30
  50. data/lib/gloo/core/dictionary.rb +0 -181
  51. data/lib/gloo/core/error.rb +0 -61
  52. data/lib/gloo/core/event_manager.rb +0 -44
  53. data/lib/gloo/core/factory.rb +0 -210
  54. data/lib/gloo/core/gloo_system.rb +0 -266
  55. data/lib/gloo/core/heap.rb +0 -52
  56. data/lib/gloo/core/here.rb +0 -36
  57. data/lib/gloo/core/it.rb +0 -36
  58. data/lib/gloo/core/literal.rb +0 -30
  59. data/lib/gloo/core/obj.rb +0 -303
  60. data/lib/gloo/core/obj_finder.rb +0 -30
  61. data/lib/gloo/core/op.rb +0 -40
  62. data/lib/gloo/core/parser.rb +0 -59
  63. data/lib/gloo/core/pn.rb +0 -188
  64. data/lib/gloo/core/tokens.rb +0 -165
  65. data/lib/gloo/core/verb.rb +0 -86
  66. data/lib/gloo/exec/action.rb +0 -48
  67. data/lib/gloo/exec/dispatch.rb +0 -40
  68. data/lib/gloo/exec/exec_env.rb +0 -74
  69. data/lib/gloo/exec/runner.rb +0 -45
  70. data/lib/gloo/exec/script.rb +0 -49
  71. data/lib/gloo/exec/stack.rb +0 -78
  72. data/lib/gloo/expr/expression.rb +0 -118
  73. data/lib/gloo/expr/l_boolean.rb +0 -36
  74. data/lib/gloo/expr/l_decimal.rb +0 -39
  75. data/lib/gloo/expr/l_integer.rb +0 -37
  76. data/lib/gloo/expr/l_string.rb +0 -58
  77. data/lib/gloo/expr/op_div.rb +0 -22
  78. data/lib/gloo/expr/op_minus.rb +0 -22
  79. data/lib/gloo/expr/op_mult.rb +0 -22
  80. data/lib/gloo/expr/op_plus.rb +0 -24
  81. data/lib/gloo/help/app/application.txt +0 -22
  82. data/lib/gloo/help/app/configuration.txt +0 -7
  83. data/lib/gloo/help/app/default_help.txt +0 -14
  84. data/lib/gloo/help/app/logging.txt +0 -16
  85. data/lib/gloo/help/core/color.txt +0 -31
  86. data/lib/gloo/help/core/error.txt +0 -33
  87. data/lib/gloo/help/core/events.txt +0 -21
  88. data/lib/gloo/help/core/gloo_system.txt +0 -57
  89. data/lib/gloo/help/core/here.txt +0 -30
  90. data/lib/gloo/help/core/it.txt +0 -23
  91. data/lib/gloo/help/core/ops.txt +0 -16
  92. data/lib/gloo/help/core/pathname.txt +0 -29
  93. data/lib/gloo/help/objs/basic/alias.txt +0 -36
  94. data/lib/gloo/help/objs/basic/boolean.txt +0 -28
  95. data/lib/gloo/help/objs/basic/container.txt +0 -33
  96. data/lib/gloo/help/objs/basic/decimal.txt +0 -28
  97. data/lib/gloo/help/objs/basic/integer.txt +0 -27
  98. data/lib/gloo/help/objs/basic/script.txt +0 -29
  99. data/lib/gloo/help/objs/basic/string.txt +0 -28
  100. data/lib/gloo/help/objs/basic/text.txt +0 -27
  101. data/lib/gloo/help/objs/basic/untyped.txt +0 -22
  102. data/lib/gloo/help/objs/cli/banner.txt +0 -49
  103. data/lib/gloo/help/objs/cli/bar.txt +0 -37
  104. data/lib/gloo/help/objs/cli/colorize.txt +0 -33
  105. data/lib/gloo/help/objs/cli/confirm.txt +0 -26
  106. data/lib/gloo/help/objs/cli/menu.txt +0 -44
  107. data/lib/gloo/help/objs/cli/menu_item.txt +0 -26
  108. data/lib/gloo/help/objs/cli/pastel.txt +0 -43
  109. data/lib/gloo/help/objs/cli/prompt.txt +0 -27
  110. data/lib/gloo/help/objs/cli/select.txt +0 -34
  111. data/lib/gloo/help/objs/ctrl/each.txt +0 -48
  112. data/lib/gloo/help/objs/ctrl/repeat.txt +0 -38
  113. data/lib/gloo/help/objs/data/markdown.txt +0 -25
  114. data/lib/gloo/help/objs/data/mysql.txt +0 -40
  115. data/lib/gloo/help/objs/data/query.txt +0 -37
  116. data/lib/gloo/help/objs/data/sqlite.txt +0 -26
  117. data/lib/gloo/help/objs/data/table.txt +0 -46
  118. data/lib/gloo/help/objs/dev/git_repo.txt +0 -36
  119. data/lib/gloo/help/objs/dev/stats.txt +0 -36
  120. data/lib/gloo/help/objs/dt/date.txt +0 -23
  121. data/lib/gloo/help/objs/dt/datetime.txt +0 -24
  122. data/lib/gloo/help/objs/dt/time.txt +0 -23
  123. data/lib/gloo/help/objs/ror/erb.txt +0 -37
  124. data/lib/gloo/help/objs/ror/eval.txt +0 -24
  125. data/lib/gloo/help/objs/snd/play.txt +0 -23
  126. data/lib/gloo/help/objs/snd/say.txt +0 -28
  127. data/lib/gloo/help/objs/system/file.txt +0 -48
  128. data/lib/gloo/help/objs/system/ssh_exec.txt +0 -30
  129. data/lib/gloo/help/objs/system/system.txt +0 -32
  130. data/lib/gloo/help/objs/web/http_get.txt +0 -35
  131. data/lib/gloo/help/objs/web/http_post.txt +0 -34
  132. data/lib/gloo/help/objs/web/json.txt +0 -34
  133. data/lib/gloo/help/objs/web/slack.txt +0 -33
  134. data/lib/gloo/help/objs/web/teams.txt +0 -30
  135. data/lib/gloo/help/objs/web/uri.txt +0 -38
  136. data/lib/gloo/help/verbs/alert.txt +0 -33
  137. data/lib/gloo/help/verbs/beep.txt +0 -25
  138. data/lib/gloo/help/verbs/cls.txt +0 -24
  139. data/lib/gloo/help/verbs/context.txt +0 -43
  140. data/lib/gloo/help/verbs/create.txt +0 -33
  141. data/lib/gloo/help/verbs/execute.txt +0 -27
  142. data/lib/gloo/help/verbs/help.txt +0 -34
  143. data/lib/gloo/help/verbs/if.txt +0 -37
  144. data/lib/gloo/help/verbs/list.txt +0 -34
  145. data/lib/gloo/help/verbs/load.txt +0 -38
  146. data/lib/gloo/help/verbs/move.txt +0 -42
  147. data/lib/gloo/help/verbs/put.txt +0 -38
  148. data/lib/gloo/help/verbs/quit.txt +0 -25
  149. data/lib/gloo/help/verbs/run.txt +0 -41
  150. data/lib/gloo/help/verbs/save.txt +0 -26
  151. data/lib/gloo/help/verbs/show.txt +0 -30
  152. data/lib/gloo/help/verbs/tell.txt +0 -34
  153. data/lib/gloo/help/verbs/unless.txt +0 -38
  154. data/lib/gloo/help/verbs/version.txt +0 -32
  155. data/lib/gloo/help/verbs/wait.txt +0 -29
  156. data/lib/gloo/objs/basic/alias.rb +0 -78
  157. data/lib/gloo/objs/basic/boolean.rb +0 -120
  158. data/lib/gloo/objs/basic/container.rb +0 -76
  159. data/lib/gloo/objs/basic/decimal.rb +0 -76
  160. data/lib/gloo/objs/basic/integer.rb +0 -73
  161. data/lib/gloo/objs/basic/script.rb +0 -99
  162. data/lib/gloo/objs/basic/string.rb +0 -77
  163. data/lib/gloo/objs/basic/text.rb +0 -87
  164. data/lib/gloo/objs/basic/untyped.rb +0 -41
  165. data/lib/gloo/objs/ctrl/each.rb +0 -279
  166. data/lib/gloo/objs/ctrl/repeat.rb +0 -108
  167. data/lib/gloo/objs/data/markdown.rb +0 -84
  168. data/lib/gloo/objs/data/query.rb +0 -176
  169. data/lib/gloo/objs/data/table.rb +0 -140
  170. data/lib/gloo/objs/dt/date.rb +0 -50
  171. data/lib/gloo/objs/dt/datetime.rb +0 -62
  172. data/lib/gloo/objs/dt/time.rb +0 -50
  173. data/lib/gloo/objs/ror/erb.rb +0 -116
  174. data/lib/gloo/objs/ror/eval.rb +0 -107
  175. data/lib/gloo/objs/web/http_get.rb +0 -159
  176. data/lib/gloo/objs/web/http_post.rb +0 -183
  177. data/lib/gloo/objs/web/json.rb +0 -135
  178. data/lib/gloo/objs/web/slack.rb +0 -130
  179. data/lib/gloo/objs/web/teams.rb +0 -117
  180. data/lib/gloo/objs/web/uri.rb +0 -148
  181. data/lib/gloo/persist/file_loader.rb +0 -191
  182. data/lib/gloo/persist/file_saver.rb +0 -49
  183. data/lib/gloo/persist/file_storage.rb +0 -45
  184. data/lib/gloo/persist/line_splitter.rb +0 -81
  185. data/lib/gloo/persist/persist_man.rb +0 -120
  186. data/lib/gloo/utils/format.rb +0 -21
  187. data/lib/gloo/utils/stats.rb +0 -205
  188. data/lib/gloo/utils/words.rb +0 -19
  189. data/lib/gloo/verbs/context.rb +0 -62
  190. data/lib/gloo/verbs/create.rb +0 -68
  191. data/lib/gloo/verbs/execute.rb +0 -56
  192. data/lib/gloo/verbs/if.rb +0 -92
  193. data/lib/gloo/verbs/list.rb +0 -98
  194. data/lib/gloo/verbs/load.rb +0 -45
  195. data/lib/gloo/verbs/move.rb +0 -89
  196. data/lib/gloo/verbs/put.rb +0 -94
  197. data/lib/gloo/verbs/quit.rb +0 -40
  198. data/lib/gloo/verbs/run.rb +0 -75
  199. data/lib/gloo/verbs/save.rb +0 -39
  200. data/lib/gloo/verbs/show.rb +0 -64
  201. data/lib/gloo/verbs/tell.rb +0 -79
  202. data/lib/gloo/verbs/unless.rb +0 -92
  203. data/lib/gloo/verbs/wait.rb +0 -42
@@ -1,30 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
- #
4
- # Utility used to find objects.
5
- #
6
-
7
- module Gloo
8
- module Core
9
- class ObjFinder
10
-
11
- #
12
- # Find all objects in the given container that have
13
- # the given name.
14
- # If the container isn't provided, root will be used.
15
- #
16
- def self.by_name( name, container = nil )
17
- container = $engine.heap.root if container.nil?
18
- arr = []
19
-
20
- container.children.each do |o|
21
- arr << o if o.name == name
22
- arr += by_name( name, o ) if o.child_count.positive?
23
- end
24
-
25
- return arr
26
- end
27
-
28
- end
29
- end
30
- end
data/lib/gloo/core/op.rb DELETED
@@ -1,40 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
- #
4
- # An Operator; part of an expression.
5
- # A static helper class.
6
- #
7
-
8
- module Gloo
9
- module Core
10
- class Op
11
-
12
- #
13
- # Is the token an operator?
14
- #
15
- def self.op?( token )
16
- return [ '+', '-', '*', '/' ].include?( token.strip )
17
- end
18
-
19
- #
20
- # Create the operator for the given token.
21
- #
22
- def self.create_op( token )
23
- return Gloo::Expr::OpMinus.new if token == '-'
24
- return Gloo::Expr::OpMult.new if token == '*'
25
- return Gloo::Expr::OpDiv.new if token == '/'
26
- return Gloo::Expr::OpPlus.new if token == '+'
27
-
28
- return default_op
29
- end
30
-
31
- #
32
- # Get the default operator (+).
33
- #
34
- def self.default_op
35
- return Gloo::Expr::OpPlus.new
36
- end
37
-
38
- end
39
- end
40
- end
@@ -1,59 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
- #
4
- # The Parser.
5
- # Can parse single line commands or files.
6
- #
7
-
8
- module Gloo
9
- module Core
10
- class Parser
11
-
12
- #
13
- # Set up the parser.
14
- #
15
- def initialize
16
- $log.debug 'parser intialized...'
17
- end
18
-
19
- #
20
- # Parse a command from the immediate execution context.
21
- #
22
- def parse_immediate( cmd )
23
- cmd, params = split_params cmd
24
- params = Gloo::Core::Tokens.new( params ) if params
25
- tokens = Gloo::Core::Tokens.new( cmd )
26
- dic = Gloo::Core::Dictionary.instance
27
- verb = dic.find_verb( tokens.verb )
28
- return verb.new( tokens, params ) if verb
29
-
30
- $log.error "Verb '#{tokens.verb}' was not found."
31
- return nil
32
- end
33
-
34
- #
35
- # If additional params were provided, split them out
36
- # from the token list.
37
- #
38
- def split_params( cmd )
39
- params = nil
40
- i = cmd.rindex( '(' )
41
- if i && cmd.strip.end_with?( ')' )
42
- pstr = cmd[ i + 1..-1 ]
43
- params = pstr.strip[ 0..-2 ] if pstr
44
- cmd = cmd[ 0, i - 1 ]
45
- end
46
- return cmd, params
47
- end
48
-
49
- #
50
- # Parse a command and then run it if it parsed correctly.
51
- #
52
- def run( cmd )
53
- v = parse_immediate( cmd )
54
- Gloo::Exec::Runner.go( v ) if v
55
- end
56
-
57
- end
58
- end
59
- end
data/lib/gloo/core/pn.rb DELETED
@@ -1,188 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
- #
4
- # An object path name.
5
- # Path and name elements are separated by periods.
6
- #
7
-
8
- module Gloo
9
- module Core
10
- class Pn < Baseo
11
-
12
- ROOT = 'root'.freeze
13
- IT = 'it'.freeze
14
- ERROR = 'error'.freeze
15
-
16
- attr_reader :src, :elements
17
-
18
- #
19
- # Set up the object given a source string,
20
- # ie: the full path and name.
21
- #
22
- def initialize( src )
23
- set_to src
24
- end
25
-
26
- #
27
- # Reference to the root object path.
28
- #
29
- def self.root
30
- return Pn.new( ROOT )
31
- end
32
-
33
- #
34
- # Reference to it.
35
- #
36
- def self.it
37
- return Pn.new( IT )
38
- end
39
-
40
- #
41
- # Reference to the error message.
42
- #
43
- def self.error
44
- return Pn.new( ERROR )
45
- end
46
-
47
- #
48
- # Does the pathname reference refer to the root?
49
- #
50
- def root?
51
- return @src.downcase == ROOT
52
- end
53
-
54
- #
55
- # Does the pathname reference refer to it?
56
- #
57
- def it?
58
- return @src.downcase == IT
59
- end
60
-
61
- #
62
- # Does the pathname reference refer to error?
63
- #
64
- def error?
65
- return @src.downcase == ERROR
66
- end
67
-
68
- #
69
- # Does the pathname reference refer to the gloo system object?
70
- #
71
- def gloo_sys?
72
- return false unless @elements&.count&.positive?
73
-
74
- o = @elements.first.downcase
75
- return true if o == Gloo::Core::GlooSystem.typename
76
- return true if o == Gloo::Core::GlooSystem.short_typename
77
-
78
- return false
79
- end
80
-
81
- #
82
- # Get the string representation of the pathname.
83
- #
84
- def to_s
85
- return @src
86
- end
87
-
88
- #
89
- # Set the object pathname to the given value.
90
- #
91
- def set_to( value )
92
- @src = value.nil? ? nil : value.strip
93
- @elements = @src.nil? ? [] : @src.split( '.' )
94
- end
95
-
96
- #
97
- # Convert the raw string to a list of segments.
98
- #
99
- def segments
100
- return @elements
101
- end
102
-
103
- #
104
- # Get the name element.
105
- #
106
- def name
107
- return '' unless self.named?
108
-
109
- return @elements.last
110
- end
111
-
112
- #
113
- # Does the value include path elements?
114
- #
115
- def named?
116
- return @elements.count.positive?
117
- end
118
-
119
- #
120
- # Does the value include a name?
121
- #
122
- def includes_path?
123
- return @elements.count > 1
124
- end
125
-
126
- #
127
- # Get the parent that contains the object referenced.
128
- #
129
- def get_parent
130
- o = $engine.heap.root
131
-
132
- if self.includes_path?
133
- @elements[ 0..-2 ].each do |e|
134
- o = o.find_child( e )
135
- if o.nil?
136
- $log.error "Object '#{e}' was not found."
137
- return nil
138
- end
139
- end
140
- end
141
-
142
- return o
143
- end
144
-
145
- #
146
- # Does the object at the path exist?
147
- #
148
- def exists?
149
- return true if self.root?
150
- return true if self.it?
151
- return true if self.error?
152
-
153
- parent = self.get_parent
154
- return false unless parent
155
-
156
- return parent.contains_child? name
157
- end
158
-
159
- #
160
- # Is the reference to a color?
161
- #
162
- def named_color?
163
- colors = %w[red blue green white black yellow]
164
- return true if colors.include?( @src.downcase )
165
- end
166
-
167
- #
168
- # Resolve the pathname reference.
169
- # Find the object referenced or return nil if it is not found.
170
- #
171
- def resolve
172
- return $engine.heap.root if self.root?
173
- return $engine.heap.it if self.it?
174
- return $engine.heap.error if self.error?
175
- return Gloo::Core::GlooSystem.new( self ) if self.gloo_sys?
176
-
177
- Here.expand_here( self ) if Here.includes_here_ref?( @elements )
178
-
179
- parent = self.get_parent
180
- return nil unless parent
181
-
182
- obj = parent.find_child( self.name )
183
- return Gloo::Objs::Alias.resolve_alias( obj, self.src )
184
- end
185
-
186
- end
187
- end
188
- end
@@ -1,165 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
- #
4
- # An ordered list of tokens.
5
- # The list of tokens makes up a command.
6
- #
7
-
8
- module Gloo
9
- module Core
10
- class Tokens
11
-
12
- attr_reader :cmd, :tokens
13
-
14
- # ---------------------------------------------------------------------
15
- # Constructor
16
- # ---------------------------------------------------------------------
17
-
18
- #
19
- # Set up the tokens.
20
- # The command string is parsed into tokens during creation.
21
- #
22
- def initialize( cmd_string )
23
- @cmd = cmd_string
24
- @tokens = []
25
- tokenize @cmd
26
- end
27
-
28
- # ---------------------------------------------------------------------
29
- # Public functions
30
- # ---------------------------------------------------------------------
31
-
32
- #
33
- # Get the number of tokens
34
- #
35
- def token_count
36
- return @tokens.size
37
- end
38
-
39
- #
40
- # Get the verb (the first word)
41
- #
42
- def verb
43
- return first
44
- end
45
-
46
- #
47
- # Get all tokens except the first.
48
- #
49
- def params
50
- return @tokens[ 1..-1 ]
51
- end
52
-
53
- #
54
- # Get the first token.
55
- #
56
- def first
57
- return @tokens.first if @tokens
58
- end
59
-
60
- #
61
- # Get the last token.
62
- #
63
- def last
64
- return @tokens.last if @tokens
65
- end
66
-
67
- #
68
- # Get the second token.
69
- #
70
- def second
71
- return @tokens[ 1 ] if @tokens&.size&.positive?
72
- end
73
-
74
- #
75
- # Get the token at the the requested index.
76
- #
77
- def at( index )
78
- return @tokens[ index ] if @tokens && @tokens.size >= index
79
- end
80
-
81
- #
82
- # Get the index of the given token.
83
- #
84
- def index_of( token )
85
- return nil unless @tokens
86
-
87
- return @tokens.find_index { |o| o.casecmp( token ).zero? }
88
- end
89
-
90
- #
91
- # Get the list of tokens after the given token
92
- #
93
- def tokens_after( token )
94
- i = index_of token
95
- return @tokens[ i + 1..-1 ] if i && @tokens && @tokens.size > ( i + 1 )
96
-
97
- return nil
98
- end
99
-
100
- #
101
- # Get the expression after the given token
102
- #
103
- def expr_after( token )
104
- str = ''
105
- tokens_after( token ).each do |t|
106
- str << ' ' unless str.empty?
107
- str << t.to_s
108
- end
109
- return str
110
- end
111
-
112
- #
113
- # Get the item after a given token.
114
- #
115
- def after_token( token )
116
- i = index_of token
117
- return @tokens[ i + 1 ] if i && @tokens && @tokens.size > ( i + 1 )
118
-
119
- return nil
120
- end
121
-
122
- #
123
- # Get the item after a given token.
124
- #
125
- def before_token( token )
126
- i = index_of token
127
- return @tokens[ 0..i - 1 ] if i && @tokens && @tokens.size >= i
128
-
129
- return nil
130
- end
131
-
132
- # ---------------------------------------------------------------------
133
- # Private functions
134
- # ---------------------------------------------------------------------
135
-
136
- private
137
-
138
- #
139
- # Create a list of token from the given string.
140
- #
141
- def tokenize( str )
142
- if str.index( '"' )
143
- i = str.index( '"' )
144
- j = str.index( '"', i + 1 )
145
- j ||= str.length
146
-
147
- tokenize( str[ 0..i - 1 ] ) if i > 1
148
- @tokens << str[ i..j ]
149
- tokenize( str[ j + 1..-1 ] ) if j + 1 < str.length
150
- elsif str.index( "'" )
151
- i = str.index( "'" )
152
- j = str.index( "'", i + 1 )
153
- j ||= str.length
154
-
155
- tokenize( str[ 0..i - 1 ] ) if i > 1
156
- @tokens << str[ i..j ]
157
- tokenize( str[ j + 1..-1 ] ) if j + 1 < str.length
158
- else
159
- str.strip.split( ' ' ).each { |t| @tokens << t }
160
- end
161
- end
162
-
163
- end
164
- end
165
- end
@@ -1,86 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
- #
4
- # An abstract base verb.
5
- # Derives from the Baseo object.
6
- # It is a special type of object in that it can be run
7
- # and can perform an action.
8
- #
9
-
10
- module Gloo
11
- module Core
12
- class Verb < Baseo
13
-
14
- attr_reader :tokens, :params
15
-
16
- #
17
- # Set up the verb.
18
- #
19
- def initialize( tokens, params = [] )
20
- @tokens = tokens
21
- @params = params
22
- end
23
-
24
- #
25
- # Register verbs when they are loaded.
26
- #
27
- def self.inherited( subclass )
28
- Dictionary.instance.register_verb( subclass )
29
- end
30
-
31
- #
32
- # Run the verb.
33
- #
34
- # We'll mark the application as not running and let the
35
- # engine stop gracefully next time through the loop.
36
- #
37
- def run
38
- raise 'this method should be overriden'
39
- end
40
-
41
- #
42
- # Get the Verb's keyword.
43
- #
44
- # The keyword will be in lower case only.
45
- # It is used by the parser.
46
- #
47
- def self.keyword
48
- raise 'this method should be overriden'
49
- end
50
-
51
- #
52
- # Get the Verb's keyword shortcut.
53
- #
54
- def self.keyword_shortcut
55
- raise 'this method should be overriden'
56
- end
57
-
58
- #
59
- # The object type, suitable for display.
60
- #
61
- def type_display
62
- return self.class.keyword
63
- end
64
-
65
- #
66
- # Generic function to get display value.
67
- # Can be used for debugging, etc.
68
- #
69
- def display_value
70
- return self.class.keyword
71
- end
72
-
73
- # ---------------------------------------------------------------------
74
- # Help
75
- # ---------------------------------------------------------------------
76
-
77
- #
78
- # Get help for this verb.
79
- #
80
- def self.help
81
- return 'No help found.'
82
- end
83
-
84
- end
85
- end
86
- end
@@ -1,48 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
- #
4
- # An action is a message sent to an object with optional parameters.
5
- #
6
-
7
- module Gloo
8
- module Exec
9
- class Action
10
-
11
- attr_accessor :msg, :to, :params
12
-
13
- #
14
- # Set up the action.
15
- #
16
- def initialize( msg, to, params = nil )
17
- @msg = msg
18
- @to = to
19
- @params = params
20
- end
21
-
22
- #
23
- # The action is valid if the object can receive
24
- # the message specified.
25
- #
26
- def valid?
27
- return @to.can_receive_message?( @msg )
28
- end
29
-
30
- #
31
- # Execute the action.
32
- # Dispatch the message to the object.
33
- #
34
- def dispatch
35
- @to.send_message @msg, @params
36
- end
37
-
38
- #
39
- # Generic function to get display value.
40
- # Can be used for debugging, etc.
41
- #
42
- def display_value
43
- return "#{@msg} -> #{@to.pn}"
44
- end
45
-
46
- end
47
- end
48
- end
@@ -1,40 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
- #
4
- # Central Message Dispatch.
5
- # Responsible for sending message to objects.
6
- # All object messaging goes through here so we can uniformly
7
- # manage things like checking to make sure object can
8
- # receive the messages sent, handling errors, etc.
9
- #
10
-
11
- module Gloo
12
- module Exec
13
- class Dispatch
14
-
15
- #
16
- # Dispatch the given message to the given object.
17
- #
18
- def self.message( msg, to_obj, params = nil )
19
- $log.debug "Dispatch message #{msg} to #{to_obj.name}"
20
- a = Gloo::Exec::Action.new msg, to_obj, params
21
- Gloo::Exec::Dispatch.action a
22
- end
23
-
24
- #
25
- # Dispatch an action.
26
- #
27
- def self.action( action )
28
- unless action.valid?
29
- $log.warn "Object #{action.to.name} does not respond to #{action.msg}"
30
- end
31
-
32
- $engine.exec_env.push_action action
33
- $log.debug "Sending message #{action.msg} to #{action.to.name}"
34
- action.dispatch
35
- $engine.exec_env.pop_action
36
- end
37
-
38
- end
39
- end
40
- end