gloo 1.4.2 → 2.0.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 (131) hide show
  1. checksums.yaml +4 -4
  2. data/.DS_Store +0 -0
  3. data/.gitignore +1 -0
  4. data/gloo.gemspec +0 -2
  5. data/lib/VERSION +1 -1
  6. data/lib/dependencies.rb +4 -4
  7. data/lib/gloo/app/args.rb +112 -0
  8. data/lib/gloo/app/engine.rb +247 -0
  9. data/lib/gloo/app/engine_context.rb +25 -0
  10. data/lib/gloo/app/info.rb +20 -3
  11. data/lib/gloo/app/log.rb +73 -1
  12. data/lib/gloo/app/mode.rb +27 -0
  13. data/lib/gloo/app/platform.rb +8 -1
  14. data/lib/gloo/app/settings.rb +202 -0
  15. data/lib/gloo/convert/converter.rb +42 -0
  16. data/lib/gloo/convert/string_to_date.rb +21 -0
  17. data/lib/gloo/convert/string_to_datetime.rb +21 -0
  18. data/lib/gloo/convert/string_to_decimal.rb +20 -0
  19. data/lib/gloo/convert/string_to_integer.rb +20 -0
  20. data/lib/gloo/convert/string_to_time.rb +21 -0
  21. data/lib/gloo/core/baseo.rb +31 -0
  22. data/lib/gloo/core/dictionary.rb +245 -0
  23. data/lib/gloo/core/error.rb +61 -0
  24. data/lib/gloo/core/event_manager.rb +45 -0
  25. data/lib/gloo/core/factory.rb +211 -0
  26. data/lib/gloo/core/gloo_system.rb +267 -0
  27. data/lib/gloo/core/heap.rb +53 -0
  28. data/lib/gloo/core/here.rb +36 -0
  29. data/lib/gloo/core/it.rb +36 -0
  30. data/lib/gloo/core/literal.rb +30 -0
  31. data/lib/gloo/core/obj.rb +318 -0
  32. data/lib/gloo/core/obj_finder.rb +30 -0
  33. data/lib/gloo/core/op.rb +40 -0
  34. data/lib/gloo/core/parser.rb +60 -0
  35. data/lib/gloo/core/pn.rb +212 -0
  36. data/lib/gloo/core/tokens.rb +165 -0
  37. data/lib/gloo/core/verb.rb +87 -0
  38. data/lib/gloo/exec/action.rb +48 -0
  39. data/lib/gloo/exec/dispatch.rb +40 -0
  40. data/lib/gloo/exec/exec_env.rb +75 -0
  41. data/lib/gloo/exec/runner.rb +45 -0
  42. data/lib/gloo/exec/script.rb +50 -0
  43. data/lib/gloo/exec/stack.rb +79 -0
  44. data/lib/gloo/expr/expression.rb +119 -0
  45. data/lib/gloo/expr/l_boolean.rb +36 -0
  46. data/lib/gloo/expr/l_decimal.rb +39 -0
  47. data/lib/gloo/expr/l_integer.rb +37 -0
  48. data/lib/gloo/expr/l_string.rb +58 -0
  49. data/lib/gloo/expr/op_div.rb +22 -0
  50. data/lib/gloo/expr/op_minus.rb +22 -0
  51. data/lib/gloo/expr/op_mult.rb +22 -0
  52. data/lib/gloo/expr/op_plus.rb +24 -0
  53. data/lib/gloo/objs/basic/alias.rb +78 -0
  54. data/lib/gloo/objs/basic/boolean.rb +120 -0
  55. data/lib/gloo/objs/basic/container.rb +65 -0
  56. data/lib/gloo/objs/basic/decimal.rb +76 -0
  57. data/lib/gloo/objs/basic/integer.rb +73 -0
  58. data/lib/gloo/objs/basic/script.rb +99 -0
  59. data/lib/gloo/objs/basic/string.rb +77 -0
  60. data/lib/gloo/objs/basic/text.rb +79 -0
  61. data/lib/gloo/objs/basic/untyped.rb +41 -0
  62. data/lib/gloo/objs/cli/banner.rb +1 -1
  63. data/lib/gloo/objs/cli/bar.rb +3 -3
  64. data/lib/gloo/objs/cli/colorize.rb +1 -1
  65. data/lib/gloo/objs/cli/confirm.rb +1 -1
  66. data/lib/gloo/objs/cli/menu.rb +6 -6
  67. data/lib/gloo/objs/cli/menu_item.rb +1 -1
  68. data/lib/gloo/objs/cli/pastel.rb +1 -1
  69. data/lib/gloo/objs/cli/prompt.rb +1 -1
  70. data/lib/gloo/objs/cli/select.rb +2 -2
  71. data/lib/gloo/objs/ctrl/each.rb +279 -0
  72. data/lib/gloo/objs/ctrl/repeat.rb +108 -0
  73. data/lib/gloo/objs/data/markdown.rb +79 -0
  74. data/lib/gloo/objs/data/mysql.rb +5 -5
  75. data/lib/gloo/objs/data/query.rb +4 -4
  76. data/lib/gloo/objs/data/sqlite.rb +1 -1
  77. data/lib/gloo/objs/data/table.rb +112 -0
  78. data/lib/gloo/objs/dev/git.rb +2 -2
  79. data/lib/gloo/objs/dev/stats.rb +4 -4
  80. data/lib/gloo/objs/dt/date.rb +65 -0
  81. data/lib/gloo/objs/dt/datetime.rb +120 -0
  82. data/lib/gloo/objs/dt/dt_tools.rb +100 -0
  83. data/lib/gloo/objs/dt/time.rb +65 -0
  84. data/lib/gloo/objs/ror/erb.rb +116 -0
  85. data/lib/gloo/objs/ror/eval.rb +107 -0
  86. data/lib/gloo/objs/snd/play.rb +1 -1
  87. data/lib/gloo/objs/snd/say.rb +1 -1
  88. data/lib/gloo/objs/system/file_handle.rb +4 -4
  89. data/lib/gloo/objs/system/ssh_exec.rb +1 -1
  90. data/lib/gloo/objs/system/system.rb +1 -1
  91. data/lib/gloo/objs/web/http_get.rb +159 -0
  92. data/lib/gloo/objs/web/http_post.rb +183 -0
  93. data/lib/gloo/objs/web/json.rb +135 -0
  94. data/lib/gloo/objs/web/slack.rb +130 -0
  95. data/lib/gloo/objs/web/teams.rb +117 -0
  96. data/lib/gloo/objs/web/uri.rb +148 -0
  97. data/lib/gloo/persist/disc_mech.rb +87 -0
  98. data/lib/gloo/persist/file_loader.rb +193 -0
  99. data/lib/gloo/persist/file_saver.rb +51 -0
  100. data/lib/gloo/persist/file_storage.rb +46 -0
  101. data/lib/gloo/persist/line_splitter.rb +81 -0
  102. data/lib/gloo/persist/persist_man.rb +153 -0
  103. data/lib/gloo/utils/format.rb +21 -0
  104. data/lib/gloo/utils/stats.rb +206 -0
  105. data/lib/gloo/utils/words.rb +19 -0
  106. data/lib/gloo/verbs/alert.rb +2 -2
  107. data/lib/gloo/verbs/beep.rb +1 -1
  108. data/lib/gloo/verbs/cls.rb +1 -1
  109. data/lib/gloo/verbs/context.rb +62 -0
  110. data/lib/gloo/verbs/create.rb +68 -0
  111. data/lib/gloo/verbs/execute.rb +56 -0
  112. data/lib/gloo/verbs/files.rb +49 -0
  113. data/lib/gloo/verbs/help.rb +1 -1
  114. data/lib/gloo/verbs/if.rb +92 -0
  115. data/lib/gloo/verbs/list.rb +98 -0
  116. data/lib/gloo/verbs/load.rb +45 -0
  117. data/lib/gloo/verbs/move.rb +89 -0
  118. data/lib/gloo/verbs/put.rb +94 -0
  119. data/lib/gloo/verbs/quit.rb +40 -0
  120. data/lib/gloo/verbs/reload.rb +43 -0
  121. data/lib/gloo/verbs/run.rb +75 -0
  122. data/lib/gloo/verbs/save.rb +39 -0
  123. data/lib/gloo/verbs/show.rb +63 -0
  124. data/lib/gloo/verbs/tell.rb +80 -0
  125. data/lib/gloo/verbs/unless.rb +92 -0
  126. data/lib/gloo/verbs/unload.rb +46 -0
  127. data/lib/gloo/verbs/version.rb +3 -3
  128. data/lib/gloo/verbs/wait.rb +42 -0
  129. data/lib/gloo.rb +2 -2
  130. data/lib/run.rb +2 -2
  131. metadata +97 -22
@@ -0,0 +1,45 @@
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
+ #
13
+ # Set up the event manager.
14
+ #
15
+ def initialize( engine )
16
+ @engine = engine
17
+ @engine.log.debug 'event manager intialized...'
18
+ end
19
+
20
+ #
21
+ # Run on_load scripts in the recently loaded object
22
+ # If no obj is given the script will be run in root.
23
+ #
24
+ def on_load( obj = nil, in_heap = false )
25
+ return unless obj || in_heap
26
+
27
+ @engine.log.debug 'on_load event'
28
+ arr = Gloo::Core::ObjFinder.by_name( @engine, 'on_load', obj )
29
+ arr.each { |o| Gloo::Exec::Dispatch.message( @engine, 'run', o ) }
30
+ end
31
+
32
+ #
33
+ # Run on_unload scripts in the object that will be unloaded.
34
+ #
35
+ def on_unload( obj )
36
+ return unless obj
37
+
38
+ @engine.log.debug 'on_unload event'
39
+ arr = Gloo::Core::ObjFinder.by_name( @engine, 'on_unload', obj )
40
+ arr.each { |o| Gloo::Exec::Dispatch.message( @engine, 'run', o ) }
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,211 @@
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
+ # ---------------------------------------------------------------------
12
+ # Initializer
13
+ # ---------------------------------------------------------------------
14
+
15
+ #
16
+ # Set up the object factory.
17
+ #
18
+ def initialize( engine )
19
+ @engine = engine
20
+ @engine.log.debug 'object factory intialized...'
21
+ end
22
+
23
+ # ---------------------------------------------------------------------
24
+ # Factory Helpers
25
+ # ---------------------------------------------------------------------
26
+
27
+ #
28
+ # Helper shortcut to create an alias child object.
29
+ #
30
+ def create_alias( name, value, parent )
31
+ params = { :name => name,
32
+ :type => 'alias',
33
+ :value => value,
34
+ :parent => parent }
35
+ create params
36
+ end
37
+
38
+ #
39
+ # Helper shortcut to create a string child object.
40
+ #
41
+ def create_untyped( name, value, parent )
42
+ params = { :name => name,
43
+ :type => 'untyped',
44
+ :value => value,
45
+ :parent => parent }
46
+ create params
47
+ end
48
+
49
+ #
50
+ # Helper shortcut to create a string child object.
51
+ #
52
+ def create_string( name, value, parent )
53
+ params = { :name => name,
54
+ :type => 'string',
55
+ :value => value,
56
+ :parent => parent }
57
+ create params
58
+ end
59
+
60
+ #
61
+ # Helper shortcut to create a text child object.
62
+ #
63
+ def create_text( name, value, parent )
64
+ params = { :name => name,
65
+ :type => 'text',
66
+ :value => value,
67
+ :parent => parent }
68
+ create params
69
+ end
70
+
71
+ #
72
+ # Helper shortcut to create an integer child object.
73
+ #
74
+ def create_int( name, value, parent )
75
+ params = { :name => name,
76
+ :type => 'integer',
77
+ :value => value,
78
+ :parent => parent }
79
+ create params
80
+ end
81
+
82
+ #
83
+ # Helper shortcut to create a boolean child object.
84
+ #
85
+ def create_bool( name, value, parent )
86
+ params = { :name => name,
87
+ :type => 'boolean',
88
+ :value => value,
89
+ :parent => parent }
90
+ create params
91
+ end
92
+
93
+ #
94
+ # Helper shortcut to create a container child object.
95
+ #
96
+ def create_can( name, parent )
97
+ params = { :name => name,
98
+ :type => 'container',
99
+ :value => nil,
100
+ :parent => parent }
101
+ create params
102
+ end
103
+
104
+ #
105
+ # Helper shortcut to create a script child object.
106
+ #
107
+ def create_script( name, value, parent )
108
+ params = { :name => name,
109
+ :type => 'script',
110
+ :value => value,
111
+ :parent => parent }
112
+ create params
113
+ end
114
+
115
+ #
116
+ # Helper shortcut to create a file child object.
117
+ #
118
+ def create_file( name, value, parent )
119
+ params = { :name => name,
120
+ :type => 'file',
121
+ :value => value,
122
+ :parent => parent }
123
+ create params
124
+ end
125
+
126
+ # ---------------------------------------------------------------------
127
+ # Object Factory
128
+ # ---------------------------------------------------------------------
129
+
130
+ # Create object with given name, type and value.
131
+ # One of either name or type is required.
132
+ # All values are optional when considered on their own.
133
+ # Parameter hash keys:
134
+ # :name - the name of the object
135
+ # :type - the name of the type
136
+ # :value - the initial object value
137
+ # :parent - the parent object
138
+ # :squash_duplicates - if the object exists, use it rather
139
+ # than creating a new one? Default = true
140
+ def create( params )
141
+ objtype = find_type params[ :type ]
142
+ return nil unless objtype
143
+
144
+ pn = Gloo::Core::Pn.new( @engine, params[ :name ] )
145
+ parent = params[ :parent ]
146
+ if parent.nil?
147
+ parent = pn.get_parent
148
+ obj_name = pn.name
149
+ else
150
+ obj_name = params[ :name ]
151
+ end
152
+
153
+ if pn.exists? && params[ :squash_duplicates ]
154
+ @engine.log.debug "Updating existing object: #{obj_name}"
155
+ return self.update_existing pn, params[ :value ]
156
+ end
157
+
158
+ @engine.log.debug "Creating new object: #{obj_name}"
159
+ return create_new obj_name, params[ :value ], objtype, parent
160
+ end
161
+
162
+ #
163
+ # Create a new object.
164
+ #
165
+ def create_new( name, value, type, parent )
166
+ unless parent
167
+ @engine.log.error "Could not create object. Bad path: #{name}"
168
+ return nil
169
+ end
170
+
171
+ o = type.new( @engine )
172
+ o.name = name
173
+ o.set_value value
174
+ parent.add_child( o )
175
+ return o
176
+ end
177
+
178
+ #
179
+ # Find and Update an existing object.
180
+ #
181
+ def update_existing( pn, value )
182
+ o = pn.resolve
183
+ o.set_value value
184
+ return o
185
+ end
186
+
187
+ #
188
+ # Find the object type by name.
189
+ # Return nil if the object type cannot be found or
190
+ # cannot be created.
191
+ #
192
+ def find_type( type_name )
193
+ type_name = 'untyped' if type_name.nil? || type_name.strip.empty?
194
+ t = @engine.dictionary.find_obj( type_name )
195
+
196
+ if t.nil?
197
+ @engine.log.warn "Could not find type, '#{type_name}'"
198
+ return nil
199
+ end
200
+
201
+ unless t.can_create?
202
+ @engine.log.error "'#{type_name}' cannot be created."
203
+ return nil
204
+ end
205
+
206
+ return t
207
+ end
208
+
209
+ end
210
+ end
211
+ end
@@ -0,0 +1,267 @@
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
+ require 'tty-platform'
10
+
11
+ module Gloo
12
+ module Core
13
+ class GlooSystem < Obj
14
+
15
+ KEYWORD = 'gloo'.freeze
16
+ KEYWORD_SHORT = '$'.freeze
17
+
18
+ attr_reader :pn
19
+
20
+ # Set up the object.
21
+ def initialize( engine, pn )
22
+ @engine = engine
23
+ @pn = pn
24
+ end
25
+
26
+ #
27
+ # The name of the object type.
28
+ #
29
+ def self.typename
30
+ return KEYWORD
31
+ end
32
+
33
+ #
34
+ # The short name of the object type.
35
+ #
36
+ def self.short_typename
37
+ return KEYWORD_SHORT
38
+ end
39
+
40
+ #
41
+ # The object type, suitable for display.
42
+ #
43
+ def type_display
44
+ return self.class.typename
45
+ end
46
+
47
+ # Is this the root object?
48
+ def 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
+ # Value
61
+ # ---------------------------------------------------------------------
62
+
63
+ #
64
+ # Get the parameter.
65
+ #
66
+ def param
67
+ return nil unless @pn && @pn.segments.count > 1
68
+
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
+ # overriding base functionality with dummy function
84
+ end
85
+
86
+ #
87
+ # Get the value for display purposes.
88
+ #
89
+ def value_display
90
+ return value
91
+ end
92
+
93
+ #
94
+ # Is the value a String?
95
+ #
96
+ def value_string?
97
+ return true
98
+ end
99
+
100
+ #
101
+ # Is the value an Array?
102
+ #
103
+ def value_is_array?
104
+ return false
105
+ end
106
+
107
+ #
108
+ # Is the value a blank string?
109
+ #
110
+ def value_is_blank?
111
+ return true
112
+ end
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
+ # Messages
127
+ # ---------------------------------------------------------------------
128
+
129
+ #
130
+ # Get a list of message names that this object receives.
131
+ #
132
+ def self.messages
133
+ return []
134
+ end
135
+
136
+ # Dispatch the message and get the value.
137
+ def dispatch( msg )
138
+ o = "msg_#{msg}"
139
+ return self.public_send( o ) if self.respond_to? o
140
+
141
+ @engine.log.error "Message #{msg} not implemented"
142
+ return false
143
+ end
144
+
145
+ # Get the system hostname.
146
+ def msg_hostname
147
+ return Socket.gethostname
148
+ end
149
+
150
+ # Get the logged in User.
151
+ def msg_user
152
+ return ENV[ 'USER' ]
153
+ end
154
+
155
+ # Get the user's home directory.
156
+ def msg_user_home
157
+ return File.expand_path( '~' )
158
+ end
159
+
160
+ # Get the working directory.
161
+ def msg_working_dir
162
+ return Dir.pwd
163
+ end
164
+
165
+ # Get the Gloo home directory
166
+ def msg_gloo_home
167
+ return @engine.settings.user_root
168
+ end
169
+
170
+ # Get the Gloo configuration directory
171
+ def msg_gloo_config
172
+ return @engine.settings.config_path
173
+ end
174
+
175
+ # Get the Gloo projects directory
176
+ def msg_gloo_projects
177
+ return @engine.settings.project_path
178
+ end
179
+
180
+ # Get the Gloo log directory
181
+ def msg_gloo_log
182
+ return @engine.settings.log_path
183
+ end
184
+
185
+ # ---------------------------------------------------------------------
186
+ # Special chars
187
+ # ---------------------------------------------------------------------
188
+
189
+ # Carriage return (line feed)
190
+ def msg_line
191
+ return "\n"
192
+ end
193
+
194
+ # ---------------------------------------------------------------------
195
+ # Screen Messages
196
+ # ---------------------------------------------------------------------
197
+
198
+ # Get the number of lines on screen.
199
+ def msg_screen_lines
200
+ return Gloo::App::Settings.lines( @engine )
201
+ end
202
+
203
+ # Get the number of columns on screen.
204
+ def msg_screen_cols
205
+ return Gloo::App::Settings.cols( @engine )
206
+ end
207
+
208
+ # ---------------------------------------------------------------------
209
+ # Platform Messages
210
+ # ---------------------------------------------------------------------
211
+
212
+ # Get the platform CPU
213
+ def msg_platform_cpu
214
+ platform = TTY::Platform.new
215
+ return platform.cpu
216
+ end
217
+
218
+ # Get the platform Operating System
219
+ def msg_platform_os
220
+ platform = TTY::Platform.new
221
+ return platform.os
222
+ end
223
+
224
+ # Get the platform version
225
+ def msg_platform_version
226
+ platform = TTY::Platform.new
227
+ return platform.version
228
+ end
229
+
230
+ # Is the platform Windows?
231
+ def msg_platform_windows?
232
+ platform = TTY::Platform.new
233
+ return platform.windows?
234
+ end
235
+
236
+ # Is the platform Unix?
237
+ def msg_platform_unix?
238
+ platform = TTY::Platform.new
239
+ return platform.unix?
240
+ end
241
+
242
+ # Is the platform Linux?
243
+ def msg_platform_linux?
244
+ platform = TTY::Platform.new
245
+ return platform.linux?
246
+ end
247
+
248
+ # Is the platform Mac?
249
+ def msg_platform_mac?
250
+ platform = TTY::Platform.new
251
+ return platform.mac?
252
+ end
253
+
254
+ #
255
+ # Get the command to open a file on this platform.
256
+ #
257
+ def self.open_for_platform
258
+ platform = TTY::Platform.new
259
+ return 'open' if platform.mac?
260
+ return 'xdg-open' if platform.linux?
261
+
262
+ return nil
263
+ end
264
+
265
+ end
266
+ end
267
+ end
@@ -0,0 +1,53 @@
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
+ attr_reader :it, :root, :error
18
+
19
+ #
20
+ # Set up the object heap.
21
+ #
22
+ def initialize( engine )
23
+ @engine = engine
24
+ @engine.log.debug 'object heap intialized...'
25
+
26
+ @root = Gloo::Objs::Container.new( @engine )
27
+ @root.name = 'root'
28
+
29
+ @context = Pn.root @engine
30
+ @it = It.new
31
+ @error = Error.new
32
+ end
33
+
34
+ #
35
+ # Unload the given obj--remove it from the heap.
36
+ #
37
+ def unload( obj )
38
+ can = obj.parent.nil? ? @root : obj.parent
39
+ return unless can
40
+
41
+ can.remove_child obj
42
+ end
43
+
44
+ #
45
+ # Is there one or more errors?
46
+ #
47
+ def error?
48
+ return @error.error_count.positive?
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,36 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # Here helper class,
5
+ # used to resolve relative referencing.
6
+ #
7
+
8
+ module Gloo
9
+ module Core
10
+ class Here
11
+
12
+ HERE = '^'.freeze
13
+
14
+ #
15
+ # Does the pathname start with here reference?
16
+ #
17
+ def self.includes_here_ref?( elements )
18
+ return elements.first.start_with?( HERE )
19
+ end
20
+
21
+ #
22
+ # Expand here reference if present.
23
+ #
24
+ def self.expand_here( engine, pn )
25
+ target = engine.exec_env.here_obj
26
+
27
+ here = pn.elements.first
28
+ remainder = pn.elements[ 1..-1 ].join( '.' )
29
+
30
+ here.length.times { target = target.parent }
31
+ pn.set_to "#{target.pn}.#{remainder}"
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
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
+ #
14
+ # Set up the object.
15
+ #
16
+ def initialize
17
+ @value = nil
18
+ end
19
+
20
+ #
21
+ # Set the value of it.
22
+ #
23
+ def set_to( new_value )
24
+ @value = new_value
25
+ end
26
+
27
+ #
28
+ # Get the string representation of it.
29
+ #
30
+ def to_s
31
+ return @value.to_s
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -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
+ # A Literal value.
5
+ # Base class for all literal values.
6
+ #
7
+
8
+ module Gloo
9
+ module Core
10
+ class Literal
11
+
12
+ attr_reader :value
13
+
14
+ #
15
+ # Create the expression from a list of tokens.
16
+ #
17
+ def initialize( value )
18
+ set_value( value )
19
+ end
20
+
21
+ #
22
+ # Set the literal value.
23
+ #
24
+ def set_value( value )
25
+ @value = value
26
+ end
27
+
28
+ end
29
+ end
30
+ end