gloo 0.5.4 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/lib/gloo/app/args.rb +48 -6
- data/lib/gloo/app/engine.rb +60 -38
- data/lib/gloo/app/help.rb +137 -16
- data/lib/gloo/app/info.rb +3 -1
- data/lib/gloo/app/log.rb +23 -0
- data/lib/gloo/app/mode.rb +2 -0
- data/lib/gloo/app/settings.rb +98 -47
- data/lib/gloo/convert/converter.rb +35 -0
- data/lib/gloo/convert/string_to_datetime.rb +1 -1
- data/lib/gloo/convert/string_to_decimal.rb +1 -1
- data/lib/gloo/convert/string_to_integer.rb +1 -1
- data/lib/gloo/core/dictionary.rb +99 -22
- data/lib/gloo/core/error.rb +19 -8
- data/lib/gloo/core/event_manager.rb +4 -0
- data/lib/gloo/core/factory.rb +11 -0
- data/lib/gloo/core/gloo_system.rb +1 -1
- data/lib/gloo/core/heap.rb +11 -3
- data/lib/gloo/core/here.rb +36 -0
- data/lib/gloo/core/it.rb +6 -0
- data/lib/gloo/core/literal.rb +5 -0
- data/lib/gloo/core/obj.rb +22 -0
- data/lib/gloo/core/op.rb +7 -0
- data/lib/gloo/core/parser.rb +6 -0
- data/lib/gloo/core/pn.rb +38 -0
- data/lib/gloo/core/tokens.rb +66 -22
- data/lib/gloo/core/verb.rb +12 -0
- data/lib/gloo/exec/action.rb +48 -0
- data/lib/gloo/exec/dispatch.rb +15 -5
- data/lib/gloo/exec/exec_env.rb +74 -0
- data/lib/gloo/exec/runner.rb +4 -2
- data/lib/gloo/{core → exec}/script.rb +21 -9
- data/lib/gloo/exec/stack.rb +78 -0
- data/lib/gloo/expr/expression.rb +26 -4
- data/lib/gloo/expr/l_boolean.rb +6 -0
- data/lib/gloo/expr/l_decimal.rb +5 -0
- data/lib/gloo/expr/l_integer.rb +7 -0
- data/lib/gloo/expr/l_string.rb +7 -0
- data/lib/gloo/expr/op_div.rb +2 -0
- data/lib/gloo/expr/op_minus.rb +2 -0
- data/lib/gloo/expr/op_mult.rb +2 -0
- data/lib/gloo/expr/op_plus.rb +2 -0
- data/lib/gloo/help/app/application.txt +22 -0
- data/lib/gloo/help/app/configuration.txt +7 -0
- data/lib/gloo/help/app/default_help.txt +14 -0
- data/lib/gloo/help/app/logging.txt +16 -0
- data/lib/gloo/help/core/color.txt +31 -0
- data/lib/gloo/help/core/error.txt +33 -0
- data/lib/gloo/help/core/events.txt +21 -0
- data/lib/gloo/help/core/gloo_system.txt +54 -0
- data/lib/gloo/help/core/here.txt +30 -0
- data/lib/gloo/help/core/it.txt +23 -0
- data/lib/gloo/help/core/ops.txt +16 -0
- data/lib/gloo/help/core/pathname.txt +29 -0
- data/lib/gloo/help/objs/basic/alias.txt +36 -0
- data/lib/gloo/help/objs/basic/boolean.txt +28 -0
- data/lib/gloo/help/objs/basic/container.txt +33 -0
- data/lib/gloo/help/objs/basic/decimal.txt +28 -0
- data/lib/gloo/help/objs/basic/integer.txt +27 -0
- data/lib/gloo/help/objs/basic/script.txt +29 -0
- data/lib/gloo/help/objs/basic/string.txt +28 -0
- data/lib/gloo/help/objs/basic/text.txt +27 -0
- data/lib/gloo/help/objs/basic/untyped.txt +22 -0
- data/lib/gloo/help/objs/cli/banner.txt +49 -0
- data/lib/gloo/help/objs/cli/bar.txt +34 -0
- data/lib/gloo/help/objs/cli/colorize.txt +33 -0
- data/lib/gloo/help/objs/cli/confirm.txt +26 -0
- data/lib/gloo/help/objs/cli/menu.txt +44 -0
- data/lib/gloo/help/objs/cli/menu_item.txt +26 -0
- data/lib/gloo/help/objs/cli/pastel.txt +43 -0
- data/lib/gloo/help/objs/cli/prompt.txt +27 -0
- data/lib/gloo/help/objs/cli/select.txt +34 -0
- data/lib/gloo/help/objs/ctrl/each.txt +48 -0
- data/lib/gloo/help/objs/ctrl/repeat.txt +38 -0
- data/lib/gloo/help/objs/data/markdown.txt +25 -0
- data/lib/gloo/help/objs/data/table.txt +46 -0
- data/lib/gloo/help/objs/dev/git_repo.txt +35 -0
- data/lib/gloo/help/objs/dt/date.txt +23 -0
- data/lib/gloo/help/objs/dt/datetime.txt +24 -0
- data/lib/gloo/help/objs/dt/time.txt +23 -0
- data/lib/gloo/help/objs/ror/erb.txt +37 -0
- data/lib/gloo/help/objs/ror/eval.txt +24 -0
- data/lib/gloo/help/objs/snd/play.txt +23 -0
- data/lib/gloo/help/objs/snd/say.txt +28 -0
- data/lib/gloo/help/objs/system/file.txt +41 -0
- data/lib/gloo/help/objs/system/system.txt +32 -0
- data/lib/gloo/help/objs/web/http_get.txt +35 -0
- data/lib/gloo/help/objs/web/http_post.txt +32 -0
- data/lib/gloo/help/objs/web/json.txt +34 -0
- data/lib/gloo/help/objs/web/slack.txt +33 -0
- data/lib/gloo/help/objs/web/teams.txt +30 -0
- data/lib/gloo/help/objs/web/uri.txt +37 -0
- data/lib/gloo/help/verbs/alert.txt +33 -0
- data/lib/gloo/help/verbs/beep.txt +25 -0
- data/lib/gloo/help/verbs/cls.txt +24 -0
- data/lib/gloo/help/verbs/context.txt +43 -0
- data/lib/gloo/help/verbs/create.txt +33 -0
- data/lib/gloo/help/verbs/execute.txt +27 -0
- data/lib/gloo/help/verbs/help.txt +34 -0
- data/lib/gloo/help/verbs/if.txt +37 -0
- data/lib/gloo/help/verbs/list.txt +34 -0
- data/lib/gloo/help/verbs/load.txt +38 -0
- data/lib/gloo/help/verbs/move.txt +42 -0
- data/lib/gloo/help/verbs/put.txt +38 -0
- data/lib/gloo/help/verbs/quit.txt +25 -0
- data/lib/gloo/help/verbs/run.txt +41 -0
- data/lib/gloo/help/verbs/save.txt +26 -0
- data/lib/gloo/help/verbs/show.txt +30 -0
- data/lib/gloo/help/verbs/tell.txt +34 -0
- data/lib/gloo/help/verbs/unless.txt +38 -0
- data/lib/gloo/help/verbs/version.txt +32 -0
- data/lib/gloo/help/verbs/wait.txt +29 -0
- data/lib/gloo/objs/basic/alias.rb +0 -33
- data/lib/gloo/objs/basic/boolean.rb +6 -27
- data/lib/gloo/objs/basic/container.rb +0 -33
- data/lib/gloo/objs/basic/decimal.rb +8 -28
- data/lib/gloo/objs/basic/integer.rb +5 -26
- data/lib/gloo/objs/basic/script.rb +1 -27
- data/lib/gloo/objs/basic/string.rb +6 -26
- data/lib/gloo/objs/basic/text.rb +0 -25
- data/lib/gloo/objs/basic/untyped.rb +0 -26
- data/lib/gloo/objs/cli/banner.rb +0 -29
- data/lib/gloo/objs/cli/bar.rb +0 -29
- data/lib/gloo/objs/cli/colorize.rb +4 -34
- data/lib/gloo/objs/cli/confirm.rb +6 -36
- data/lib/gloo/objs/cli/menu.rb +6 -36
- data/lib/gloo/objs/cli/menu_item.rb +0 -33
- data/lib/gloo/objs/cli/pastel.rb +4 -27
- data/lib/gloo/objs/cli/prompt.rb +4 -28
- data/lib/gloo/objs/cli/select.rb +4 -31
- data/lib/gloo/objs/ctrl/each.rb +33 -33
- data/lib/gloo/objs/ctrl/repeat.rb +8 -29
- data/lib/gloo/objs/data/markdown.rb +0 -25
- data/lib/gloo/objs/data/table.rb +4 -32
- data/lib/gloo/objs/dev/git.rb +12 -30
- data/lib/gloo/objs/dt/date.rb +3 -25
- data/lib/gloo/objs/dt/datetime.rb +4 -26
- data/lib/gloo/objs/dt/time.rb +3 -25
- data/lib/gloo/objs/ror/erb.rb +11 -45
- data/lib/gloo/objs/ror/eval.rb +11 -38
- data/lib/gloo/objs/snd/play.rb +2 -25
- data/lib/gloo/objs/snd/say.rb +9 -31
- data/lib/gloo/objs/system/file_handle.rb +0 -38
- data/lib/gloo/objs/system/system.rb +16 -46
- data/lib/gloo/objs/web/http_get.rb +57 -83
- data/lib/gloo/objs/web/http_post.rb +8 -31
- data/lib/gloo/objs/web/json.rb +11 -31
- data/lib/gloo/objs/web/slack.rb +7 -34
- data/lib/gloo/objs/web/teams.rb +13 -48
- data/lib/gloo/objs/web/uri.rb +0 -29
- data/lib/gloo/persist/file_loader.rb +8 -0
- data/lib/gloo/persist/file_saver.rb +6 -0
- data/lib/gloo/persist/file_storage.rb +2 -0
- data/lib/gloo/persist/line_splitter.rb +2 -0
- data/lib/gloo/persist/persist_man.rb +6 -0
- data/lib/gloo/verbs/alert.rb +30 -44
- data/lib/gloo/verbs/beep.rb +0 -30
- data/lib/gloo/verbs/cls.rb +0 -30
- data/lib/gloo/verbs/context.rb +9 -39
- data/lib/gloo/verbs/create.rb +17 -32
- data/lib/gloo/verbs/execute.rb +52 -0
- data/lib/gloo/verbs/help.rb +151 -115
- data/lib/gloo/verbs/if.rb +46 -44
- data/lib/gloo/verbs/list.rb +36 -54
- data/lib/gloo/verbs/load.rb +8 -37
- data/lib/gloo/verbs/move.rb +12 -51
- data/lib/gloo/verbs/put.rb +28 -52
- data/lib/gloo/verbs/quit.rb +0 -31
- data/lib/gloo/verbs/run.rb +23 -39
- data/lib/gloo/verbs/save.rb +0 -33
- data/lib/gloo/verbs/show.rb +6 -31
- data/lib/gloo/verbs/tell.rb +31 -31
- data/lib/gloo/verbs/unless.rb +47 -46
- data/lib/gloo/verbs/version.rb +0 -30
- data/lib/gloo/verbs/wait.rb +0 -31
- metadata +79 -3
data/lib/gloo/app/info.rb
CHANGED
@@ -8,10 +8,12 @@ module Gloo
|
|
8
8
|
module App
|
9
9
|
class Info
|
10
10
|
|
11
|
-
VERSION = '0.
|
11
|
+
VERSION = '0.7.2'.freeze
|
12
12
|
APP_NAME = 'Gloo'.freeze
|
13
13
|
|
14
|
+
#
|
14
15
|
# Get the application display title.
|
16
|
+
#
|
15
17
|
def self.display_title
|
16
18
|
return "#{APP_NAME}, version #{VERSION}"
|
17
19
|
end
|
data/lib/gloo/app/log.rb
CHANGED
@@ -13,6 +13,11 @@ module Gloo
|
|
13
13
|
|
14
14
|
attr_reader :logger, :quiet
|
15
15
|
|
16
|
+
#
|
17
|
+
# Set up a logger.
|
18
|
+
# If quiet is true, then message are written to the log
|
19
|
+
# but not to the console.
|
20
|
+
#
|
16
21
|
def initialize( quiet )
|
17
22
|
f = File.join( $settings.log_path, 'gloo.log' )
|
18
23
|
@logger = Logger.new( f )
|
@@ -20,25 +25,43 @@ module Gloo
|
|
20
25
|
@quiet = quiet
|
21
26
|
end
|
22
27
|
|
28
|
+
#
|
23
29
|
# Show a message unless we're in quite mode.
|
30
|
+
#
|
24
31
|
def show( msg )
|
25
32
|
puts msg unless @quiet
|
26
33
|
end
|
27
34
|
|
35
|
+
#
|
36
|
+
# Write a debug message to the log.
|
37
|
+
#
|
28
38
|
def debug( msg )
|
29
39
|
@logger.debug msg
|
30
40
|
end
|
31
41
|
|
42
|
+
#
|
43
|
+
# Write an information message to the log.
|
44
|
+
# Also write to the console unless quiet.
|
45
|
+
#
|
32
46
|
def info( msg )
|
33
47
|
@logger.info msg
|
34
48
|
puts msg.blue unless @quiet
|
35
49
|
end
|
36
50
|
|
51
|
+
#
|
52
|
+
# Write a warning message to the log.
|
53
|
+
# Also write to the console unless quiet.
|
54
|
+
#
|
37
55
|
def warn( msg )
|
38
56
|
@logger.warn msg
|
39
57
|
puts msg.yellow unless @quiet
|
40
58
|
end
|
41
59
|
|
60
|
+
#
|
61
|
+
# Write an error message to the log and set the error
|
62
|
+
# in the engine's data heap.
|
63
|
+
# Also write to the console unless quiet.
|
64
|
+
#
|
42
65
|
def error( msg, ex = nil, engine = nil )
|
43
66
|
engine&.heap&.error&.set_to msg
|
44
67
|
@logger.error msg
|
data/lib/gloo/app/mode.rb
CHANGED
data/lib/gloo/app/settings.rb
CHANGED
@@ -14,8 +14,12 @@ module Gloo
|
|
14
14
|
|
15
15
|
attr_reader :user_root, :log_path, :config_path, :project_path
|
16
16
|
attr_reader :start_with, :list_indent, :tmp_path
|
17
|
+
attr_reader :debug_path, :debug
|
17
18
|
|
19
|
+
#
|
18
20
|
# Load setting from the yml file.
|
21
|
+
# The mode parameter is used to determine if we are running in TEST.
|
22
|
+
#
|
19
23
|
def initialize( mode )
|
20
24
|
@mode = mode
|
21
25
|
init_root
|
@@ -23,30 +27,99 @@ module Gloo
|
|
23
27
|
init_user_settings
|
24
28
|
end
|
25
29
|
|
26
|
-
|
27
|
-
if in_test_mode?
|
28
|
-
path = File.dirname( File.dirname( File.absolute_path( __FILE__ ) ) )
|
29
|
-
path = File.dirname( File.dirname( path ) )
|
30
|
-
path = File.join( path, 'test', 'gloo' )
|
31
|
-
@user_root = path
|
32
|
-
else
|
33
|
-
@user_root = File.join( Dir.home, 'gloo' )
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
30
|
+
#
|
37
31
|
# Are we in test mode?
|
32
|
+
#
|
38
33
|
def in_test_mode?
|
39
34
|
return @mode == 'TEST'
|
40
35
|
end
|
41
36
|
|
37
|
+
#
|
42
38
|
# Get the project path for the current mode.
|
39
|
+
#
|
43
40
|
def project_path_for_mode( settings )
|
44
41
|
return File.join( @user_root, 'projects' ) if in_test_mode?
|
45
42
|
|
46
43
|
return settings[ 'gloo' ][ 'project_path' ]
|
47
44
|
end
|
48
45
|
|
46
|
+
#
|
47
|
+
# Show the current application settings.
|
48
|
+
# Can be seen in app with 'help settings'
|
49
|
+
#
|
50
|
+
def show
|
51
|
+
puts "\nApplication Settings:".blue
|
52
|
+
puts ' Startup with: '.yellow + @start_with.white
|
53
|
+
puts ' Indent in Listing: '.yellow + @list_indent.to_s.white
|
54
|
+
puts ' Screen Lines: '.yellow + Gloo::App::Settings.lines.to_s.white
|
55
|
+
puts ' Page Size: '.yellow + Gloo::App::Settings.page_size.to_s.white
|
56
|
+
puts ''
|
57
|
+
self.show_paths
|
58
|
+
puts ''
|
59
|
+
end
|
60
|
+
|
61
|
+
#
|
62
|
+
# Show path settings
|
63
|
+
#
|
64
|
+
def show_paths
|
65
|
+
puts ' User Root Path is here: '.yellow + @user_root.white
|
66
|
+
puts ' Projects Path: '.yellow + @project_path.white
|
67
|
+
puts ' Tmp Path: '.yellow + @tmp_path.white
|
68
|
+
puts ' Debug Path: '.yellow + @debug_path.white
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# Get the number of vertical lines on screen.
|
73
|
+
#
|
74
|
+
def self.lines
|
75
|
+
TTY::Screen.rows
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# Get the number of horizontal columns on screen.
|
80
|
+
#
|
81
|
+
def self.cols
|
82
|
+
TTY::Screen.cols
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
# Get the default page size.
|
87
|
+
# This is the number of lines of text we can show.
|
88
|
+
#
|
89
|
+
def self.page_size
|
90
|
+
Settings.lines - 3
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
# How many lines should we use for a preview?
|
95
|
+
#
|
96
|
+
def self.preview_lines
|
97
|
+
return 7
|
98
|
+
end
|
99
|
+
|
100
|
+
# ---------------------------------------------------------------------
|
101
|
+
# Private
|
102
|
+
# ---------------------------------------------------------------------
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
#
|
107
|
+
# Initialize gloo's root path.
|
108
|
+
#
|
109
|
+
def init_root
|
110
|
+
if in_test_mode?
|
111
|
+
path = File.dirname( File.dirname( File.absolute_path( __FILE__ ) ) )
|
112
|
+
path = File.dirname( File.dirname( path ) )
|
113
|
+
path = File.join( path, 'test', 'gloo' )
|
114
|
+
@user_root = path
|
115
|
+
else
|
116
|
+
@user_root = File.join( Dir.home, 'gloo' )
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
#
|
49
121
|
# Get the app's required directories.
|
122
|
+
#
|
50
123
|
def init_path_settings
|
51
124
|
Dir.mkdir( @user_root ) unless File.exist?( @user_root )
|
52
125
|
|
@@ -58,31 +131,44 @@ module Gloo
|
|
58
131
|
|
59
132
|
@tmp_path = File.join( @user_root, 'tmp' )
|
60
133
|
Dir.mkdir( @tmp_path ) unless File.exist?( @tmp_path )
|
134
|
+
|
135
|
+
@debug_path = File.join( @user_root, 'debug' )
|
136
|
+
Dir.mkdir( @debug_path ) unless File.exist?( @debug_path )
|
61
137
|
end
|
62
138
|
|
139
|
+
#
|
63
140
|
# Initialize the user settings for the currently
|
64
141
|
# running environment.
|
142
|
+
#
|
65
143
|
def init_user_settings
|
66
144
|
settings = get_settings
|
67
145
|
|
68
146
|
@project_path = project_path_for_mode settings
|
69
147
|
@start_with = settings[ 'gloo' ][ 'start_with' ]
|
70
148
|
@list_indent = settings[ 'gloo' ][ 'list_indent' ]
|
149
|
+
|
150
|
+
@debug = settings[ 'gloo' ][ 'debug' ]
|
71
151
|
end
|
72
152
|
|
153
|
+
#
|
73
154
|
# Get the app's required directories.
|
155
|
+
#
|
74
156
|
def get_settings
|
75
157
|
f = File.join( @config_path, 'gloo.yml' )
|
76
158
|
create_settings( f ) unless File.exist?( f )
|
77
159
|
return YAML.load_file f
|
78
160
|
end
|
79
161
|
|
162
|
+
#
|
80
163
|
# Create settings file.
|
164
|
+
#
|
81
165
|
def create_settings( file )
|
82
166
|
IO.write( file, get_default_settings )
|
83
167
|
end
|
84
168
|
|
169
|
+
#
|
85
170
|
# Get the value for default settings.
|
171
|
+
#
|
86
172
|
def get_default_settings
|
87
173
|
projects = File.join( @user_root, 'projects' )
|
88
174
|
str = <<~TEXT
|
@@ -90,46 +176,11 @@ module Gloo
|
|
90
176
|
project_path: #{projects}
|
91
177
|
start_with:
|
92
178
|
list_indent: 1
|
179
|
+
debug: false
|
93
180
|
TEXT
|
94
181
|
return str
|
95
182
|
end
|
96
183
|
|
97
|
-
#
|
98
|
-
# Show the current application settings.
|
99
|
-
# Can be seen in app with 'help settings'
|
100
|
-
#
|
101
|
-
def show
|
102
|
-
puts "\nApplication Settings:".blue
|
103
|
-
puts ' User Root Path is here: '.yellow + @user_root.white
|
104
|
-
puts ' Projects directory: '.yellow + @project_path.white
|
105
|
-
puts ' Tmp directory: '.yellow + @tmp_path.white
|
106
|
-
puts ' Startup with: '.yellow + @start_with.white
|
107
|
-
puts ' Indent in Listing: '.yellow + @list_indent.to_s.white
|
108
|
-
puts ''
|
109
|
-
puts ' Screen Lines: '.yellow + Gloo::App::Settings.lines.to_s.white
|
110
|
-
puts ' Page Size: '.yellow + Gloo::App::Settings.page_size.to_s.white
|
111
|
-
puts ''
|
112
|
-
end
|
113
|
-
|
114
|
-
# Get the number of lines on screen.
|
115
|
-
def self.lines
|
116
|
-
TTY::Screen.rows
|
117
|
-
end
|
118
|
-
|
119
|
-
def self.cols
|
120
|
-
TTY::Screen.cols
|
121
|
-
end
|
122
|
-
|
123
|
-
# Get the default page size.
|
124
|
-
def self.page_size
|
125
|
-
Settings.lines - 3
|
126
|
-
end
|
127
|
-
|
128
|
-
# How many lines should we use for a preview?
|
129
|
-
def self.preview_lines
|
130
|
-
return 7
|
131
|
-
end
|
132
|
-
|
133
184
|
end
|
134
185
|
end
|
135
186
|
end
|
@@ -0,0 +1,35 @@
|
|
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
|
+
# Convert
|
13
|
+
# ---------------------------------------------------------------------
|
14
|
+
|
15
|
+
#
|
16
|
+
# Convert the given value to the specified type,
|
17
|
+
# or if no conversion is available, revert to default.
|
18
|
+
#
|
19
|
+
def convert( value, to_type, default = nil )
|
20
|
+
begin
|
21
|
+
name = "Gloo::Convert::#{value.class}To#{to_type}"
|
22
|
+
clazz = name.split( '::' ).inject( Object ) { |o, c| o.const_get c }
|
23
|
+
o = clazz.new
|
24
|
+
return o.convert( value )
|
25
|
+
rescue => e
|
26
|
+
$log.error e.message
|
27
|
+
$engine.heap.error.set_to e.message
|
28
|
+
end
|
29
|
+
|
30
|
+
return default
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/gloo/core/dictionary.rb
CHANGED
@@ -11,51 +11,54 @@ module Gloo
|
|
11
11
|
|
12
12
|
include Singleton
|
13
13
|
|
14
|
-
attr_reader :verbs, :objs
|
14
|
+
attr_reader :verbs, :objs, :keywords
|
15
15
|
|
16
|
+
#
|
16
17
|
# Set up the object dictionary.
|
18
|
+
#
|
17
19
|
def initialize
|
18
20
|
@verbs = {}
|
19
21
|
@objs = {}
|
20
22
|
@verb_references = []
|
21
23
|
@obj_references = []
|
24
|
+
@keywords = []
|
22
25
|
end
|
23
26
|
|
27
|
+
#
|
24
28
|
# Register a verb.
|
29
|
+
#
|
25
30
|
def register_verb( subclass )
|
26
31
|
@verb_references << subclass
|
27
32
|
end
|
28
33
|
|
34
|
+
#
|
29
35
|
# Register an object type.
|
36
|
+
#
|
30
37
|
def register_obj( subclass )
|
31
38
|
@obj_references << subclass
|
32
39
|
end
|
33
40
|
|
41
|
+
#
|
34
42
|
# Initialize verbs and objects in the dictionary.
|
43
|
+
#
|
35
44
|
def init
|
36
45
|
$log.debug 'initializing dictionaries'
|
37
46
|
init_verbs
|
38
47
|
init_objs
|
39
48
|
end
|
40
49
|
|
41
|
-
#
|
42
|
-
def init_objs
|
43
|
-
$log.debug "initializing #{@obj_references.count} objects"
|
44
|
-
@obj_references.each do |o|
|
45
|
-
$log.debug o
|
46
|
-
@objs[ o.typename ] = o
|
47
|
-
@objs[ o.short_typename ] = o
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
50
|
+
#
|
51
51
|
# Is the given word an object type?
|
52
|
+
#
|
52
53
|
def obj?( word )
|
53
54
|
return false unless word
|
54
55
|
|
55
56
|
return @objs.key?( word.downcase )
|
56
57
|
end
|
57
58
|
|
59
|
+
#
|
58
60
|
# Find the object type by name.
|
61
|
+
#
|
59
62
|
def find_obj( word )
|
60
63
|
return nil unless word
|
61
64
|
return nil unless obj?( word )
|
@@ -63,25 +66,18 @@ module Gloo
|
|
63
66
|
return @objs[ word.downcase ]
|
64
67
|
end
|
65
68
|
|
66
|
-
#
|
67
|
-
def init_verbs
|
68
|
-
$log.debug "initializing #{@verb_references.count} verbs"
|
69
|
-
@verb_references.each do |v|
|
70
|
-
$log.debug v
|
71
|
-
@verbs[ v.keyword ] = v
|
72
|
-
@verbs[ v.keyword_shortcut ] = v
|
73
|
-
# v.send( :new ).run
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
69
|
+
#
|
77
70
|
# Is the given word a verb?
|
71
|
+
#
|
78
72
|
def verb?( word )
|
79
73
|
return false unless word
|
80
74
|
|
81
75
|
return @verbs.key?( word.downcase )
|
82
76
|
end
|
83
77
|
|
78
|
+
#
|
84
79
|
# Find the verb by name.
|
80
|
+
#
|
85
81
|
def find_verb( verb )
|
86
82
|
return nil unless verb
|
87
83
|
return nil unless verb?( verb )
|
@@ -89,16 +85,97 @@ module Gloo
|
|
89
85
|
return @verbs[ verb.downcase ]
|
90
86
|
end
|
91
87
|
|
88
|
+
#
|
92
89
|
# Get the list of verbs, sorted.
|
90
|
+
#
|
93
91
|
def get_obj_types
|
94
92
|
return @obj_references.sort { |a, b| a.typename <=> b.typename }
|
95
93
|
end
|
96
94
|
|
95
|
+
#
|
97
96
|
# Get the list of verbs, sorted.
|
97
|
+
#
|
98
98
|
def get_verbs
|
99
99
|
return @verb_references.sort { |a, b| a.keyword <=> b.keyword }
|
100
100
|
end
|
101
101
|
|
102
|
+
#
|
103
|
+
# Lookup the keyword by name or shortcut.
|
104
|
+
# Return the keyword (name) or nil if it is not found.
|
105
|
+
#
|
106
|
+
def lookup_keyword( key )
|
107
|
+
v = find_verb key
|
108
|
+
return v.keyword if v
|
109
|
+
|
110
|
+
o = find_obj key
|
111
|
+
return o.typename if o
|
112
|
+
|
113
|
+
return nil
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# Show a list of all keywords.
|
118
|
+
# This includes verbs and objects, names and shortcuts.
|
119
|
+
#
|
120
|
+
def show_keywords
|
121
|
+
str = ''
|
122
|
+
@keywords.sort.each_with_index do |k, i|
|
123
|
+
str << k.ljust( 20, ' ' )
|
124
|
+
if ( ( i + 1 ) % 6 ).zero?
|
125
|
+
puts str
|
126
|
+
str = ''
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
# ---------------------------------------------------------------------
|
132
|
+
# Private
|
133
|
+
# ---------------------------------------------------------------------
|
134
|
+
|
135
|
+
private
|
136
|
+
|
137
|
+
#
|
138
|
+
# Add a keyword to the keyword list.
|
139
|
+
# Report an error if the keyword is already in the list.
|
140
|
+
#
|
141
|
+
def add_key( keyword )
|
142
|
+
if @keywords.include?( keyword )
|
143
|
+
$log.error "duplicate keyword '#{keyword}'"
|
144
|
+
return
|
145
|
+
end
|
146
|
+
|
147
|
+
@keywords << keyword
|
148
|
+
end
|
149
|
+
|
150
|
+
#
|
151
|
+
# Init the list of objects.
|
152
|
+
#
|
153
|
+
def init_objs
|
154
|
+
$log.debug "initializing #{@obj_references.count} objects"
|
155
|
+
@obj_references.each do |o|
|
156
|
+
$log.debug o
|
157
|
+
@objs[ o.typename ] = o
|
158
|
+
@objs[ o.short_typename ] = o
|
159
|
+
add_key o.typename
|
160
|
+
add_key o.short_typename if o.typename != o.short_typename
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
#
|
165
|
+
# Init the list of verbs.
|
166
|
+
#
|
167
|
+
def init_verbs
|
168
|
+
$log.debug "initializing #{@verb_references.count} verbs"
|
169
|
+
@verb_references.each do |v|
|
170
|
+
$log.debug v
|
171
|
+
@verbs[ v.keyword ] = v
|
172
|
+
@verbs[ v.keyword_shortcut ] = v
|
173
|
+
# v.send( :new ).run
|
174
|
+
add_key v.keyword
|
175
|
+
add_key v.keyword_shortcut if v.keyword != v.keyword_shortcut
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
102
179
|
end
|
103
180
|
end
|
104
181
|
end
|