gloo 0.3.0 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.rubocop.yml +73 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +86 -83
- data/Rakefile +7 -6
- data/bin/console +4 -4
- data/gloo.gemspec +22 -18
- data/lib/gloo.rb +6 -6
- data/lib/gloo/app/args.rb +30 -31
- data/lib/gloo/app/engine.rb +80 -30
- data/lib/gloo/app/help.rb +17 -11
- data/lib/gloo/app/info.rb +3 -3
- data/lib/gloo/app/log.rb +17 -17
- data/lib/gloo/app/mode.rb +4 -4
- data/lib/gloo/app/settings.rb +51 -41
- data/lib/gloo/convert/string_to_datetime.rb +21 -0
- data/lib/gloo/convert/string_to_decimal.rb +20 -0
- data/lib/gloo/convert/string_to_integer.rb +20 -0
- data/lib/gloo/core/baseo.rb +7 -7
- data/lib/gloo/core/dictionary.rb +30 -27
- data/lib/gloo/core/error.rb +50 -0
- data/lib/gloo/core/event_manager.rb +17 -23
- data/lib/gloo/core/factory.rb +149 -39
- data/lib/gloo/core/gloo_system.rb +121 -54
- data/lib/gloo/core/heap.rb +15 -13
- data/lib/gloo/core/it.rb +5 -5
- data/lib/gloo/core/literal.rb +7 -7
- data/lib/gloo/core/obj.rb +138 -79
- data/lib/gloo/core/obj_finder.rb +9 -14
- data/lib/gloo/core/op.rb +8 -8
- data/lib/gloo/core/parser.rb +27 -26
- data/lib/gloo/core/pn.rb +68 -52
- data/lib/gloo/core/script.rb +7 -7
- data/lib/gloo/core/tokens.rb +39 -41
- data/lib/gloo/core/verb.rb +30 -19
- data/lib/gloo/exec/dispatch.rb +30 -0
- data/lib/gloo/exec/runner.rb +43 -0
- data/lib/gloo/expr/expression.rb +36 -43
- data/lib/gloo/expr/l_boolean.rb +7 -6
- data/lib/gloo/expr/l_decimal.rb +34 -0
- data/lib/gloo/expr/l_integer.rb +5 -4
- data/lib/gloo/expr/l_string.rb +13 -15
- data/lib/gloo/expr/op_div.rb +5 -5
- data/lib/gloo/expr/op_minus.rb +5 -5
- data/lib/gloo/expr/op_mult.rb +5 -5
- data/lib/gloo/expr/op_plus.rb +7 -7
- data/lib/gloo/objs/basic/alias.rb +111 -0
- data/lib/gloo/objs/basic/boolean.rb +63 -38
- data/lib/gloo/objs/basic/container.rb +71 -12
- data/lib/gloo/objs/basic/decimal.rb +96 -0
- data/lib/gloo/objs/basic/integer.rb +45 -16
- data/lib/gloo/objs/basic/script.rb +62 -38
- data/lib/gloo/objs/basic/string.rb +47 -15
- data/lib/gloo/objs/basic/text.rb +69 -21
- data/lib/gloo/objs/basic/untyped.rb +35 -10
- data/lib/gloo/objs/cli/banner.rb +137 -0
- data/lib/gloo/objs/cli/bar.rb +141 -0
- data/lib/gloo/objs/cli/colorize.rb +54 -24
- data/lib/gloo/objs/cli/confirm.rb +63 -29
- data/lib/gloo/objs/cli/menu.rb +236 -0
- data/lib/gloo/objs/cli/menu_item.rb +128 -0
- data/lib/gloo/objs/cli/pastel.rb +120 -0
- data/lib/gloo/objs/cli/prompt.rb +73 -31
- data/lib/gloo/objs/cli/select.rb +153 -0
- data/lib/gloo/objs/ctrl/each.rb +128 -61
- data/lib/gloo/objs/ctrl/repeat.rb +129 -0
- data/lib/gloo/objs/data/markdown.rb +109 -0
- data/lib/gloo/objs/data/table.rb +168 -0
- data/lib/gloo/objs/dev/git.rb +98 -64
- data/lib/gloo/objs/dt/date.rb +72 -0
- data/lib/gloo/objs/dt/datetime.rb +84 -0
- data/lib/gloo/objs/dt/time.rb +72 -0
- data/lib/gloo/objs/ror/erb.rb +82 -41
- data/lib/gloo/objs/ror/eval.rb +73 -31
- data/lib/gloo/objs/snd/play.rb +71 -0
- data/lib/gloo/objs/snd/say.rb +120 -0
- data/lib/gloo/objs/system/file_handle.rb +129 -48
- data/lib/gloo/objs/system/system.rb +84 -38
- data/lib/gloo/objs/web/http_get.rb +103 -46
- data/lib/gloo/objs/web/http_post.rb +70 -44
- data/lib/gloo/objs/web/json.rb +155 -0
- data/lib/gloo/objs/web/slack.rb +89 -58
- data/lib/gloo/objs/web/teams.rb +88 -53
- data/lib/gloo/objs/web/uri.rb +160 -0
- data/lib/gloo/persist/file_loader.rb +95 -85
- data/lib/gloo/persist/file_saver.rb +12 -12
- data/lib/gloo/persist/file_storage.rb +15 -15
- data/lib/gloo/persist/line_splitter.rb +79 -0
- data/lib/gloo/persist/persist_man.rb +63 -39
- data/lib/gloo/utils/words.rb +2 -2
- data/lib/gloo/verbs/alert.rb +67 -16
- data/lib/gloo/verbs/beep.rb +70 -0
- data/lib/gloo/verbs/cls.rb +67 -0
- data/lib/gloo/verbs/context.rb +61 -21
- data/lib/gloo/verbs/create.rb +52 -21
- data/lib/gloo/verbs/help.rb +186 -27
- data/lib/gloo/verbs/if.rb +55 -21
- data/lib/gloo/verbs/list.rb +55 -24
- data/lib/gloo/verbs/load.rb +47 -12
- data/lib/gloo/verbs/move.rb +128 -0
- data/lib/gloo/verbs/put.rb +90 -34
- data/lib/gloo/verbs/quit.rb +43 -12
- data/lib/gloo/verbs/run.rb +63 -18
- data/lib/gloo/verbs/save.rb +45 -10
- data/lib/gloo/verbs/show.rb +56 -22
- data/lib/gloo/verbs/tell.rb +45 -13
- data/lib/gloo/verbs/unless.rb +56 -21
- data/lib/gloo/verbs/version.rb +42 -12
- data/lib/gloo/verbs/wait.rb +73 -0
- data/lib/run.rb +5 -5
- metadata +90 -12
@@ -6,46 +6,45 @@
|
|
6
6
|
# system level variables and functions. But it is not
|
7
7
|
# actually an object in the normal sense of the word.
|
8
8
|
#
|
9
|
+
require 'tty-platform'
|
9
10
|
|
10
11
|
module Gloo
|
11
12
|
module Core
|
12
13
|
class GlooSystem < Obj
|
13
|
-
|
14
|
-
KEYWORD = 'gloo'
|
15
|
-
KEYWORD_SHORT = '$'
|
16
|
-
|
17
|
-
attr_reader :pn
|
18
14
|
|
15
|
+
KEYWORD = 'gloo'.freeze
|
16
|
+
KEYWORD_SHORT = '$'.freeze
|
17
|
+
|
18
|
+
attr_reader :pn
|
19
19
|
|
20
20
|
# Set up the object.
|
21
21
|
def initialize( pn )
|
22
22
|
@pn = pn
|
23
23
|
end
|
24
|
-
|
25
|
-
#
|
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
38
|
|
39
|
-
#
|
39
|
+
#
|
40
40
|
# The object type, suitable for display.
|
41
|
-
#
|
41
|
+
#
|
42
42
|
def type_display
|
43
43
|
return self.class.typename
|
44
44
|
end
|
45
45
|
|
46
|
-
|
47
46
|
# Is this the root object?
|
48
|
-
def
|
47
|
+
def root?
|
49
48
|
return false
|
50
49
|
end
|
51
50
|
|
@@ -56,61 +55,61 @@ module Gloo
|
|
56
55
|
false
|
57
56
|
end
|
58
57
|
|
59
|
-
|
60
58
|
# ---------------------------------------------------------------------
|
61
59
|
# Value
|
62
60
|
# ---------------------------------------------------------------------
|
63
61
|
|
64
|
-
#
|
62
|
+
#
|
65
63
|
# Get the parameter.
|
66
|
-
#
|
64
|
+
#
|
67
65
|
def param
|
68
66
|
return nil unless @pn && @pn.segments.count > 1
|
69
|
-
|
67
|
+
|
68
|
+
return @pn.segments[ 1..-1 ].join( '_' )
|
70
69
|
end
|
71
|
-
|
70
|
+
|
72
71
|
#
|
73
72
|
# Get the system value.
|
74
|
-
#
|
73
|
+
#
|
75
74
|
def value
|
76
75
|
return dispatch param
|
77
76
|
end
|
78
|
-
|
79
|
-
#
|
77
|
+
|
78
|
+
#
|
80
79
|
# There is no value object in the system.
|
81
|
-
#
|
82
|
-
def set_value new_value
|
80
|
+
#
|
81
|
+
def set_value( new_value )
|
82
|
+
# overriding base functionality with dummy function
|
83
83
|
end
|
84
|
-
|
85
|
-
#
|
84
|
+
|
85
|
+
#
|
86
86
|
# Get the value for display purposes.
|
87
|
-
#
|
87
|
+
#
|
88
88
|
def value_display
|
89
89
|
return value
|
90
90
|
end
|
91
|
-
|
92
|
-
#
|
91
|
+
|
92
|
+
#
|
93
93
|
# Is the value a String?
|
94
|
-
#
|
95
|
-
def
|
94
|
+
#
|
95
|
+
def value_string?
|
96
96
|
return true
|
97
97
|
end
|
98
98
|
|
99
|
-
#
|
99
|
+
#
|
100
100
|
# Is the value an Array?
|
101
|
-
#
|
101
|
+
#
|
102
102
|
def value_is_array?
|
103
103
|
return false
|
104
104
|
end
|
105
|
-
|
106
|
-
#
|
105
|
+
|
106
|
+
#
|
107
107
|
# Is the value a blank string?
|
108
|
-
#
|
108
|
+
#
|
109
109
|
def value_is_blank?
|
110
110
|
return true
|
111
111
|
end
|
112
112
|
|
113
|
-
|
114
113
|
# ---------------------------------------------------------------------
|
115
114
|
# Children
|
116
115
|
# ---------------------------------------------------------------------
|
@@ -122,34 +121,31 @@ module Gloo
|
|
122
121
|
return false
|
123
122
|
end
|
124
123
|
|
125
|
-
|
126
124
|
# ---------------------------------------------------------------------
|
127
125
|
# Messages
|
128
126
|
# ---------------------------------------------------------------------
|
129
127
|
|
130
|
-
#
|
128
|
+
#
|
131
129
|
# Get a list of message names that this object receives.
|
132
|
-
#
|
130
|
+
#
|
133
131
|
def self.messages
|
134
132
|
return []
|
135
133
|
end
|
136
|
-
|
134
|
+
|
137
135
|
# Dispatch the message and get the value.
|
138
|
-
def dispatch msg
|
136
|
+
def dispatch( msg )
|
139
137
|
o = "msg_#{msg}"
|
140
|
-
if self.respond_to? o
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
end
|
147
|
-
|
138
|
+
return self.public_send( o ) if self.respond_to? o
|
139
|
+
|
140
|
+
$log.error "Message #{msg} not implemented"
|
141
|
+
return false
|
142
|
+
end
|
143
|
+
|
148
144
|
# Get the system hostname.
|
149
145
|
def msg_hostname
|
150
146
|
return Socket.gethostname
|
151
147
|
end
|
152
|
-
|
148
|
+
|
153
149
|
# Get the logged in User.
|
154
150
|
def msg_user
|
155
151
|
return ENV[ 'USER' ]
|
@@ -157,14 +153,14 @@ module Gloo
|
|
157
153
|
|
158
154
|
# Get the user's home directory.
|
159
155
|
def msg_user_home
|
160
|
-
return File.expand_path(
|
156
|
+
return File.expand_path( '~' )
|
161
157
|
end
|
162
158
|
|
163
|
-
|
159
|
+
# Get the working directory.
|
164
160
|
def msg_working_dir
|
165
161
|
return Dir.pwd
|
166
162
|
end
|
167
|
-
|
163
|
+
|
168
164
|
# Get the Gloo home directory
|
169
165
|
def msg_gloo_home
|
170
166
|
return $settings.user_root
|
@@ -185,6 +181,77 @@ module Gloo
|
|
185
181
|
return $settings.log_path
|
186
182
|
end
|
187
183
|
|
184
|
+
# ---------------------------------------------------------------------
|
185
|
+
# Screen Messages
|
186
|
+
# ---------------------------------------------------------------------
|
187
|
+
|
188
|
+
# Get the number of lines on screen.
|
189
|
+
def msg_screen_lines
|
190
|
+
return Gloo::App::Settings.lines
|
191
|
+
end
|
192
|
+
|
193
|
+
# Get the number of columns on screen.
|
194
|
+
def msg_screen_cols
|
195
|
+
return Gloo::App::Settings.cols
|
196
|
+
end
|
197
|
+
|
198
|
+
# ---------------------------------------------------------------------
|
199
|
+
# Platform Messages
|
200
|
+
# ---------------------------------------------------------------------
|
201
|
+
|
202
|
+
# Get the platform CPU
|
203
|
+
def msg_platform_cpu
|
204
|
+
platform = TTY::Platform.new
|
205
|
+
return platform.cpu
|
206
|
+
end
|
207
|
+
|
208
|
+
# Get the platform Operating System
|
209
|
+
def msg_platform_os
|
210
|
+
platform = TTY::Platform.new
|
211
|
+
return platform.os
|
212
|
+
end
|
213
|
+
|
214
|
+
# Get the platform version
|
215
|
+
def msg_platform_version
|
216
|
+
platform = TTY::Platform.new
|
217
|
+
return platform.version
|
218
|
+
end
|
219
|
+
|
220
|
+
# Is the platform Windows?
|
221
|
+
def msg_platform_windows?
|
222
|
+
platform = TTY::Platform.new
|
223
|
+
return platform.windows?
|
224
|
+
end
|
225
|
+
|
226
|
+
# Is the platform Unix?
|
227
|
+
def msg_platform_unix?
|
228
|
+
platform = TTY::Platform.new
|
229
|
+
return platform.unix?
|
230
|
+
end
|
231
|
+
|
232
|
+
# Is the platform Linux?
|
233
|
+
def msg_platform_linux?
|
234
|
+
platform = TTY::Platform.new
|
235
|
+
return platform.linux?
|
236
|
+
end
|
237
|
+
|
238
|
+
# Is the platform Mac?
|
239
|
+
def msg_platform_mac?
|
240
|
+
platform = TTY::Platform.new
|
241
|
+
return platform.mac?
|
242
|
+
end
|
243
|
+
|
244
|
+
#
|
245
|
+
# Get the command to open a file on this platform.
|
246
|
+
#
|
247
|
+
def self.open_for_platform
|
248
|
+
platform = TTY::Platform.new
|
249
|
+
return 'open' if platform.mac?
|
250
|
+
return 'xdg-open' if platform.linux?
|
251
|
+
|
252
|
+
return nil
|
253
|
+
end
|
254
|
+
|
188
255
|
end
|
189
256
|
end
|
190
257
|
end
|
data/lib/gloo/core/heap.rb
CHANGED
@@ -9,34 +9,36 @@
|
|
9
9
|
module Gloo
|
10
10
|
module Core
|
11
11
|
class Heap
|
12
|
-
|
12
|
+
|
13
13
|
# The context is a reference to an object, usually a container.
|
14
14
|
# The context will be the root by default.
|
15
15
|
attr_reader :context
|
16
|
-
|
16
|
+
|
17
17
|
# TODO: Do I need a running script context?
|
18
18
|
# how to resolve relative reference.
|
19
|
-
|
20
|
-
attr_reader :it, :root
|
21
|
-
|
19
|
+
|
20
|
+
attr_reader :it, :root, :error
|
21
|
+
|
22
22
|
# Set up the object heap.
|
23
|
-
def initialize
|
24
|
-
$log.debug
|
25
|
-
|
23
|
+
def initialize
|
24
|
+
$log.debug 'object heap intialized...'
|
25
|
+
|
26
26
|
@root = Gloo::Objs::Container.new
|
27
|
-
@root.name =
|
28
|
-
|
27
|
+
@root.name = 'root'
|
28
|
+
|
29
29
|
@context = Pn.root
|
30
30
|
@it = It.new
|
31
|
+
@error = Error.new
|
31
32
|
end
|
32
|
-
|
33
|
+
|
33
34
|
# Unload the given obj--remove it from the heap.
|
34
|
-
def unload obj
|
35
|
+
def unload( obj )
|
35
36
|
can = obj.parent.nil? ? @root : obj.parent
|
36
37
|
return unless can
|
38
|
+
|
37
39
|
can.remove_child obj
|
38
40
|
end
|
39
|
-
|
41
|
+
|
40
42
|
end
|
41
43
|
end
|
42
44
|
end
|
data/lib/gloo/core/it.rb
CHANGED
@@ -7,16 +7,16 @@
|
|
7
7
|
module Gloo
|
8
8
|
module Core
|
9
9
|
class It
|
10
|
-
|
10
|
+
|
11
11
|
attr_accessor :value
|
12
|
-
|
12
|
+
|
13
13
|
# Set up the object.
|
14
|
-
def initialize
|
14
|
+
def initialize
|
15
15
|
@value = nil
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
# Set the value of it.
|
19
|
-
def set_to new_value
|
19
|
+
def set_to( new_value )
|
20
20
|
@value = new_value
|
21
21
|
end
|
22
22
|
|
data/lib/gloo/core/literal.rb
CHANGED
@@ -7,19 +7,19 @@
|
|
7
7
|
module Gloo
|
8
8
|
module Core
|
9
9
|
class Literal
|
10
|
-
|
10
|
+
|
11
11
|
attr_reader :value
|
12
|
-
|
12
|
+
|
13
13
|
# Create the expression from a list of tokens.
|
14
|
-
def initialize value
|
14
|
+
def initialize( value )
|
15
15
|
set_value( value )
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
# Set the literal value.
|
19
|
-
def set_value value
|
19
|
+
def set_value( value )
|
20
20
|
@value = value
|
21
|
-
end
|
22
|
-
|
21
|
+
end
|
22
|
+
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
data/lib/gloo/core/obj.rb
CHANGED
@@ -8,47 +8,48 @@
|
|
8
8
|
module Gloo
|
9
9
|
module Core
|
10
10
|
class Obj < Baseo
|
11
|
-
|
11
|
+
|
12
12
|
attr_accessor :value
|
13
13
|
attr_reader :children, :parent
|
14
14
|
|
15
15
|
# Set up the object.
|
16
|
-
def initialize
|
17
|
-
@value =
|
16
|
+
def initialize
|
17
|
+
@value = ''
|
18
18
|
@children = []
|
19
19
|
@parent = nil
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
# Register object types when they are loaded.
|
23
23
|
def self.inherited( subclass )
|
24
24
|
Dictionary.instance.register_obj( subclass )
|
25
25
|
end
|
26
26
|
|
27
|
-
#
|
27
|
+
#
|
28
28
|
# The name of the object type.
|
29
|
-
#
|
29
|
+
#
|
30
30
|
def self.typename
|
31
31
|
raise 'this method should be overriden'
|
32
32
|
end
|
33
33
|
|
34
|
-
#
|
34
|
+
#
|
35
35
|
# The object type, suitable for display.
|
36
|
-
#
|
36
|
+
#
|
37
37
|
def type_display
|
38
38
|
return self.class.typename
|
39
39
|
end
|
40
40
|
|
41
|
-
#
|
41
|
+
#
|
42
42
|
# Set the parent for the object.
|
43
|
-
#
|
44
|
-
def set_parent obj
|
43
|
+
#
|
44
|
+
def set_parent( obj )
|
45
45
|
@parent = obj
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
# Is this the root object?
|
49
|
-
def
|
49
|
+
def root?
|
50
50
|
return false if @parent
|
51
|
-
return false unless name.downcase ==
|
51
|
+
return false unless name.downcase == 'root'
|
52
|
+
|
52
53
|
return true
|
53
54
|
end
|
54
55
|
|
@@ -58,165 +59,223 @@ module Gloo
|
|
58
59
|
def self.can_create?
|
59
60
|
true
|
60
61
|
end
|
61
|
-
|
62
|
-
|
62
|
+
|
63
|
+
#
|
64
|
+
# Get the path and name to this object.
|
65
|
+
#
|
66
|
+
def pn
|
67
|
+
str = self.name
|
68
|
+
p = self.parent
|
69
|
+
while p && !p.root?
|
70
|
+
str = "#{p.name}.#{str}"
|
71
|
+
p = p.parent
|
72
|
+
end
|
73
|
+
return str
|
74
|
+
end
|
75
|
+
|
63
76
|
# ---------------------------------------------------------------------
|
64
77
|
# Value
|
65
78
|
# ---------------------------------------------------------------------
|
66
79
|
|
67
|
-
#
|
80
|
+
#
|
68
81
|
# Set the value with any necessary type conversions.
|
69
|
-
#
|
70
|
-
def set_value new_value
|
82
|
+
#
|
83
|
+
def set_value( new_value )
|
71
84
|
self.value = new_value
|
72
85
|
end
|
73
|
-
|
74
|
-
#
|
86
|
+
|
87
|
+
#
|
75
88
|
# Get the value for display purposes.
|
76
|
-
#
|
89
|
+
#
|
77
90
|
def value_display
|
78
91
|
return self.value.to_s
|
79
92
|
end
|
80
|
-
|
81
|
-
#
|
93
|
+
|
94
|
+
#
|
82
95
|
# Does this object support multi-line values?
|
83
96
|
# Initially only true for scripts.
|
84
|
-
#
|
85
|
-
def
|
97
|
+
#
|
98
|
+
def multiline_value?
|
86
99
|
return false
|
87
100
|
end
|
88
|
-
|
89
|
-
#
|
101
|
+
|
102
|
+
#
|
90
103
|
# Is the value a String?
|
91
|
-
#
|
92
|
-
def
|
104
|
+
#
|
105
|
+
def value_string?
|
93
106
|
return self.value.is_a? String
|
94
107
|
end
|
95
108
|
|
96
|
-
#
|
109
|
+
#
|
97
110
|
# Is the value an Array?
|
98
|
-
#
|
111
|
+
#
|
99
112
|
def value_is_array?
|
100
113
|
return self.value.is_a? Array
|
101
114
|
end
|
102
|
-
|
103
|
-
#
|
115
|
+
|
116
|
+
#
|
104
117
|
# Is the value a blank string?
|
105
|
-
#
|
118
|
+
#
|
106
119
|
def value_is_blank?
|
107
120
|
return true if value.nil?
|
121
|
+
|
108
122
|
return self.value.to_s.strip.empty?
|
109
123
|
end
|
110
|
-
|
111
124
|
|
112
125
|
# ---------------------------------------------------------------------
|
113
126
|
# Children
|
114
127
|
# ---------------------------------------------------------------------
|
115
|
-
|
128
|
+
|
129
|
+
#
|
130
|
+
# Find a child of the given name.
|
131
|
+
# If found, return it. If not found create it.
|
132
|
+
#
|
133
|
+
def find_add_child( name, type )
|
134
|
+
child = self.find_child( name )
|
135
|
+
return child if child
|
136
|
+
|
137
|
+
params = { :name => name,
|
138
|
+
:type => type,
|
139
|
+
:value => nil,
|
140
|
+
:parent => self }
|
141
|
+
return $engine.factory.create params
|
142
|
+
end
|
143
|
+
|
116
144
|
# Add a child object to the container.
|
117
|
-
def add_child obj
|
145
|
+
def add_child( obj )
|
118
146
|
@children << obj
|
119
147
|
obj.set_parent self
|
120
148
|
end
|
121
|
-
|
149
|
+
|
122
150
|
# Get the number of children.
|
123
151
|
def child_count
|
124
152
|
return @children.count
|
125
153
|
end
|
126
|
-
|
154
|
+
|
127
155
|
# Does this object contain an object with the given name?
|
128
|
-
def
|
156
|
+
def contains_child?( name )
|
129
157
|
@children.each do |o|
|
130
|
-
return true if
|
158
|
+
return true if name.downcase == o.name.downcase
|
131
159
|
end
|
132
160
|
return false
|
133
161
|
end
|
134
162
|
|
135
163
|
# Find a child object with the given name.
|
136
|
-
def find_child name
|
164
|
+
def find_child( name )
|
165
|
+
if name.end_with?( Gloo::Objs::Alias::ALIAS_REFERENCE )
|
166
|
+
name = name[ 0..-2 ]
|
167
|
+
end
|
168
|
+
|
137
169
|
@children.each do |o|
|
138
|
-
return o if
|
170
|
+
return o if name.downcase == o.name.downcase
|
171
|
+
end
|
172
|
+
|
173
|
+
if self.type_display == Gloo::Objs::Alias.typename
|
174
|
+
ln = Gloo::Core::Pn.new( self.value )
|
175
|
+
redirect = ln.resolve
|
176
|
+
return redirect.find_child( name )
|
139
177
|
end
|
140
178
|
return nil
|
141
179
|
end
|
142
|
-
|
180
|
+
|
181
|
+
#
|
182
|
+
# Delete all children from the container.
|
183
|
+
#
|
184
|
+
def delete_children
|
185
|
+
@children.reverse.each do |o|
|
186
|
+
self.remove_child o
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
#
|
143
191
|
# Remove the object from the children collection.
|
144
|
-
|
192
|
+
#
|
193
|
+
def remove_child( obj )
|
145
194
|
@children.delete obj
|
146
195
|
end
|
147
|
-
|
196
|
+
|
148
197
|
# Does this object have children to add when an object
|
149
198
|
# is created in interactive mode?
|
150
199
|
# This does not apply during obj load, etc.
|
151
200
|
def add_children_on_create?
|
152
201
|
return false
|
153
202
|
end
|
154
|
-
|
203
|
+
|
155
204
|
# Add children to this object.
|
156
|
-
# This is used by containers to add children needed
|
205
|
+
# This is used by containers to add children needed
|
157
206
|
# for default configurations.
|
158
207
|
def add_default_children
|
208
|
+
# Override this.
|
159
209
|
end
|
160
210
|
|
161
|
-
|
162
211
|
# ---------------------------------------------------------------------
|
163
212
|
# Messages
|
164
213
|
# ---------------------------------------------------------------------
|
165
214
|
|
166
|
-
#
|
215
|
+
#
|
167
216
|
# Get a list of message names that this object receives.
|
168
|
-
#
|
217
|
+
#
|
169
218
|
def self.messages
|
170
|
-
return [
|
219
|
+
return %w[unload]
|
171
220
|
end
|
172
|
-
|
173
|
-
#
|
221
|
+
|
222
|
+
#
|
174
223
|
# Can this object receive a message?
|
175
|
-
#
|
176
|
-
def can_receive_message? msg
|
224
|
+
#
|
225
|
+
def can_receive_message?( msg )
|
177
226
|
msgs = self.class.messages
|
178
227
|
return msgs.include?( msg.strip.downcase )
|
179
228
|
end
|
180
229
|
|
181
|
-
#
|
230
|
+
#
|
182
231
|
# Sent this object the given message.
|
183
|
-
#
|
184
|
-
def send_message msg, params=nil
|
185
|
-
|
186
|
-
if self.can_receive_message? msg
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
return false
|
191
|
-
end
|
232
|
+
#
|
233
|
+
def send_message( msg, params = nil )
|
234
|
+
@params = params
|
235
|
+
return self.dispatch msg if self.can_receive_message? msg
|
236
|
+
|
237
|
+
$log.error "Object #{self.name} cannot receive message #{msg}"
|
238
|
+
return false
|
192
239
|
end
|
193
|
-
|
194
|
-
#
|
240
|
+
|
241
|
+
#
|
195
242
|
# Dispatch the message to the object.
|
196
|
-
#
|
197
|
-
def dispatch msg
|
243
|
+
#
|
244
|
+
def dispatch( msg )
|
198
245
|
o = "msg_#{msg}"
|
199
|
-
if self.respond_to? o
|
200
|
-
self.public_send( o )
|
246
|
+
if self.respond_to? o
|
247
|
+
self.public_send( o )
|
201
248
|
return true
|
202
249
|
else
|
203
250
|
$log.error "Message #{msg} not implemented"
|
204
251
|
return false
|
205
252
|
end
|
206
253
|
end
|
207
|
-
|
208
|
-
#
|
254
|
+
|
255
|
+
#
|
209
256
|
# Send the object the unload message.
|
210
|
-
#
|
257
|
+
#
|
211
258
|
def msg_unload
|
212
|
-
if self.
|
213
|
-
$log.error
|
259
|
+
if self.root?
|
260
|
+
$log.error 'Cannot unload the root object.'
|
214
261
|
return
|
215
262
|
end
|
263
|
+
|
216
264
|
$engine.event_manager.on_unload self
|
217
265
|
$engine.heap.unload self
|
218
266
|
end
|
219
|
-
|
267
|
+
|
268
|
+
# ---------------------------------------------------------------------
|
269
|
+
# Help
|
270
|
+
# ---------------------------------------------------------------------
|
271
|
+
|
272
|
+
#
|
273
|
+
# Get help for this object.
|
274
|
+
#
|
275
|
+
def self.help
|
276
|
+
return 'No help found.'
|
277
|
+
end
|
278
|
+
|
220
279
|
end
|
221
280
|
end
|
222
281
|
end
|