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
@@ -8,39 +8,37 @@
|
|
8
8
|
module Gloo
|
9
9
|
module Core
|
10
10
|
class EventManager
|
11
|
-
|
11
|
+
|
12
12
|
# Set up the event manager.
|
13
|
-
def initialize
|
14
|
-
$log.debug
|
13
|
+
def initialize
|
14
|
+
$log.debug 'event manager intialized...'
|
15
15
|
end
|
16
|
-
|
17
|
-
#
|
16
|
+
|
17
|
+
#
|
18
18
|
# Run on_load scripts in the recently loaded object
|
19
19
|
# If no obj is given the script will be run in root.
|
20
|
-
#
|
21
|
-
def on_load obj=nil, in_heap=false
|
20
|
+
#
|
21
|
+
def on_load( obj = nil, in_heap = false )
|
22
22
|
return unless obj || in_heap
|
23
|
-
|
23
|
+
|
24
|
+
arr = Gloo::Core::ObjFinder.by_name 'on_load', obj
|
24
25
|
arr.each do |o|
|
25
|
-
if o.can_receive_message?
|
26
|
-
o.send_message "run"
|
27
|
-
end
|
26
|
+
o.send_message 'run' if o.can_receive_message? 'run'
|
28
27
|
end
|
29
28
|
end
|
30
29
|
|
31
|
-
#
|
30
|
+
#
|
32
31
|
# Run on_unload scripts in the object that will be unloaded.
|
33
|
-
#
|
34
|
-
def on_unload obj
|
32
|
+
#
|
33
|
+
def on_unload( obj )
|
35
34
|
return unless obj
|
36
|
-
|
35
|
+
|
36
|
+
arr = Gloo::Core::ObjFinder.by_name 'on_unload', obj
|
37
37
|
arr.each do |o|
|
38
|
-
if o.can_receive_message?
|
39
|
-
o.send_message "run"
|
40
|
-
end
|
38
|
+
o.send_message 'run' if o.can_receive_message? 'run'
|
41
39
|
end
|
42
40
|
end
|
43
|
-
|
41
|
+
|
44
42
|
end
|
45
43
|
end
|
46
44
|
end
|
data/lib/gloo/core/factory.rb
CHANGED
@@ -7,61 +7,114 @@
|
|
7
7
|
module Gloo
|
8
8
|
module Core
|
9
9
|
class Factory < Baseo
|
10
|
-
|
10
|
+
|
11
|
+
# ---------------------------------------------------------------------
|
12
|
+
# Initializer
|
13
|
+
# ---------------------------------------------------------------------
|
14
|
+
|
15
|
+
#
|
11
16
|
# Set up the object factory.
|
12
|
-
|
13
|
-
|
17
|
+
#
|
18
|
+
def initialize
|
19
|
+
$log.debug 'object factory intialized...'
|
14
20
|
end
|
15
|
-
|
21
|
+
|
22
|
+
# ---------------------------------------------------------------------
|
23
|
+
# Factory Helpers
|
24
|
+
# ---------------------------------------------------------------------
|
25
|
+
|
26
|
+
# Helper shortcut to create a string.
|
27
|
+
def create_string( name, value, parent )
|
28
|
+
params = { :name => name,
|
29
|
+
:type => 'string',
|
30
|
+
:value => value,
|
31
|
+
:parent => parent }
|
32
|
+
create params
|
33
|
+
end
|
34
|
+
|
35
|
+
# ---------------------------------------------------------------------
|
36
|
+
# Object Factory
|
37
|
+
# ---------------------------------------------------------------------
|
38
|
+
|
16
39
|
# Create object with given name, type and value.
|
17
40
|
# One of either name or type is required.
|
18
41
|
# All values are optional when considered on their own.
|
19
|
-
|
20
|
-
|
21
|
-
|
42
|
+
# Parameter hash keys:
|
43
|
+
# :name - the name of the object
|
44
|
+
# :type - the name of the type
|
45
|
+
# :value - the initial object value
|
46
|
+
# :parent - the parent object
|
47
|
+
# :squash_duplicates - if the object exists, use it rather
|
48
|
+
# than creating a new one? Default = true
|
49
|
+
def create( params )
|
50
|
+
objtype = find_type params[ :type ]
|
51
|
+
return nil unless objtype
|
52
|
+
|
53
|
+
pn = Gloo::Core::Pn.new params[ :name ]
|
54
|
+
parent = params[ :parent ]
|
22
55
|
if parent.nil?
|
23
56
|
parent = pn.get_parent
|
24
57
|
obj_name = pn.name
|
25
58
|
else
|
26
|
-
obj_name = name
|
59
|
+
obj_name = params[ :name ]
|
27
60
|
end
|
28
61
|
|
29
|
-
if
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
parent.add_child( o )
|
45
|
-
return o
|
46
|
-
else
|
47
|
-
$log.error "Could not create object. Bad path: #{name}"
|
48
|
-
return nil
|
49
|
-
end
|
50
|
-
end
|
51
|
-
else
|
52
|
-
$log.warn "Could not find type, '#{type}'"
|
62
|
+
if pn.exists? && params[ :squash_duplicates ]
|
63
|
+
$log.debug "Updating existing object: #{name}"
|
64
|
+
return self.update_existing pn, params[ :value ]
|
65
|
+
end
|
66
|
+
|
67
|
+
$log.debug "Creating new object: #{name}"
|
68
|
+
return create_new obj_name, params[ :value ], objtype, parent
|
69
|
+
end
|
70
|
+
|
71
|
+
#
|
72
|
+
# Create a new object.
|
73
|
+
#
|
74
|
+
def create_new( name, value, type, parent )
|
75
|
+
unless parent
|
76
|
+
$log.error "Could not create object. Bad path: #{name}"
|
53
77
|
return nil
|
54
|
-
end
|
78
|
+
end
|
79
|
+
|
80
|
+
o = type.new
|
81
|
+
o.name = name
|
82
|
+
o.set_value value
|
83
|
+
parent.add_child( o )
|
84
|
+
return o
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# Find and Update an existing object.
|
89
|
+
#
|
90
|
+
def update_existing( pn, value )
|
91
|
+
o = pn.resolve
|
92
|
+
o.set_value value
|
93
|
+
return o
|
55
94
|
end
|
56
|
-
|
95
|
+
|
96
|
+
#
|
57
97
|
# Find the object type by name.
|
58
|
-
|
59
|
-
|
60
|
-
|
98
|
+
# Return nil if the object type cannot be found or
|
99
|
+
# cannot be created.
|
100
|
+
#
|
101
|
+
def find_type( type_name )
|
102
|
+
type_name = 'untyped' if type_name.nil? || type_name.strip.empty?
|
103
|
+
t = $engine.dictionary.find_obj( type_name )
|
104
|
+
|
105
|
+
if t.nil?
|
106
|
+
$log.warn "Could not find type, '#{type_name}'"
|
107
|
+
return nil
|
108
|
+
end
|
109
|
+
|
110
|
+
unless t.can_create?
|
111
|
+
$log.error "'#{type_name}' cannot be created."
|
112
|
+
return nil
|
61
113
|
end
|
62
|
-
|
114
|
+
|
115
|
+
return t
|
63
116
|
end
|
64
|
-
|
117
|
+
|
65
118
|
end
|
66
119
|
end
|
67
120
|
end
|
@@ -10,42 +10,40 @@
|
|
10
10
|
module Gloo
|
11
11
|
module Core
|
12
12
|
class GlooSystem < Obj
|
13
|
-
|
14
|
-
KEYWORD = 'gloo'
|
15
|
-
KEYWORD_SHORT = '$'
|
16
|
-
|
17
|
-
attr_reader :pn
|
18
13
|
|
14
|
+
KEYWORD = 'gloo'.freeze
|
15
|
+
KEYWORD_SHORT = '$'.freeze
|
16
|
+
|
17
|
+
attr_reader :pn
|
19
18
|
|
20
19
|
# Set up the object.
|
21
20
|
def initialize( pn )
|
22
21
|
@pn = pn
|
23
22
|
end
|
24
|
-
|
25
|
-
#
|
23
|
+
|
24
|
+
#
|
26
25
|
# The name of the object type.
|
27
|
-
#
|
26
|
+
#
|
28
27
|
def self.typename
|
29
28
|
return KEYWORD
|
30
29
|
end
|
31
30
|
|
32
|
-
#
|
31
|
+
#
|
33
32
|
# The short name of the object type.
|
34
|
-
#
|
33
|
+
#
|
35
34
|
def self.short_typename
|
36
35
|
return KEYWORD_SHORT
|
37
36
|
end
|
38
37
|
|
39
|
-
#
|
38
|
+
#
|
40
39
|
# The object type, suitable for display.
|
41
|
-
#
|
40
|
+
#
|
42
41
|
def type_display
|
43
42
|
return self.class.typename
|
44
43
|
end
|
45
44
|
|
46
|
-
|
47
45
|
# Is this the root object?
|
48
|
-
def
|
46
|
+
def root?
|
49
47
|
return false
|
50
48
|
end
|
51
49
|
|
@@ -56,61 +54,61 @@ module Gloo
|
|
56
54
|
false
|
57
55
|
end
|
58
56
|
|
59
|
-
|
60
57
|
# ---------------------------------------------------------------------
|
61
58
|
# Value
|
62
59
|
# ---------------------------------------------------------------------
|
63
60
|
|
64
|
-
#
|
61
|
+
#
|
65
62
|
# Get the parameter.
|
66
|
-
#
|
63
|
+
#
|
67
64
|
def param
|
68
65
|
return nil unless @pn && @pn.segments.count > 1
|
69
|
-
|
66
|
+
|
67
|
+
return @pn.segments[ 1..-1 ].join( '_' )
|
70
68
|
end
|
71
|
-
|
69
|
+
|
72
70
|
#
|
73
71
|
# Get the system value.
|
74
|
-
#
|
72
|
+
#
|
75
73
|
def value
|
76
74
|
return dispatch param
|
77
75
|
end
|
78
|
-
|
79
|
-
#
|
76
|
+
|
77
|
+
#
|
80
78
|
# There is no value object in the system.
|
81
|
-
#
|
82
|
-
def set_value new_value
|
79
|
+
#
|
80
|
+
def set_value( new_value )
|
81
|
+
# overriding base functionality with dummy function
|
83
82
|
end
|
84
|
-
|
85
|
-
#
|
83
|
+
|
84
|
+
#
|
86
85
|
# Get the value for display purposes.
|
87
|
-
#
|
86
|
+
#
|
88
87
|
def value_display
|
89
88
|
return value
|
90
89
|
end
|
91
|
-
|
92
|
-
#
|
90
|
+
|
91
|
+
#
|
93
92
|
# Is the value a String?
|
94
|
-
#
|
95
|
-
def
|
93
|
+
#
|
94
|
+
def value_string?
|
96
95
|
return true
|
97
96
|
end
|
98
97
|
|
99
|
-
#
|
98
|
+
#
|
100
99
|
# Is the value an Array?
|
101
|
-
#
|
100
|
+
#
|
102
101
|
def value_is_array?
|
103
102
|
return false
|
104
103
|
end
|
105
|
-
|
106
|
-
#
|
104
|
+
|
105
|
+
#
|
107
106
|
# Is the value a blank string?
|
108
|
-
#
|
107
|
+
#
|
109
108
|
def value_is_blank?
|
110
109
|
return true
|
111
110
|
end
|
112
111
|
|
113
|
-
|
114
112
|
# ---------------------------------------------------------------------
|
115
113
|
# Children
|
116
114
|
# ---------------------------------------------------------------------
|
@@ -122,34 +120,31 @@ module Gloo
|
|
122
120
|
return false
|
123
121
|
end
|
124
122
|
|
125
|
-
|
126
123
|
# ---------------------------------------------------------------------
|
127
124
|
# Messages
|
128
125
|
# ---------------------------------------------------------------------
|
129
126
|
|
130
|
-
#
|
127
|
+
#
|
131
128
|
# Get a list of message names that this object receives.
|
132
|
-
#
|
129
|
+
#
|
133
130
|
def self.messages
|
134
131
|
return []
|
135
132
|
end
|
136
|
-
|
133
|
+
|
137
134
|
# Dispatch the message and get the value.
|
138
|
-
def dispatch msg
|
135
|
+
def dispatch( msg )
|
139
136
|
o = "msg_#{msg}"
|
140
|
-
if self.respond_to? o
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
end
|
147
|
-
|
137
|
+
return self.public_send( o ) if self.respond_to? o
|
138
|
+
|
139
|
+
$log.error "Message #{msg} not implemented"
|
140
|
+
return false
|
141
|
+
end
|
142
|
+
|
148
143
|
# Get the system hostname.
|
149
144
|
def msg_hostname
|
150
145
|
return Socket.gethostname
|
151
146
|
end
|
152
|
-
|
147
|
+
|
153
148
|
# Get the logged in User.
|
154
149
|
def msg_user
|
155
150
|
return ENV[ 'USER' ]
|
@@ -157,14 +152,14 @@ module Gloo
|
|
157
152
|
|
158
153
|
# Get the user's home directory.
|
159
154
|
def msg_user_home
|
160
|
-
return File.expand_path(
|
155
|
+
return File.expand_path( '~' )
|
161
156
|
end
|
162
157
|
|
163
|
-
|
158
|
+
# Get the working directory.
|
164
159
|
def msg_working_dir
|
165
160
|
return Dir.pwd
|
166
161
|
end
|
167
|
-
|
162
|
+
|
168
163
|
# Get the Gloo home directory
|
169
164
|
def msg_gloo_home
|
170
165
|
return $settings.user_root
|
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
|