gloo 0.3.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.
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,101 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # A dictionary of Objects and Verbs.
5
+ #
6
+ require 'singleton'
7
+
8
+ module Gloo
9
+ module Core
10
+ class Dictionary
11
+
12
+ include Singleton
13
+
14
+ attr_reader :verbs, :objs
15
+
16
+ # Set up the object dictionary.
17
+ def initialize()
18
+ @verbs = {}
19
+ @objs = {}
20
+ @verb_references = []
21
+ @obj_references = []
22
+ end
23
+
24
+ # Register a verb.
25
+ def register_verb subclass
26
+ @verb_references << subclass
27
+ end
28
+
29
+ # Register an object type.
30
+ def register_obj subclass
31
+ @obj_references << subclass
32
+ end
33
+
34
+ # Initialize verbs and objects in the dictionary.
35
+ def init
36
+ $log.debug "initializing dictionaries"
37
+ init_verbs
38
+ init_objs
39
+ end
40
+
41
+ # Init the list of verbs.
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
+
51
+ # Is the given word an object type?
52
+ def is_obj? word
53
+ return false unless word
54
+ return @objs.key?( word.downcase )
55
+ end
56
+
57
+ # Find the object type by name.
58
+ def find_obj word
59
+ return nil unless word
60
+ return nil unless is_obj?( word )
61
+ return @objs[ word.downcase ]
62
+ end
63
+
64
+
65
+ # Init the list of verbs.
66
+ def init_verbs
67
+ $log.debug "initializing #{@verb_references.count} verbs"
68
+ @verb_references.each do |v|
69
+ $log.debug v
70
+ @verbs[ v.keyword ] = v
71
+ @verbs[ v.keyword_shortcut ] = v
72
+ # v.send( :new ).run
73
+ end
74
+ end
75
+
76
+ # Is the given word a verb?
77
+ def is_verb? word
78
+ return false unless word
79
+ return @verbs.key?( word.downcase )
80
+ end
81
+
82
+ # Find the verb by name.
83
+ def find_verb verb
84
+ return nil unless verb
85
+ return nil unless is_verb?( verb )
86
+ return @verbs[ verb.downcase ]
87
+ end
88
+
89
+ # Get the list of verbs, sorted.
90
+ def get_obj_types
91
+ return @obj_references.sort{ |a,b| a.typename <=> b.typename }
92
+ end
93
+
94
+ # Get the list of verbs, sorted.
95
+ def get_verbs
96
+ return @verb_references.sort{ |a,b| a.keyword <=> b.keyword }
97
+ end
98
+
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,46 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # The Event Manager.
5
+ # Run scripts in response to pre-defined events.
6
+ #
7
+
8
+ module Gloo
9
+ module Core
10
+ class EventManager
11
+
12
+ # Set up the event manager.
13
+ def initialize()
14
+ $log.debug "event manager intialized..."
15
+ end
16
+
17
+ #
18
+ # Run on_load scripts in the recently loaded object
19
+ # If no obj is given the script will be run in root.
20
+ #
21
+ def on_load obj=nil, in_heap=false
22
+ return unless obj || in_heap
23
+ arr = Gloo::Core::ObjFinder.by_name "on_load", obj
24
+ arr.each do |o|
25
+ if o.can_receive_message? "run"
26
+ o.send_message "run"
27
+ end
28
+ end
29
+ end
30
+
31
+ #
32
+ # Run on_unload scripts in the object that will be unloaded.
33
+ #
34
+ def on_unload obj
35
+ return unless obj
36
+ arr = Gloo::Core::ObjFinder.by_name "on_unload", obj
37
+ arr.each do |o|
38
+ if o.can_receive_message? "run"
39
+ o.send_message "run"
40
+ end
41
+ end
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,67 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # An object factory.
5
+ #
6
+
7
+ module Gloo
8
+ module Core
9
+ class Factory < Baseo
10
+
11
+ # Set up the object factory.
12
+ def initialize()
13
+ $log.debug "object factory intialized..."
14
+ end
15
+
16
+ # Create object with given name, type and value.
17
+ # One of either name or type is required.
18
+ # All values are optional when considered on their own.
19
+ def create name=nil, type=nil, value=nil, parent=nil, squash_dups=true
20
+ objtype = find_type( type )
21
+ pn = Gloo::Core::Pn.new name
22
+ if parent.nil?
23
+ parent = pn.get_parent
24
+ obj_name = pn.name
25
+ else
26
+ obj_name = name
27
+ end
28
+
29
+ if objtype
30
+ unless objtype.can_create?
31
+ $log.error "'#{type}' cannot be created."
32
+ return nil
33
+ end
34
+ if pn.exists? && squash_dups
35
+ o = pn.resolve
36
+ o.set_value value
37
+ return o
38
+ else
39
+ o = objtype.new
40
+ o.name = obj_name
41
+ o.set_value value
42
+
43
+ if parent
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}'"
53
+ return nil
54
+ end
55
+ end
56
+
57
+ # Find the object type by name.
58
+ def find_type type_name
59
+ if type_name.nil? || type_name.strip.empty?
60
+ type_name = "untyped"
61
+ end
62
+ return $engine.dictionary.find_obj( type_name )
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,190 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # The System Object.
5
+ # A virtual Object: the system object can be used to access
6
+ # system level variables and functions. But it is not
7
+ # actually an object in the normal sense of the word.
8
+ #
9
+
10
+ module Gloo
11
+ module Core
12
+ class GlooSystem < Obj
13
+
14
+ KEYWORD = 'gloo'
15
+ KEYWORD_SHORT = '$'
16
+
17
+ attr_reader :pn
18
+
19
+
20
+ # Set up the object.
21
+ def initialize( pn )
22
+ @pn = pn
23
+ end
24
+
25
+ #
26
+ # The name of the object type.
27
+ #
28
+ def self.typename
29
+ return KEYWORD
30
+ end
31
+
32
+ #
33
+ # The short name of the object type.
34
+ #
35
+ def self.short_typename
36
+ return KEYWORD_SHORT
37
+ end
38
+
39
+ #
40
+ # The object type, suitable for display.
41
+ #
42
+ def type_display
43
+ return self.class.typename
44
+ end
45
+
46
+
47
+ # Is this the root object?
48
+ def is_root?
49
+ return false
50
+ end
51
+
52
+ # Can this object be created?
53
+ # This is true by default and only false for some special cases
54
+ # such as the System object.
55
+ def self.can_create?
56
+ false
57
+ end
58
+
59
+
60
+ # ---------------------------------------------------------------------
61
+ # Value
62
+ # ---------------------------------------------------------------------
63
+
64
+ #
65
+ # Get the parameter.
66
+ #
67
+ def param
68
+ return nil unless @pn && @pn.segments.count > 1
69
+ return @pn.segments[1..-1].join( "_" )
70
+ end
71
+
72
+ #
73
+ # Get the system value.
74
+ #
75
+ def value
76
+ return dispatch param
77
+ end
78
+
79
+ #
80
+ # There is no value object in the system.
81
+ #
82
+ def set_value new_value
83
+ end
84
+
85
+ #
86
+ # Get the value for display purposes.
87
+ #
88
+ def value_display
89
+ return value
90
+ end
91
+
92
+ #
93
+ # Is the value a String?
94
+ #
95
+ def value_is_string?
96
+ return true
97
+ end
98
+
99
+ #
100
+ # Is the value an Array?
101
+ #
102
+ def value_is_array?
103
+ return false
104
+ end
105
+
106
+ #
107
+ # Is the value a blank string?
108
+ #
109
+ def value_is_blank?
110
+ return true
111
+ end
112
+
113
+
114
+ # ---------------------------------------------------------------------
115
+ # Children
116
+ # ---------------------------------------------------------------------
117
+
118
+ # Does this object have children to add when an object
119
+ # is created in interactive mode?
120
+ # This does not apply during obj load, etc.
121
+ def add_children_on_create?
122
+ return false
123
+ end
124
+
125
+
126
+ # ---------------------------------------------------------------------
127
+ # Messages
128
+ # ---------------------------------------------------------------------
129
+
130
+ #
131
+ # Get a list of message names that this object receives.
132
+ #
133
+ def self.messages
134
+ return []
135
+ end
136
+
137
+ # Dispatch the message and get the value.
138
+ def dispatch msg
139
+ o = "msg_#{msg}"
140
+ if self.respond_to? o
141
+ return self.public_send( o )
142
+ else
143
+ $log.error "Message #{msg} not implemented"
144
+ return false
145
+ end
146
+ end
147
+
148
+ # Get the system hostname.
149
+ def msg_hostname
150
+ return Socket.gethostname
151
+ end
152
+
153
+ # Get the logged in User.
154
+ def msg_user
155
+ return ENV[ 'USER' ]
156
+ end
157
+
158
+ # Get the user's home directory.
159
+ def msg_user_home
160
+ return File.expand_path( "~" )
161
+ end
162
+
163
+ # Get the working directory.
164
+ def msg_working_dir
165
+ return Dir.pwd
166
+ end
167
+
168
+ # Get the Gloo home directory
169
+ def msg_gloo_home
170
+ return $settings.user_root
171
+ end
172
+
173
+ # Get the Gloo home directory
174
+ def msg_gloo_config
175
+ return $settings.config_path
176
+ end
177
+
178
+ # Get the Gloo projects directory
179
+ def msg_gloo_projects
180
+ return $settings.project_path
181
+ end
182
+
183
+ # Get the Gloo log directory
184
+ def msg_gloo_log
185
+ return $settings.log_path
186
+ end
187
+
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,42 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
3
+ #
4
+ # The Object Heap.
5
+ # The collection of objects that are currently in play in
6
+ # the running engine.
7
+ #
8
+
9
+ module Gloo
10
+ module Core
11
+ class Heap
12
+
13
+ # The context is a reference to an object, usually a container.
14
+ # The context will be the root by default.
15
+ attr_reader :context
16
+
17
+ # TODO: Do I need a running script context?
18
+ # how to resolve relative reference.
19
+
20
+ attr_reader :it, :root
21
+
22
+ # Set up the object heap.
23
+ def initialize()
24
+ $log.debug "object heap intialized..."
25
+
26
+ @root = Gloo::Objs::Container.new
27
+ @root.name = "root"
28
+
29
+ @context = Pn.root
30
+ @it = It.new
31
+ end
32
+
33
+ # Unload the given obj--remove it from the heap.
34
+ def unload obj
35
+ can = obj.parent.nil? ? @root : obj.parent
36
+ return unless can
37
+ can.remove_child obj
38
+ end
39
+
40
+ end
41
+ end
42
+ end