gloo 0.3.0 → 0.4.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +73 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +3 -3
- data/Rakefile +6 -6
- data/bin/console +4 -4
- data/gloo.gemspec +19 -18
- data/lib/gloo.rb +6 -6
- data/lib/gloo/app/args.rb +30 -31
- data/lib/gloo/app/engine.rb +33 -28
- 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 +43 -40
- 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 -19
- data/lib/gloo/core/factory.rb +92 -39
- data/lib/gloo/core/gloo_system.rb +49 -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 +89 -79
- data/lib/gloo/core/obj_finder.rb +9 -14
- data/lib/gloo/core/op.rb +8 -8
- data/lib/gloo/core/parser.rb +25 -26
- data/lib/gloo/core/pn.rb +65 -50
- data/lib/gloo/core/runner.rb +26 -0
- 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/expr/expression.rb +35 -43
- data/lib/gloo/expr/l_boolean.rb +7 -6
- 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 +3 -5
- data/lib/gloo/expr/op_minus.rb +3 -5
- data/lib/gloo/expr/op_mult.rb +3 -5
- data/lib/gloo/expr/op_plus.rb +5 -7
- data/lib/gloo/objs/basic/boolean.rb +63 -38
- data/lib/gloo/objs/basic/container.rb +40 -12
- data/lib/gloo/objs/basic/integer.rb +40 -16
- data/lib/gloo/objs/basic/script.rb +62 -38
- data/lib/gloo/objs/basic/string.rb +39 -15
- data/lib/gloo/objs/basic/text.rb +43 -20
- data/lib/gloo/objs/basic/untyped.rb +35 -10
- data/lib/gloo/objs/cli/colorize.rb +53 -23
- data/lib/gloo/objs/cli/confirm.rb +63 -29
- data/lib/gloo/objs/cli/prompt.rb +63 -29
- data/lib/gloo/objs/ctrl/each.rb +98 -60
- data/lib/gloo/objs/dev/git.rb +98 -64
- data/lib/gloo/objs/ror/erb.rb +81 -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 +80 -48
- data/lib/gloo/objs/system/system.rb +84 -38
- data/lib/gloo/objs/web/http_get.rb +83 -46
- data/lib/gloo/objs/web/http_post.rb +69 -43
- data/lib/gloo/objs/web/slack.rb +89 -58
- data/lib/gloo/objs/web/teams.rb +88 -53
- data/lib/gloo/persist/file_loader.rb +81 -82
- 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 +74 -0
- data/lib/gloo/persist/persist_man.rb +29 -29
- 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/context.rb +61 -21
- data/lib/gloo/verbs/create.rb +52 -21
- data/lib/gloo/verbs/help.rb +177 -27
- data/lib/gloo/verbs/if.rb +54 -21
- data/lib/gloo/verbs/list.rb +55 -24
- data/lib/gloo/verbs/load.rb +46 -12
- data/lib/gloo/verbs/put.rb +90 -34
- data/lib/gloo/verbs/quit.rb +43 -12
- data/lib/gloo/verbs/run.rb +42 -11
- data/lib/gloo/verbs/save.rb +45 -10
- data/lib/gloo/verbs/show.rb +56 -22
- data/lib/gloo/verbs/tell.rb +44 -12
- data/lib/gloo/verbs/unless.rb +55 -21
- data/lib/gloo/verbs/version.rb +42 -12
- data/lib/run.rb +5 -5
- metadata +19 -12
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,174 @@ module Gloo
|
|
58
59
|
def self.can_create?
|
59
60
|
true
|
60
61
|
end
|
61
|
-
|
62
|
-
|
62
|
+
|
63
63
|
# ---------------------------------------------------------------------
|
64
64
|
# Value
|
65
65
|
# ---------------------------------------------------------------------
|
66
66
|
|
67
|
-
#
|
67
|
+
#
|
68
68
|
# Set the value with any necessary type conversions.
|
69
|
-
#
|
70
|
-
def set_value new_value
|
69
|
+
#
|
70
|
+
def set_value( new_value )
|
71
71
|
self.value = new_value
|
72
72
|
end
|
73
|
-
|
74
|
-
#
|
73
|
+
|
74
|
+
#
|
75
75
|
# Get the value for display purposes.
|
76
|
-
#
|
76
|
+
#
|
77
77
|
def value_display
|
78
78
|
return self.value.to_s
|
79
79
|
end
|
80
|
-
|
81
|
-
#
|
80
|
+
|
81
|
+
#
|
82
82
|
# Does this object support multi-line values?
|
83
83
|
# Initially only true for scripts.
|
84
|
-
#
|
85
|
-
def
|
84
|
+
#
|
85
|
+
def multiline_value?
|
86
86
|
return false
|
87
87
|
end
|
88
|
-
|
89
|
-
#
|
88
|
+
|
89
|
+
#
|
90
90
|
# Is the value a String?
|
91
|
-
#
|
92
|
-
def
|
91
|
+
#
|
92
|
+
def value_string?
|
93
93
|
return self.value.is_a? String
|
94
94
|
end
|
95
95
|
|
96
|
-
#
|
96
|
+
#
|
97
97
|
# Is the value an Array?
|
98
|
-
#
|
98
|
+
#
|
99
99
|
def value_is_array?
|
100
100
|
return self.value.is_a? Array
|
101
101
|
end
|
102
|
-
|
103
|
-
#
|
102
|
+
|
103
|
+
#
|
104
104
|
# Is the value a blank string?
|
105
|
-
#
|
105
|
+
#
|
106
106
|
def value_is_blank?
|
107
107
|
return true if value.nil?
|
108
|
+
|
108
109
|
return self.value.to_s.strip.empty?
|
109
110
|
end
|
110
|
-
|
111
111
|
|
112
112
|
# ---------------------------------------------------------------------
|
113
113
|
# Children
|
114
114
|
# ---------------------------------------------------------------------
|
115
|
-
|
115
|
+
|
116
116
|
# Add a child object to the container.
|
117
|
-
def add_child obj
|
117
|
+
def add_child( obj )
|
118
118
|
@children << obj
|
119
119
|
obj.set_parent self
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
# Get the number of children.
|
123
123
|
def child_count
|
124
124
|
return @children.count
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
# Does this object contain an object with the given name?
|
128
|
-
def
|
128
|
+
def contains_child?( name )
|
129
129
|
@children.each do |o|
|
130
|
-
return true if
|
130
|
+
return true if name.downcase == o.name.downcase
|
131
131
|
end
|
132
132
|
return false
|
133
133
|
end
|
134
134
|
|
135
135
|
# Find a child object with the given name.
|
136
|
-
def find_child name
|
136
|
+
def find_child( name )
|
137
137
|
@children.each do |o|
|
138
|
-
return o if
|
138
|
+
return o if name.downcase == o.name.downcase
|
139
139
|
end
|
140
140
|
return nil
|
141
141
|
end
|
142
|
-
|
142
|
+
|
143
143
|
# Remove the object from the children collection.
|
144
|
-
def remove_child obj
|
144
|
+
def remove_child( obj )
|
145
145
|
@children.delete obj
|
146
146
|
end
|
147
|
-
|
147
|
+
|
148
148
|
# Does this object have children to add when an object
|
149
149
|
# is created in interactive mode?
|
150
150
|
# This does not apply during obj load, etc.
|
151
151
|
def add_children_on_create?
|
152
152
|
return false
|
153
153
|
end
|
154
|
-
|
154
|
+
|
155
155
|
# Add children to this object.
|
156
|
-
# This is used by containers to add children needed
|
156
|
+
# This is used by containers to add children needed
|
157
157
|
# for default configurations.
|
158
158
|
def add_default_children
|
159
|
+
# Override this.
|
159
160
|
end
|
160
161
|
|
161
|
-
|
162
162
|
# ---------------------------------------------------------------------
|
163
163
|
# Messages
|
164
164
|
# ---------------------------------------------------------------------
|
165
165
|
|
166
|
-
#
|
166
|
+
#
|
167
167
|
# Get a list of message names that this object receives.
|
168
|
-
#
|
168
|
+
#
|
169
169
|
def self.messages
|
170
|
-
return [
|
170
|
+
return [ 'unload' ]
|
171
171
|
end
|
172
|
-
|
173
|
-
#
|
172
|
+
|
173
|
+
#
|
174
174
|
# Can this object receive a message?
|
175
|
-
#
|
176
|
-
def can_receive_message? msg
|
175
|
+
#
|
176
|
+
def can_receive_message?( msg )
|
177
177
|
msgs = self.class.messages
|
178
178
|
return msgs.include?( msg.strip.downcase )
|
179
179
|
end
|
180
180
|
|
181
|
-
#
|
181
|
+
#
|
182
182
|
# 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
|
183
|
+
#
|
184
|
+
def send_message( msg, params = nil )
|
185
|
+
@params = params
|
186
|
+
return self.dispatch msg if self.can_receive_message? msg
|
187
|
+
|
188
|
+
$log.error "Object #{self.name} cannot receive message #{msg}"
|
189
|
+
return false
|
192
190
|
end
|
193
|
-
|
194
|
-
#
|
191
|
+
|
192
|
+
#
|
195
193
|
# Dispatch the message to the object.
|
196
|
-
#
|
197
|
-
def dispatch msg
|
194
|
+
#
|
195
|
+
def dispatch( msg )
|
198
196
|
o = "msg_#{msg}"
|
199
|
-
if self.respond_to? o
|
200
|
-
self.public_send( o )
|
197
|
+
if self.respond_to? o
|
198
|
+
self.public_send( o )
|
201
199
|
return true
|
202
200
|
else
|
203
201
|
$log.error "Message #{msg} not implemented"
|
204
202
|
return false
|
205
203
|
end
|
206
204
|
end
|
207
|
-
|
208
|
-
#
|
205
|
+
|
206
|
+
#
|
209
207
|
# Send the object the unload message.
|
210
|
-
#
|
208
|
+
#
|
211
209
|
def msg_unload
|
212
|
-
if self.
|
213
|
-
$log.error
|
210
|
+
if self.root?
|
211
|
+
$log.error 'Cannot unload the root object.'
|
214
212
|
return
|
215
213
|
end
|
214
|
+
|
216
215
|
$engine.event_manager.on_unload self
|
217
216
|
$engine.heap.unload self
|
218
217
|
end
|
219
|
-
|
218
|
+
|
219
|
+
# ---------------------------------------------------------------------
|
220
|
+
# Help
|
221
|
+
# ---------------------------------------------------------------------
|
222
|
+
|
223
|
+
#
|
224
|
+
# Get help for this object.
|
225
|
+
#
|
226
|
+
def self.help
|
227
|
+
return 'No help found.'
|
228
|
+
end
|
229
|
+
|
220
230
|
end
|
221
231
|
end
|
222
232
|
end
|
data/lib/gloo/core/obj_finder.rb
CHANGED
@@ -7,29 +7,24 @@
|
|
7
7
|
module Gloo
|
8
8
|
module Core
|
9
9
|
class ObjFinder
|
10
|
-
|
11
|
-
#
|
10
|
+
|
11
|
+
#
|
12
12
|
# Find all objects in the given container that have
|
13
13
|
# the given name.
|
14
14
|
# If the container isn't provided, root will be used.
|
15
|
-
#
|
16
|
-
def self.by_name name, container=nil
|
17
|
-
if container.nil?
|
18
|
-
container = $engine.heap.root
|
19
|
-
end
|
15
|
+
#
|
16
|
+
def self.by_name( name, container = nil )
|
17
|
+
container = $engine.heap.root if container.nil?
|
20
18
|
arr = []
|
21
|
-
|
19
|
+
|
22
20
|
container.children.each do |o|
|
23
21
|
arr << o if o.name == name
|
24
|
-
if o.child_count
|
25
|
-
arr += by_name( name, o )
|
26
|
-
end
|
22
|
+
arr += by_name( name, o ) if o.child_count.positive?
|
27
23
|
end
|
28
|
-
|
24
|
+
|
29
25
|
return arr
|
30
26
|
end
|
31
|
-
|
32
|
-
|
27
|
+
|
33
28
|
end
|
34
29
|
end
|
35
30
|
end
|
data/lib/gloo/core/op.rb
CHANGED
@@ -7,27 +7,27 @@
|
|
7
7
|
module Gloo
|
8
8
|
module Core
|
9
9
|
class Op
|
10
|
-
|
10
|
+
|
11
11
|
# Is the token an operator?
|
12
|
-
def self.
|
13
|
-
return [
|
12
|
+
def self.op?( token )
|
13
|
+
return [ '+', '-', '*', '/' ].include?( token.strip )
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
# Create the operator for the given token.
|
17
|
-
def self.create_op token
|
17
|
+
def self.create_op( token )
|
18
18
|
return Gloo::Expr::OpMinus.new if token == '-'
|
19
19
|
return Gloo::Expr::OpMult.new if token == '*'
|
20
20
|
return Gloo::Expr::OpDiv.new if token == '/'
|
21
21
|
return Gloo::Expr::OpPlus.new if token == '+'
|
22
|
-
|
22
|
+
|
23
23
|
return default_op
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
# Get the default operator (+).
|
27
27
|
def self.default_op
|
28
28
|
return Gloo::Expr::OpPlus.new
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
data/lib/gloo/core/parser.rb
CHANGED
@@ -8,45 +8,44 @@
|
|
8
8
|
module Gloo
|
9
9
|
module Core
|
10
10
|
class Parser
|
11
|
-
|
11
|
+
|
12
12
|
# Set up the parser.
|
13
|
-
def initialize
|
14
|
-
$log.debug
|
13
|
+
def initialize
|
14
|
+
$log.debug 'parser intialized...'
|
15
15
|
end
|
16
|
-
|
17
|
-
|
16
|
+
|
18
17
|
# Parse a command from the immediate execution context.
|
19
|
-
def parse_immediate cmd
|
20
|
-
|
21
|
-
|
18
|
+
def parse_immediate( cmd )
|
19
|
+
cmd, params = split_params cmd
|
20
|
+
params = Gloo::Core::Tokens.new( params ) if params
|
22
21
|
tokens = Gloo::Core::Tokens.new( cmd )
|
23
22
|
dic = Gloo::Core::Dictionary.instance
|
24
23
|
verb = dic.find_verb( tokens.verb )
|
25
24
|
return verb.new( tokens, params ) if verb
|
26
|
-
|
25
|
+
|
27
26
|
$log.error "Verb '#{tokens.verb}' was not found."
|
28
27
|
return nil
|
29
28
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
29
|
+
|
30
|
+
# If additional params were provided, split them out
|
31
|
+
# from the token list.
|
32
|
+
def split_params( cmd )
|
33
|
+
params = nil
|
34
|
+
i = cmd.rindex( '(' )
|
35
|
+
if i && cmd.strip.end_with?( ')' )
|
36
|
+
pstr = cmd[ i + 1..-1 ]
|
37
|
+
params = pstr.strip[ 0..-2 ] if pstr
|
38
|
+
cmd = cmd[ 0, i - 1 ]
|
39
|
+
end
|
40
|
+
return cmd, params
|
41
|
+
end
|
42
|
+
|
44
43
|
# Parse a command and then run it if it parsed correctly.
|
45
|
-
def run cmd
|
44
|
+
def run( cmd )
|
46
45
|
v = parse_immediate( cmd )
|
47
|
-
|
46
|
+
Runner.go( v ) if v
|
48
47
|
end
|
49
|
-
|
48
|
+
|
50
49
|
end
|
51
50
|
end
|
52
51
|
end
|