gloo 1.4.2 → 2.0.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 (131) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.gitignore +1 -0
  4. data/gloo.gemspec +0 -2
  5. data/lib/VERSION +1 -1
  6. data/lib/dependencies.rb +4 -4
  7. data/lib/gloo/app/args.rb +112 -0
  8. data/lib/gloo/app/engine.rb +247 -0
  9. data/lib/gloo/app/engine_context.rb +25 -0
  10. data/lib/gloo/app/info.rb +20 -3
  11. data/lib/gloo/app/log.rb +73 -1
  12. data/lib/gloo/app/mode.rb +27 -0
  13. data/lib/gloo/app/platform.rb +8 -1
  14. data/lib/gloo/app/settings.rb +202 -0
  15. data/lib/gloo/convert/converter.rb +42 -0
  16. data/lib/gloo/convert/string_to_date.rb +21 -0
  17. data/lib/gloo/convert/string_to_datetime.rb +21 -0
  18. data/lib/gloo/convert/string_to_decimal.rb +20 -0
  19. data/lib/gloo/convert/string_to_integer.rb +20 -0
  20. data/lib/gloo/convert/string_to_time.rb +21 -0
  21. data/lib/gloo/core/baseo.rb +31 -0
  22. data/lib/gloo/core/dictionary.rb +245 -0
  23. data/lib/gloo/core/error.rb +61 -0
  24. data/lib/gloo/core/event_manager.rb +45 -0
  25. data/lib/gloo/core/factory.rb +211 -0
  26. data/lib/gloo/core/gloo_system.rb +267 -0
  27. data/lib/gloo/core/heap.rb +53 -0
  28. data/lib/gloo/core/here.rb +36 -0
  29. data/lib/gloo/core/it.rb +36 -0
  30. data/lib/gloo/core/literal.rb +30 -0
  31. data/lib/gloo/core/obj.rb +318 -0
  32. data/lib/gloo/core/obj_finder.rb +30 -0
  33. data/lib/gloo/core/op.rb +40 -0
  34. data/lib/gloo/core/parser.rb +60 -0
  35. data/lib/gloo/core/pn.rb +212 -0
  36. data/lib/gloo/core/tokens.rb +165 -0
  37. data/lib/gloo/core/verb.rb +87 -0
  38. data/lib/gloo/exec/action.rb +48 -0
  39. data/lib/gloo/exec/dispatch.rb +40 -0
  40. data/lib/gloo/exec/exec_env.rb +75 -0
  41. data/lib/gloo/exec/runner.rb +45 -0
  42. data/lib/gloo/exec/script.rb +50 -0
  43. data/lib/gloo/exec/stack.rb +79 -0
  44. data/lib/gloo/expr/expression.rb +119 -0
  45. data/lib/gloo/expr/l_boolean.rb +36 -0
  46. data/lib/gloo/expr/l_decimal.rb +39 -0
  47. data/lib/gloo/expr/l_integer.rb +37 -0
  48. data/lib/gloo/expr/l_string.rb +58 -0
  49. data/lib/gloo/expr/op_div.rb +22 -0
  50. data/lib/gloo/expr/op_minus.rb +22 -0
  51. data/lib/gloo/expr/op_mult.rb +22 -0
  52. data/lib/gloo/expr/op_plus.rb +24 -0
  53. data/lib/gloo/objs/basic/alias.rb +78 -0
  54. data/lib/gloo/objs/basic/boolean.rb +120 -0
  55. data/lib/gloo/objs/basic/container.rb +65 -0
  56. data/lib/gloo/objs/basic/decimal.rb +76 -0
  57. data/lib/gloo/objs/basic/integer.rb +73 -0
  58. data/lib/gloo/objs/basic/script.rb +99 -0
  59. data/lib/gloo/objs/basic/string.rb +77 -0
  60. data/lib/gloo/objs/basic/text.rb +79 -0
  61. data/lib/gloo/objs/basic/untyped.rb +41 -0
  62. data/lib/gloo/objs/cli/banner.rb +1 -1
  63. data/lib/gloo/objs/cli/bar.rb +3 -3
  64. data/lib/gloo/objs/cli/colorize.rb +1 -1
  65. data/lib/gloo/objs/cli/confirm.rb +1 -1
  66. data/lib/gloo/objs/cli/menu.rb +6 -6
  67. data/lib/gloo/objs/cli/menu_item.rb +1 -1
  68. data/lib/gloo/objs/cli/pastel.rb +1 -1
  69. data/lib/gloo/objs/cli/prompt.rb +1 -1
  70. data/lib/gloo/objs/cli/select.rb +2 -2
  71. data/lib/gloo/objs/ctrl/each.rb +279 -0
  72. data/lib/gloo/objs/ctrl/repeat.rb +108 -0
  73. data/lib/gloo/objs/data/markdown.rb +79 -0
  74. data/lib/gloo/objs/data/mysql.rb +5 -5
  75. data/lib/gloo/objs/data/query.rb +4 -4
  76. data/lib/gloo/objs/data/sqlite.rb +1 -1
  77. data/lib/gloo/objs/data/table.rb +112 -0
  78. data/lib/gloo/objs/dev/git.rb +2 -2
  79. data/lib/gloo/objs/dev/stats.rb +4 -4
  80. data/lib/gloo/objs/dt/date.rb +65 -0
  81. data/lib/gloo/objs/dt/datetime.rb +120 -0
  82. data/lib/gloo/objs/dt/dt_tools.rb +100 -0
  83. data/lib/gloo/objs/dt/time.rb +65 -0
  84. data/lib/gloo/objs/ror/erb.rb +116 -0
  85. data/lib/gloo/objs/ror/eval.rb +107 -0
  86. data/lib/gloo/objs/snd/play.rb +1 -1
  87. data/lib/gloo/objs/snd/say.rb +1 -1
  88. data/lib/gloo/objs/system/file_handle.rb +4 -4
  89. data/lib/gloo/objs/system/ssh_exec.rb +1 -1
  90. data/lib/gloo/objs/system/system.rb +1 -1
  91. data/lib/gloo/objs/web/http_get.rb +159 -0
  92. data/lib/gloo/objs/web/http_post.rb +183 -0
  93. data/lib/gloo/objs/web/json.rb +135 -0
  94. data/lib/gloo/objs/web/slack.rb +130 -0
  95. data/lib/gloo/objs/web/teams.rb +117 -0
  96. data/lib/gloo/objs/web/uri.rb +148 -0
  97. data/lib/gloo/persist/disc_mech.rb +87 -0
  98. data/lib/gloo/persist/file_loader.rb +193 -0
  99. data/lib/gloo/persist/file_saver.rb +51 -0
  100. data/lib/gloo/persist/file_storage.rb +46 -0
  101. data/lib/gloo/persist/line_splitter.rb +81 -0
  102. data/lib/gloo/persist/persist_man.rb +153 -0
  103. data/lib/gloo/utils/format.rb +21 -0
  104. data/lib/gloo/utils/stats.rb +206 -0
  105. data/lib/gloo/utils/words.rb +19 -0
  106. data/lib/gloo/verbs/alert.rb +2 -2
  107. data/lib/gloo/verbs/beep.rb +1 -1
  108. data/lib/gloo/verbs/cls.rb +1 -1
  109. data/lib/gloo/verbs/context.rb +62 -0
  110. data/lib/gloo/verbs/create.rb +68 -0
  111. data/lib/gloo/verbs/execute.rb +56 -0
  112. data/lib/gloo/verbs/files.rb +49 -0
  113. data/lib/gloo/verbs/help.rb +1 -1
  114. data/lib/gloo/verbs/if.rb +92 -0
  115. data/lib/gloo/verbs/list.rb +98 -0
  116. data/lib/gloo/verbs/load.rb +45 -0
  117. data/lib/gloo/verbs/move.rb +89 -0
  118. data/lib/gloo/verbs/put.rb +94 -0
  119. data/lib/gloo/verbs/quit.rb +40 -0
  120. data/lib/gloo/verbs/reload.rb +43 -0
  121. data/lib/gloo/verbs/run.rb +75 -0
  122. data/lib/gloo/verbs/save.rb +39 -0
  123. data/lib/gloo/verbs/show.rb +63 -0
  124. data/lib/gloo/verbs/tell.rb +80 -0
  125. data/lib/gloo/verbs/unless.rb +92 -0
  126. data/lib/gloo/verbs/unload.rb +46 -0
  127. data/lib/gloo/verbs/version.rb +3 -3
  128. data/lib/gloo/verbs/wait.rb +42 -0
  129. data/lib/gloo.rb +2 -2
  130. data/lib/run.rb +2 -2
  131. metadata +97 -22
@@ -0,0 +1,202 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Application and user settings.
5
+ #
6
+
7
+ require 'yaml'
8
+
9
+ module Gloo
10
+ module App
11
+ class Settings
12
+
13
+ attr_reader :user_root, :log_path,
14
+ :config_path, :project_path,
15
+ :start_with, :list_indent, :tmp_path,
16
+ :debug_path, :debug
17
+
18
+ #
19
+ # Load setting from the yml file.
20
+ # The mode parameter is used to determine if we are running in TEST.
21
+ #
22
+ def initialize( engine, root=nil )
23
+ @engine = engine
24
+ # @mode = mode
25
+ init_root( root )
26
+
27
+ init_path_settings
28
+ init_user_settings
29
+ end
30
+
31
+ #
32
+ # Show the current application settings.
33
+ # Can be seen in app with 'help settings'
34
+ #
35
+ def show
36
+ puts "\nApplication Settings:"
37
+ puts ' Startup with: ' + @start_with
38
+ puts ' Indent in Listing: ' + @list_indent.to_s
39
+ puts ' Screen Lines: ' + Gloo::App::Settings.lines( @engine ).to_s
40
+ puts ' Page Size: ' + Gloo::App::Settings.page_size( @engine ).to_s
41
+ puts ''
42
+ self.show_paths
43
+ puts ''
44
+ end
45
+
46
+ #
47
+ # Show path settings
48
+ #
49
+ def show_paths
50
+ puts ' User Root Path is here: ' + @user_root
51
+ puts ' Projects Path: ' + @project_path
52
+ puts ' Tmp Path: ' + @tmp_path
53
+ puts ' Debug Path: ' + @debug_path
54
+ end
55
+
56
+ # #
57
+ # # Show the current application settings.
58
+ # # Can be seen in app with 'help settings'
59
+ # #
60
+ # def show
61
+ # puts "\nApplication Settings:".blue
62
+ # puts ' Startup with: '.yellow + @start_with.white
63
+ # puts ' Indent in Listing: '.yellow + @list_indent.to_s.white
64
+ # puts ' Screen Lines: '.yellow + Gloo::App::Settings.lines.to_s.white
65
+ # puts ' Page Size: '.yellow + Gloo::App::Settings.page_size.to_s.white
66
+ # puts ''
67
+ # self.show_paths
68
+ # puts ''
69
+ # end
70
+ #
71
+ # #
72
+ # # Show path settings
73
+ # #
74
+ # def show_paths
75
+ # puts ' User Root Path is here: '.yellow + @user_root.white
76
+ # puts ' Projects Path: '.yellow + @project_path.white
77
+ # puts ' Tmp Path: '.yellow + @tmp_path.white
78
+ # puts ' Debug Path: '.yellow + @debug_path.white
79
+ # end
80
+
81
+ #
82
+ # Get the number of vertical lines on screen.
83
+ #
84
+ def self.lines engine
85
+ engine.platform.lines
86
+ end
87
+
88
+ #
89
+ # Get the number of horizontal columns on screen.
90
+ #
91
+ def self.cols engine
92
+ engine.platform.cols
93
+ end
94
+
95
+ #
96
+ # Get the default page size.
97
+ # This is the number of lines of text we can show.
98
+ #
99
+ def self.page_size engine
100
+ Settings.lines( engine ) - 3
101
+ end
102
+
103
+ #
104
+ # How many lines should we use for a preview?
105
+ #
106
+ def self.preview_lines
107
+ return 7
108
+ end
109
+
110
+ # ---------------------------------------------------------------------
111
+ # Private
112
+ # ---------------------------------------------------------------------
113
+
114
+ private
115
+
116
+ #
117
+ # Initialize gloo's root path.
118
+ #
119
+ def init_root root
120
+ if root
121
+ @user_root = root
122
+ # if in_test_mode?
123
+ # path = File.dirname( File.dirname( File.absolute_path( __FILE__ ) ) )
124
+ # path = File.dirname( File.dirname( path ) )
125
+ # path = File.join( path, 'test', 'gloo' )
126
+ # @user_root = path
127
+ else
128
+ @user_root = File.join( Dir.home, 'gloo' )
129
+ end
130
+ end
131
+
132
+ #
133
+ # Get the app's required directories.
134
+ #
135
+ def init_path_settings
136
+ Dir.mkdir( @user_root ) unless File.exist?( @user_root )
137
+
138
+ @log_path = File.join( @user_root, 'logs' )
139
+ Dir.mkdir( @log_path ) unless File.exist?( @log_path )
140
+
141
+ @config_path = File.join( @user_root, 'config' )
142
+ Dir.mkdir( @config_path ) unless File.exist?( @config_path )
143
+
144
+ @tmp_path = File.join( @user_root, 'tmp' )
145
+ Dir.mkdir( @tmp_path ) unless File.exist?( @tmp_path )
146
+
147
+ @debug_path = File.join( @user_root, 'debug' )
148
+ Dir.mkdir( @debug_path ) unless File.exist?( @debug_path )
149
+ end
150
+
151
+ #
152
+ # Initialize the user settings for the currently
153
+ # running environment.
154
+ #
155
+ def init_user_settings
156
+ settings = get_settings
157
+
158
+ @project_path = settings[ 'gloo' ][ 'project_path' ]
159
+ if @project_path.blank?
160
+ @project_path = File.join( @user_root, 'projects' )
161
+ end
162
+
163
+ @start_with = settings[ 'gloo' ][ 'start_with' ]
164
+ @list_indent = settings[ 'gloo' ][ 'list_indent' ]
165
+
166
+ @debug = settings[ 'gloo' ][ 'debug' ]
167
+ end
168
+
169
+ #
170
+ # Get the app's required directories.
171
+ #
172
+ def get_settings
173
+ f = File.join( @config_path, 'gloo.yml' )
174
+ create_settings( f ) unless File.exist?( f )
175
+ return YAML.load_file f
176
+ end
177
+
178
+ #
179
+ # Create settings file.
180
+ #
181
+ def create_settings( file )
182
+ IO.write( file, get_default_settings )
183
+ end
184
+
185
+ #
186
+ # Get the value for default settings.
187
+ #
188
+ def get_default_settings
189
+ projects = File.join( @user_root, 'projects' )
190
+ str = <<~TEXT
191
+ gloo:
192
+ project_path: #{projects}
193
+ start_with:
194
+ list_indent: 1
195
+ debug: false
196
+ TEXT
197
+ return str
198
+ end
199
+
200
+ end
201
+ end
202
+ end
@@ -0,0 +1,42 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Data conversion manager.
5
+ #
6
+
7
+ module Gloo
8
+ module Convert
9
+ class Converter
10
+
11
+ #
12
+ # Initializer.
13
+ #
14
+ def initialize( engine )
15
+ @engine = engine
16
+ end
17
+
18
+ # ---------------------------------------------------------------------
19
+ # Convert
20
+ # ---------------------------------------------------------------------
21
+
22
+ #
23
+ # Convert the given value to the specified type,
24
+ # or if no conversion is available, revert to default.
25
+ #
26
+ def convert( value, to_type, default = nil )
27
+ begin
28
+ name = "Gloo::Convert::#{value.class}To#{to_type}"
29
+ clazz = name.split( '::' ).inject( Object ) { |o, c| o.const_get c }
30
+ o = clazz.new
31
+ return o.convert( value )
32
+ rescue => e
33
+ @engine.log.error e.message
34
+ @engine.heap.error.set_to e.message
35
+ end
36
+
37
+ return default
38
+ end
39
+
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,21 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2023 Eric Crane. All rights reserved.
3
+ #
4
+ # Conversion tool: String to Date.
5
+ #
6
+ require 'chronic'
7
+
8
+ module Gloo
9
+ module Convert
10
+ class StringToDate
11
+
12
+ #
13
+ # Convert the given string value to date.
14
+ #
15
+ def convert( value )
16
+ return Chronic.parse( value )
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Conversion tool: String to Date Time.
5
+ #
6
+ require 'chronic'
7
+
8
+ module Gloo
9
+ module Convert
10
+ class StringToDateTime
11
+
12
+ #
13
+ # Convert the given string value to a date and time.
14
+ #
15
+ def convert( value )
16
+ return Chronic.parse( value )
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Conversion tool: String to Decimal.
5
+ #
6
+
7
+ module Gloo
8
+ module Convert
9
+ class StringToDecimal
10
+
11
+ #
12
+ # Convert the given string value to an integer.
13
+ #
14
+ def convert( value )
15
+ return value.to_f
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Conversion tool: String to Integer.
5
+ #
6
+
7
+ module Gloo
8
+ module Convert
9
+ class StringToInteger
10
+
11
+ #
12
+ # Convert the given string value to an integer.
13
+ #
14
+ def convert( value )
15
+ return value.to_i
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2023 Eric Crane. All rights reserved.
3
+ #
4
+ # Conversion tool: String to Time.
5
+ #
6
+ require 'chronic'
7
+
8
+ module Gloo
9
+ module Convert
10
+ class StringToTime
11
+
12
+ #
13
+ # Convert the given string value to time.
14
+ #
15
+ def convert( value )
16
+ return Chronic.parse( value )
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An abstract base object.
5
+ # All objects and verbs derive from this.
6
+ #
7
+
8
+ module Gloo
9
+ module Core
10
+ class Baseo
11
+
12
+ attr_accessor :name
13
+
14
+ NOT_IMPLEMENTED_ERR = 'Not implemented yet!'.freeze
15
+
16
+ # Set up the object.
17
+ def initialize( engine )
18
+ @engine = engine
19
+ @name = ''
20
+ end
21
+
22
+ #
23
+ # The object type, suitable for display.
24
+ #
25
+ def type_display
26
+ raise 'this method should be overriden'
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,245 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # A dictionary of Objects and Verbs.
5
+ #
6
+ require 'singleton'
7
+
8
+ module Gloo
9
+ module Core
10
+ class Dictionary
11
+
12
+ include Singleton
13
+
14
+ attr_reader :verbs, :objs, :keywords
15
+
16
+ #
17
+ # Set up the object dictionary.
18
+ #
19
+ def initialize
20
+ @verbs = {}
21
+ @objs = {}
22
+ @verb_references = []
23
+ @obj_references = []
24
+ @keywords = []
25
+ end
26
+
27
+ #
28
+ # Get the singleton Dictionary and Initialize
29
+ # if this is the first time.
30
+ #
31
+ def self.get
32
+ o = Gloo::Core::Dictionary.instance
33
+ o.init if o.verbs.count == 0
34
+ return o
35
+ end
36
+
37
+ #
38
+ # Register a verb.
39
+ #
40
+ def register_verb( subclass )
41
+ @verb_references << subclass
42
+ end
43
+
44
+ #
45
+ # Register an object type.
46
+ #
47
+ def register_obj( subclass )
48
+ @obj_references << subclass
49
+ end
50
+
51
+ #
52
+ # Initialize verbs and objects in the dictionary.
53
+ #
54
+ def init
55
+ # @engine.log.debug 'initializing dictionaries'
56
+ init_verbs
57
+ init_objs
58
+ end
59
+
60
+ #
61
+ # Is the given word an object type?
62
+ #
63
+ def obj?( word )
64
+ return false unless word
65
+
66
+ return @objs.key?( word.downcase )
67
+ end
68
+
69
+ #
70
+ # Find the object type by name.
71
+ #
72
+ def find_obj( word )
73
+ return nil unless word
74
+ return nil unless obj?( word )
75
+
76
+ return @objs[ word.downcase ]
77
+ end
78
+
79
+ #
80
+ # Is the given word a verb?
81
+ #
82
+ def verb?( word )
83
+ return false unless word
84
+
85
+ return @verbs.key?( word.downcase )
86
+ end
87
+
88
+ #
89
+ # Find the verb by name.
90
+ #
91
+ def find_verb( verb )
92
+ return nil unless verb
93
+ return nil unless verb?( verb )
94
+
95
+ return @verbs[ verb.downcase ]
96
+ end
97
+
98
+ #
99
+ # Get the list of verbs, sorted.
100
+ #
101
+ def get_obj_types
102
+ return @obj_references.sort { |a, b| a.typename <=> b.typename }
103
+ end
104
+
105
+ #
106
+ # Get the list of verbs, sorted.
107
+ #
108
+ def get_verbs
109
+ return @verb_references.sort { |a, b| a.keyword <=> b.keyword }
110
+ end
111
+
112
+ #
113
+ # Lookup the keyword by name or shortcut.
114
+ # Return the keyword (name) or nil if it is not found.
115
+ #
116
+ def lookup_keyword( key )
117
+ v = find_verb key
118
+ return v.keyword if v
119
+
120
+ o = find_obj key
121
+ return o.typename if o
122
+
123
+ return nil
124
+ end
125
+
126
+ #
127
+ # Show a list of all keywords.
128
+ # This includes verbs and objects, names and shortcuts.
129
+ #
130
+ def show_keywords
131
+ str = ''
132
+ @keywords.sort.each_with_index do |k, i|
133
+ str << k.ljust( 20, ' ' )
134
+ if ( ( i + 1 ) % 6 ).zero?
135
+ puts str
136
+ str = ''
137
+ end
138
+ end
139
+ end
140
+
141
+ # ---------------------------------------------------------------------
142
+ # Register after start up
143
+ # ---------------------------------------------------------------------
144
+
145
+ #
146
+ # Register a verb after start up.
147
+ #
148
+ def register_verb_post_start( verb_class )
149
+ add_verb verb_class
150
+ end
151
+
152
+ #
153
+ # Register an object type after start up.
154
+ #
155
+ def register_obj_post_start( obj_class )
156
+ add_object obj_class
157
+ end
158
+
159
+ #
160
+ # Un-Register a verb.
161
+ #
162
+ def unregister_verb( verb_class )
163
+ @verbs.delete( verb_class.keyword )
164
+ @verbs.delete( verb_class.keyword_shortcut )
165
+
166
+ @keywords.delete( verb_class.keyword )
167
+ @keywords.delete( verb_class.keyword_shortcut )
168
+ end
169
+
170
+ #
171
+ # Un-Register an object.
172
+ #
173
+ def unregister_obj( obj_class )
174
+ @objs.delete( obj_class.typename )
175
+ @objs.delete( obj_class.short_typename )
176
+
177
+ @keywords.delete( obj_class.typename )
178
+ @keywords.delete( obj_class.short_typename )
179
+ end
180
+
181
+ # ---------------------------------------------------------------------
182
+ # Private
183
+ # ---------------------------------------------------------------------
184
+
185
+ private
186
+
187
+ #
188
+ # Add a keyword to the keyword list.
189
+ # Report an error if the keyword is already in the list.
190
+ #
191
+ def add_key( keyword )
192
+ if @keywords.include?( keyword )
193
+ # @engine.log.error "duplicate keyword '#{keyword}'"
194
+ return
195
+ end
196
+
197
+ @keywords << keyword
198
+ end
199
+
200
+ #
201
+ # Init the list of objects.
202
+ #
203
+ def init_objs
204
+ # @engine.log.debug "initializing #{@obj_references.count} objects"
205
+ @obj_references.each do |o|
206
+ add_object o
207
+ end
208
+ end
209
+
210
+ #
211
+ # Init the list of verbs.
212
+ #
213
+ def init_verbs
214
+ # @engine.log.debug "initializing #{@verb_references.count} verbs"
215
+ @verb_references.each do |v|
216
+ add_verb v
217
+ end
218
+ end
219
+
220
+ #
221
+ # Add an object to the dictionary
222
+ #
223
+ def add_object o
224
+ # @engine.log.debug o
225
+ @objs[ o.typename ] = o
226
+ @objs[ o.short_typename ] = o
227
+ add_key o.typename
228
+ add_key o.short_typename if o.typename != o.short_typename
229
+ end
230
+
231
+ #
232
+ # Add a verb to the dictionary
233
+ #
234
+ def add_verb v
235
+ # @engine.log.debug v
236
+ @verbs[ v.keyword ] = v
237
+ @verbs[ v.keyword_shortcut ] = v
238
+ # v.send( :new ).run
239
+ add_key v.keyword
240
+ add_key v.keyword_shortcut if v.keyword != v.keyword_shortcut
241
+ end
242
+
243
+ end
244
+ end
245
+ end
@@ -0,0 +1,61 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # If the last command to run generated an error it will be here.
5
+ #
6
+
7
+ module Gloo
8
+ module Core
9
+ class Error
10
+
11
+ attr_accessor :value, :error_count
12
+
13
+ #
14
+ # Set up the error object.
15
+ #
16
+ def initialize
17
+ clear
18
+ end
19
+
20
+ #
21
+ # Clear out the error message.
22
+ #
23
+ def clear
24
+ @error_count = 0
25
+ @value = nil
26
+ end
27
+
28
+ #
29
+ # Set the value of error.
30
+ #
31
+ def set_to( new_value )
32
+ @error_count += 1
33
+ @value = new_value
34
+ end
35
+
36
+ #
37
+ # Start counting errors.
38
+ # We're looking to see if we get any new ones during
39
+ # a script or an immediate command.
40
+ #
41
+ def start_tracking
42
+ @error_count = 0
43
+ end
44
+
45
+ #
46
+ # Clear out error if we didn't add any new ones.
47
+ #
48
+ def clear_if_no_errors
49
+ self.clear if @error_count.zero?
50
+ end
51
+
52
+ #
53
+ # Get the string representation of the error.
54
+ #
55
+ def to_s
56
+ return @value.to_s
57
+ end
58
+
59
+ end
60
+ end
61
+ end