gloo 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +5 -0
  4. data/CODE_OF_CONDUCT.md +74 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +139 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +43 -0
  9. data/Rakefile +12 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/exe/gloo +4 -0
  13. data/exe/o +4 -0
  14. data/gloo.gemspec +38 -0
  15. data/lib/gloo.rb +19 -0
  16. data/lib/gloo/app/args.rb +71 -0
  17. data/lib/gloo/app/engine.rb +158 -0
  18. data/lib/gloo/app/help.rb +29 -0
  19. data/lib/gloo/app/info.rb +21 -0
  20. data/lib/gloo/app/log.rb +58 -0
  21. data/lib/gloo/app/mode.rb +25 -0
  22. data/lib/gloo/app/settings.rb +125 -0
  23. data/lib/gloo/core/baseo.rb +28 -0
  24. data/lib/gloo/core/dictionary.rb +101 -0
  25. data/lib/gloo/core/event_manager.rb +46 -0
  26. data/lib/gloo/core/factory.rb +67 -0
  27. data/lib/gloo/core/gloo_system.rb +190 -0
  28. data/lib/gloo/core/heap.rb +42 -0
  29. data/lib/gloo/core/it.rb +30 -0
  30. data/lib/gloo/core/literal.rb +25 -0
  31. data/lib/gloo/core/obj.rb +222 -0
  32. data/lib/gloo/core/obj_finder.rb +35 -0
  33. data/lib/gloo/core/op.rb +33 -0
  34. data/lib/gloo/core/parser.rb +52 -0
  35. data/lib/gloo/core/pn.rb +134 -0
  36. data/lib/gloo/core/script.rb +37 -0
  37. data/lib/gloo/core/tokens.rb +123 -0
  38. data/lib/gloo/core/verb.rb +63 -0
  39. data/lib/gloo/expr/expression.rb +103 -0
  40. data/lib/gloo/expr/l_boolean.rb +29 -0
  41. data/lib/gloo/expr/l_integer.rb +29 -0
  42. data/lib/gloo/expr/l_string.rb +53 -0
  43. data/lib/gloo/expr/op_div.rb +20 -0
  44. data/lib/gloo/expr/op_minus.rb +20 -0
  45. data/lib/gloo/expr/op_mult.rb +20 -0
  46. data/lib/gloo/expr/op_plus.rb +22 -0
  47. data/lib/gloo/objs/basic/boolean.rb +113 -0
  48. data/lib/gloo/objs/basic/container.rb +50 -0
  49. data/lib/gloo/objs/basic/integer.rb +65 -0
  50. data/lib/gloo/objs/basic/script.rb +101 -0
  51. data/lib/gloo/objs/basic/string.rb +65 -0
  52. data/lib/gloo/objs/basic/text.rb +64 -0
  53. data/lib/gloo/objs/basic/untyped.rb +42 -0
  54. data/lib/gloo/objs/cli/colorize.rb +73 -0
  55. data/lib/gloo/objs/cli/confirm.rb +92 -0
  56. data/lib/gloo/objs/cli/prompt.rb +92 -0
  57. data/lib/gloo/objs/ctrl/each.rb +212 -0
  58. data/lib/gloo/objs/dev/git.rb +112 -0
  59. data/lib/gloo/objs/ror/erb.rb +109 -0
  60. data/lib/gloo/objs/ror/eval.rb +92 -0
  61. data/lib/gloo/objs/system/file_handle.rb +86 -0
  62. data/lib/gloo/objs/system/system.rb +120 -0
  63. data/lib/gloo/objs/web/http_get.rb +128 -0
  64. data/lib/gloo/objs/web/http_post.rb +127 -0
  65. data/lib/gloo/objs/web/slack.rb +126 -0
  66. data/lib/gloo/objs/web/teams.rb +117 -0
  67. data/lib/gloo/persist/file_loader.rb +171 -0
  68. data/lib/gloo/persist/file_saver.rb +43 -0
  69. data/lib/gloo/persist/file_storage.rb +43 -0
  70. data/lib/gloo/persist/persist_man.rb +90 -0
  71. data/lib/gloo/utils/words.rb +19 -0
  72. data/lib/gloo/verbs/alert.rb +42 -0
  73. data/lib/gloo/verbs/context.rb +52 -0
  74. data/lib/gloo/verbs/create.rb +52 -0
  75. data/lib/gloo/verbs/help.rb +69 -0
  76. data/lib/gloo/verbs/if.rb +56 -0
  77. data/lib/gloo/verbs/list.rb +85 -0
  78. data/lib/gloo/verbs/load.rb +39 -0
  79. data/lib/gloo/verbs/put.rb +62 -0
  80. data/lib/gloo/verbs/quit.rb +40 -0
  81. data/lib/gloo/verbs/run.rb +46 -0
  82. data/lib/gloo/verbs/save.rb +37 -0
  83. data/lib/gloo/verbs/show.rb +55 -0
  84. data/lib/gloo/verbs/tell.rb +47 -0
  85. data/lib/gloo/verbs/unless.rb +56 -0
  86. data/lib/gloo/verbs/version.rb +37 -0
  87. data/lib/run.rb +13 -0
  88. metadata +254 -0
@@ -0,0 +1,30 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # It is the value of the last command that was run.
5
+ #
6
+
7
+ module Gloo
8
+ module Core
9
+ class It
10
+
11
+ attr_accessor :value
12
+
13
+ # Set up the object.
14
+ def initialize()
15
+ @value = nil
16
+ end
17
+
18
+ # Set the value of it.
19
+ def set_to new_value
20
+ @value = new_value
21
+ end
22
+
23
+ # Get the string representation of it.
24
+ def to_s
25
+ return @value.to_s
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # A Literal value.
5
+ #
6
+
7
+ module Gloo
8
+ module Core
9
+ class Literal
10
+
11
+ attr_reader :value
12
+
13
+ # Create the expression from a list of tokens.
14
+ def initialize value
15
+ set_value( value )
16
+ end
17
+
18
+ # Set the literal value.
19
+ def set_value value
20
+ @value = value
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,222 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An data/value object.
5
+ # Derives from the Baseo object. Is not a verb.
6
+ #
7
+
8
+ module Gloo
9
+ module Core
10
+ class Obj < Baseo
11
+
12
+ attr_accessor :value
13
+ attr_reader :children, :parent
14
+
15
+ # Set up the object.
16
+ def initialize()
17
+ @value = ""
18
+ @children = []
19
+ @parent = nil
20
+ end
21
+
22
+ # Register object types when they are loaded.
23
+ def self.inherited( subclass )
24
+ Dictionary.instance.register_obj( subclass )
25
+ end
26
+
27
+ #
28
+ # The name of the object type.
29
+ #
30
+ def self.typename
31
+ raise 'this method should be overriden'
32
+ end
33
+
34
+ #
35
+ # The object type, suitable for display.
36
+ #
37
+ def type_display
38
+ return self.class.typename
39
+ end
40
+
41
+ #
42
+ # Set the parent for the object.
43
+ #
44
+ def set_parent obj
45
+ @parent = obj
46
+ end
47
+
48
+ # Is this the root object?
49
+ def is_root?
50
+ return false if @parent
51
+ return false unless name.downcase == "root"
52
+ return true
53
+ end
54
+
55
+ # Can this object be created?
56
+ # This is true by default and only false for some special cases
57
+ # such as the System object.
58
+ def self.can_create?
59
+ true
60
+ end
61
+
62
+
63
+ # ---------------------------------------------------------------------
64
+ # Value
65
+ # ---------------------------------------------------------------------
66
+
67
+ #
68
+ # Set the value with any necessary type conversions.
69
+ #
70
+ def set_value new_value
71
+ self.value = new_value
72
+ end
73
+
74
+ #
75
+ # Get the value for display purposes.
76
+ #
77
+ def value_display
78
+ return self.value.to_s
79
+ end
80
+
81
+ #
82
+ # Does this object support multi-line values?
83
+ # Initially only true for scripts.
84
+ #
85
+ def has_multiline_value?
86
+ return false
87
+ end
88
+
89
+ #
90
+ # Is the value a String?
91
+ #
92
+ def value_is_string?
93
+ return self.value.is_a? String
94
+ end
95
+
96
+ #
97
+ # Is the value an Array?
98
+ #
99
+ def value_is_array?
100
+ return self.value.is_a? Array
101
+ end
102
+
103
+ #
104
+ # Is the value a blank string?
105
+ #
106
+ def value_is_blank?
107
+ return true if value.nil?
108
+ return self.value.to_s.strip.empty?
109
+ end
110
+
111
+
112
+ # ---------------------------------------------------------------------
113
+ # Children
114
+ # ---------------------------------------------------------------------
115
+
116
+ # Add a child object to the container.
117
+ def add_child obj
118
+ @children << obj
119
+ obj.set_parent self
120
+ end
121
+
122
+ # Get the number of children.
123
+ def child_count
124
+ return @children.count
125
+ end
126
+
127
+ # Does this object contain an object with the given name?
128
+ def has_child? name
129
+ @children.each do |o|
130
+ return true if ( name.downcase == o.name.downcase )
131
+ end
132
+ return false
133
+ end
134
+
135
+ # Find a child object with the given name.
136
+ def find_child name
137
+ @children.each do |o|
138
+ return o if ( name.downcase == o.name.downcase )
139
+ end
140
+ return nil
141
+ end
142
+
143
+ # Remove the object from the children collection.
144
+ def remove_child obj
145
+ @children.delete obj
146
+ end
147
+
148
+ # Does this object have children to add when an object
149
+ # is created in interactive mode?
150
+ # This does not apply during obj load, etc.
151
+ def add_children_on_create?
152
+ return false
153
+ end
154
+
155
+ # Add children to this object.
156
+ # This is used by containers to add children needed
157
+ # for default configurations.
158
+ def add_default_children
159
+ end
160
+
161
+
162
+ # ---------------------------------------------------------------------
163
+ # Messages
164
+ # ---------------------------------------------------------------------
165
+
166
+ #
167
+ # Get a list of message names that this object receives.
168
+ #
169
+ def self.messages
170
+ return [ "unload" ]
171
+ end
172
+
173
+ #
174
+ # Can this object receive a message?
175
+ #
176
+ def can_receive_message? msg
177
+ msgs = self.class.messages
178
+ return msgs.include?( msg.strip.downcase )
179
+ end
180
+
181
+ #
182
+ # Sent this object the given message.
183
+ #
184
+ def send_message msg, params=nil
185
+ @params = params
186
+ if self.can_receive_message? msg
187
+ return self.dispatch msg
188
+ else
189
+ $log.error "Object #{self.name} cannot receive message #{msg}"
190
+ return false
191
+ end
192
+ end
193
+
194
+ #
195
+ # Dispatch the message to the object.
196
+ #
197
+ def dispatch msg
198
+ o = "msg_#{msg}"
199
+ if self.respond_to? o
200
+ self.public_send( o )
201
+ return true
202
+ else
203
+ $log.error "Message #{msg} not implemented"
204
+ return false
205
+ end
206
+ end
207
+
208
+ #
209
+ # Send the object the unload message.
210
+ #
211
+ def msg_unload
212
+ if self.is_root?
213
+ $log.error "Cannot unload the root object."
214
+ return
215
+ end
216
+ $engine.event_manager.on_unload self
217
+ $engine.heap.unload self
218
+ end
219
+
220
+ end
221
+ end
222
+ end
@@ -0,0 +1,35 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # Utility used to find objects.
5
+ #
6
+
7
+ module Gloo
8
+ module Core
9
+ class ObjFinder
10
+
11
+ #
12
+ # Find all objects in the given container that have
13
+ # the given name.
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
20
+ arr = []
21
+
22
+ container.children.each do |o|
23
+ arr << o if o.name == name
24
+ if o.child_count > 0
25
+ arr += by_name( name, o )
26
+ end
27
+ end
28
+
29
+ return arr
30
+ end
31
+
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,33 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An Operator; part of an expression.
5
+ #
6
+
7
+ module Gloo
8
+ module Core
9
+ class Op
10
+
11
+ # Is the token an operator?
12
+ def self.is_op? token
13
+ return [ "+", "-", "*", "/" ].include?( token.strip )
14
+ end
15
+
16
+ # Create the operator for the given token.
17
+ def self.create_op token
18
+ return Gloo::Expr::OpMinus.new if token == '-'
19
+ return Gloo::Expr::OpMult.new if token == '*'
20
+ return Gloo::Expr::OpDiv.new if token == '/'
21
+ return Gloo::Expr::OpPlus.new if token == '+'
22
+
23
+ return default_op
24
+ end
25
+
26
+ # Get the default operator (+).
27
+ def self.default_op
28
+ return Gloo::Expr::OpPlus.new
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,52 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # The Parser.
5
+ # Can parse single line commands or files.
6
+ #
7
+
8
+ module Gloo
9
+ module Core
10
+ class Parser
11
+
12
+ # Set up the parser.
13
+ def initialize()
14
+ $log.debug "parser intialized..."
15
+ end
16
+
17
+
18
+ # Parse a command from the immediate execution context.
19
+ def parse_immediate cmd
20
+ cmd, params = split_params cmd
21
+ params = Gloo::Core::Tokens.new( params ) if params
22
+ tokens = Gloo::Core::Tokens.new( cmd )
23
+ dic = Gloo::Core::Dictionary.instance
24
+ verb = dic.find_verb( tokens.verb )
25
+ return verb.new( tokens, params ) if verb
26
+
27
+ $log.error "Verb '#{tokens.verb}' was not found."
28
+ return nil
29
+ end
30
+
31
+ # If additional params were provided, split them out
32
+ # from the token list.
33
+ def split_params cmd
34
+ params = nil
35
+ i = cmd.rindex( '(' )
36
+ if i && cmd.strip.end_with?( ')' )
37
+ pstr = cmd[i+1..-1]
38
+ params = pstr.strip[0..-2] if pstr
39
+ cmd = cmd[ 0, i-1]
40
+ end
41
+ return cmd, params
42
+ end
43
+
44
+ # Parse a command and then run it if it parsed correctly.
45
+ def run cmd
46
+ v = parse_immediate( cmd )
47
+ v.run if v
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,134 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An object path name.
5
+ # Path and name elements are separated by periods.
6
+ #
7
+
8
+ module Gloo
9
+ module Core
10
+ class Pn < Baseo
11
+
12
+ attr_reader :src, :elements
13
+
14
+ # Set up the object given a source string,
15
+ # ie: the full path and name.
16
+ def initialize( src )
17
+ set_to src
18
+ end
19
+
20
+ # Reference to the root object path.
21
+ def self.root
22
+ return Pn.new( "root" )
23
+ end
24
+
25
+ # Reference to it.
26
+ def self.it
27
+ return Pn.new( "it" )
28
+ end
29
+
30
+ # Does the pathname reference refer to the root?
31
+ def is_root?
32
+ return @src.downcase == "root"
33
+ end
34
+
35
+ # Does the pathname reference refer to the root?
36
+ def is_it?
37
+ return @src.downcase == "it"
38
+ end
39
+
40
+ # Does the pathname reference refer to the gloo system object?
41
+ def is_gloo_sys?
42
+ return false unless @elements && @elements.count > 0
43
+ o = @elements.first.downcase
44
+ return true if o == Gloo::Core::GlooSystem.typename
45
+ return true if o == Gloo::Core::GlooSystem.short_typename
46
+ return false
47
+ end
48
+
49
+ # Get the string representation of the pathname.
50
+ def to_s
51
+ return @src
52
+ end
53
+
54
+ # Set the object pathname to the given value.
55
+ def set_to value
56
+ @src = value.strip unless value.nil?
57
+ if @src.nil?
58
+ @elements = []
59
+ else
60
+ @elements = @src.split( '.' )
61
+ end
62
+ end
63
+
64
+ # Convert the raw string to a list of segments.
65
+ def segments
66
+ return @elements
67
+ end
68
+
69
+ # Get the name element.
70
+ def name
71
+ return "" unless self.has_name?
72
+ return @elements.last
73
+ end
74
+
75
+ # Does the value include path elements?
76
+ def has_name?
77
+ return @elements.count > 0
78
+ end
79
+
80
+ # Does the value include a name?
81
+ def has_path?
82
+ return @elements.count > 1
83
+ end
84
+
85
+ # Get the parent that contains the object referenced.
86
+ def get_parent
87
+ o = $engine.heap.root
88
+
89
+ if self.has_path?
90
+ @elements[0..-2].each do |e|
91
+ o = o.find_child( e )
92
+ if o.nil?
93
+ $log.error "Object '#{e}' was not found."
94
+ return nil
95
+ end
96
+ end
97
+ end
98
+
99
+ return o
100
+ end
101
+
102
+ # Does the object at the path exist?
103
+ def exists?
104
+ return true if self.is_root?
105
+ return true if self.is_it?
106
+
107
+ parent = self.get_parent
108
+ return false unless parent
109
+ return parent.has_child? name
110
+ end
111
+
112
+ # Is the reference to a color?
113
+ def is_color?
114
+ colors = [ "red", "blue", "green", "white", "black", "yellow" ]
115
+ return true if colors.include?( @src.downcase )
116
+ end
117
+
118
+ # Resolve the pathname reference.
119
+ # Find the object referenced or return nil if it is not found.
120
+ def resolve
121
+ return $engine.heap.root if self.is_root?
122
+ return $engine.heap.it if self.is_it?
123
+ if self.is_gloo_sys?
124
+ return Gloo::Core::GlooSystem.new( self )
125
+ end
126
+
127
+ parent = self.get_parent
128
+ return nil unless parent
129
+ return parent.find_child( self.name )
130
+ end
131
+
132
+ end
133
+ end
134
+ end