gloo 4.7.0 → 5.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 (63) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/gloo.gemspec +22 -11
  4. data/lib/VERSION +1 -1
  5. data/lib/VERSION_NOTES +7 -0
  6. data/lib/gloo/app/engine.rb +3 -2
  7. data/lib/gloo/app/running_app.rb +13 -0
  8. data/lib/gloo/core/dictionary.rb +13 -2
  9. data/lib/gloo/objs/ctrl/each.rb +2 -2
  10. data/lib/gloo/{ext → plugin}/base.rb +1 -1
  11. data/lib/gloo/{ext → plugin}/callback.rb +2 -3
  12. data/lib/gloo/{ext/manager.rb → plugin/ext_manager.rb} +2 -2
  13. data/lib/gloo/plugin/lib_manager.rb +97 -0
  14. data/lib/gloo/verbs/exists.rb +75 -0
  15. data/lib/gloo/verbs/help.rb +28 -0
  16. data/lib/gloo/verbs/load.rb +8 -2
  17. data/lib/gloo/verbs/redirect.rb +2 -1
  18. metadata +38 -164
  19. data/lib/gloo/objs/cli/colorize.rb +0 -73
  20. data/lib/gloo/objs/cli/confirm.rb +0 -96
  21. data/lib/gloo/objs/cli/menu.rb +0 -370
  22. data/lib/gloo/objs/cli/menu_item.rb +0 -95
  23. data/lib/gloo/objs/cli/prompt.rb +0 -110
  24. data/lib/gloo/objs/cli/select.rb +0 -127
  25. data/lib/gloo/objs/ctrl/each_repo.rb +0 -84
  26. data/lib/gloo/objs/data/markdown.rb +0 -133
  27. data/lib/gloo/objs/data/markdown_ext.rb +0 -260
  28. data/lib/gloo/objs/data/mysql.rb +0 -254
  29. data/lib/gloo/objs/data/query.rb +0 -269
  30. data/lib/gloo/objs/data/query_result.rb +0 -158
  31. data/lib/gloo/objs/data/sqlite.rb +0 -174
  32. data/lib/gloo/objs/data/table.rb +0 -267
  33. data/lib/gloo/objs/dev/git.rb +0 -140
  34. data/lib/gloo/objs/dev/stats.rb +0 -123
  35. data/lib/gloo/objs/system/ssh_exec.rb +0 -126
  36. data/lib/gloo/objs/web_svr/element.rb +0 -254
  37. data/lib/gloo/objs/web_svr/field.rb +0 -429
  38. data/lib/gloo/objs/web_svr/form.rb +0 -271
  39. data/lib/gloo/objs/web_svr/page.rb +0 -562
  40. data/lib/gloo/objs/web_svr/partial.rb +0 -210
  41. data/lib/gloo/objs/web_svr/svr.rb +0 -713
  42. data/lib/gloo/utils/stats.rb +0 -206
  43. data/lib/gloo/web_svr/asset.rb +0 -407
  44. data/lib/gloo/web_svr/asset_info.rb +0 -116
  45. data/lib/gloo/web_svr/config.rb +0 -56
  46. data/lib/gloo/web_svr/embedded_renderer.rb +0 -154
  47. data/lib/gloo/web_svr/handler.rb +0 -154
  48. data/lib/gloo/web_svr/request.rb +0 -143
  49. data/lib/gloo/web_svr/request_params.rb +0 -181
  50. data/lib/gloo/web_svr/response.rb +0 -177
  51. data/lib/gloo/web_svr/response_code.rb +0 -69
  52. data/lib/gloo/web_svr/routing/resource_router.rb +0 -47
  53. data/lib/gloo/web_svr/routing/router.rb +0 -232
  54. data/lib/gloo/web_svr/routing/show_routes.rb +0 -94
  55. data/lib/gloo/web_svr/server.rb +0 -105
  56. data/lib/gloo/web_svr/session.rb +0 -215
  57. data/lib/gloo/web_svr/table_renderer.rb +0 -151
  58. data/lib/gloo/web_svr/web_method.rb +0 -54
  59. /data/lib/gloo/objs/{security → str_utils}/cipher.rb +0 -0
  60. /data/lib/gloo/objs/{security → str_utils}/csrf_token.rb +0 -0
  61. /data/lib/gloo/objs/{security → str_utils}/password.rb +0 -0
  62. /data/lib/gloo/objs/{ror → system}/erb.rb +0 -0
  63. /data/lib/gloo/objs/{ror → system}/eval.rb +0 -0
@@ -1,254 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
- #
4
- # A MySQL database connection.
5
- #
6
- #
7
- # https://github.com/brianmario/mysql2
8
- # https://www.rubydoc.info/gems/mysql2/0.2.3/Mysql2/Client
9
- #
10
- # Connection Parameters
11
- # user = opts[:username]
12
- # pass = opts[:password]
13
- # host = opts[:host] || 'localhost'
14
- # port = opts[:port] || 3306
15
- # database = opts[:database]
16
- # socket = opts[:socket]
17
- # flags = opts[:flags] || 0
18
- #
19
- require 'mysql2'
20
-
21
- module Gloo
22
- module Objs
23
- class Mysql < Gloo::Core::Obj
24
-
25
- KEYWORD = 'mysql'.freeze
26
- KEYWORD_SHORT = 'mysql'.freeze
27
-
28
- HOST = 'host'.freeze
29
- DB = 'database'.freeze
30
- USER = 'username'.freeze
31
- PASSWD = 'password'.freeze
32
-
33
- #
34
- # The name of the object type.
35
- #
36
- def self.typename
37
- return KEYWORD
38
- end
39
-
40
- #
41
- # The short name of the object type.
42
- #
43
- def self.short_typename
44
- return KEYWORD_SHORT
45
- end
46
-
47
- # ---------------------------------------------------------------------
48
- # Children
49
- # ---------------------------------------------------------------------
50
-
51
- #
52
- # Does this object have children to add when an object
53
- # is created in interactive mode?
54
- # This does not apply during obj load, etc.
55
- #
56
- def add_children_on_create?
57
- return true
58
- end
59
-
60
- #
61
- # Add children to this object.
62
- # This is used by containers to add children needed
63
- # for default configurations.
64
- #
65
- def add_default_children
66
- fac = @engine.factory
67
- fac.create_string HOST, nil, self
68
- fac.create_string DB, nil, self
69
- fac.create_string USER, nil, self
70
- fac.create_string PASSWD, nil, self
71
- end
72
-
73
- # ---------------------------------------------------------------------
74
- # Messages
75
- # ---------------------------------------------------------------------
76
-
77
- #
78
- # Get a list of message names that this object receives.
79
- #
80
- def self.messages
81
- return super + [ 'verify' ]
82
- end
83
-
84
- #
85
- # SSH to the host and execute the command, then update result.
86
- #
87
- def msg_verify
88
- return unless connects?
89
-
90
- @engine.heap.it.set_to true
91
- end
92
-
93
-
94
- # ---------------------------------------------------------------------
95
- # DB functions (all database connections)
96
- # ---------------------------------------------------------------------
97
-
98
- #
99
- # Get the client object.
100
- # It might be cached, so check first.
101
- # If it is not cached, create a new one.
102
- #
103
- def get_client
104
- app = @engine.running_app
105
-
106
- client = app.db_client_for_obj( self ) if app
107
-
108
- if client && client.ping
109
- @engine.log.debug "Connection is established and active."
110
- return client
111
- elsif client
112
- @engine.log.debug "Connection is established but NOT active. Reconnecting."
113
- else
114
- @engine.log.debug "Opening a new Connection."
115
- end
116
-
117
- h = {
118
- host: host_value,
119
- database: db_value,
120
- username: user_value,
121
- password: passwd_value
122
- }
123
- client = Mysql2::Client.new( h )
124
-
125
- app.cache_db_client( self, client ) if app
126
-
127
- return client
128
- end
129
-
130
- #
131
- # Open a connection and execute the SQL statement.
132
- # Return the resulting data.
133
- #
134
- def query( sql, params = nil )
135
- client = get_client
136
-
137
- heads = []
138
- data = []
139
- begin
140
- if params
141
- pst = client.prepare( sql )
142
- rs = pst.execute( *params, :as => :array )
143
- if rs
144
- rs.each do |row|
145
- arr = []
146
- row.each do |o|
147
- arr << o
148
- end
149
- data << arr
150
- end
151
- end
152
- else
153
- rs = client.query( sql, :as => :array )
154
- if rs
155
- rs.each do |row|
156
- data << row
157
- end
158
- end
159
- end
160
-
161
- heads = rs.fields if rs
162
- rescue => e
163
- @engine.log_exception e
164
- end
165
-
166
- return [ heads, data ]
167
- end
168
-
169
- #
170
- # Based on the result set, build a QueryResult object.
171
- #
172
- def get_query_result( result )
173
- return QueryResult.new result[0], result[1], @engine
174
- end
175
-
176
-
177
- # ---------------------------------------------------------------------
178
- # Private functions
179
- # ---------------------------------------------------------------------
180
-
181
- private
182
-
183
- #
184
- # Get the host from the child object.
185
- # Returns nil if there is none.
186
- #
187
- def host_value
188
- o = find_child HOST
189
- return nil unless o
190
-
191
- o = Gloo::Objs::Alias.resolve_alias( @engine, o )
192
- return o.value
193
- end
194
-
195
- #
196
- # Get the Database name from the child object.
197
- # Returns nil if there is none.
198
- #
199
- def db_value
200
- o = find_child DB
201
- return nil unless o
202
-
203
- o = Gloo::Objs::Alias.resolve_alias( @engine, o )
204
- return o.value
205
- end
206
-
207
- #
208
- # Get the Username from the child object.
209
- # Returns nil if there is none.
210
- #
211
- def user_value
212
- o = find_child USER
213
- return nil unless o
214
-
215
- o = Gloo::Objs::Alias.resolve_alias( @engine, o )
216
- return o.value
217
- end
218
-
219
- #
220
- # Get the Password name from the child object.
221
- # Returns nil if there is none.
222
- #
223
- def passwd_value
224
- o = find_child PASSWD
225
- return nil unless o
226
-
227
- o = Gloo::Objs::Alias.resolve_alias( @engine, o )
228
- return o.value
229
- end
230
-
231
- #
232
- # Try the connection and make sure it works.
233
- # Returns true if we can establish a connection.
234
- #
235
- def connects?
236
- begin
237
- h = {
238
- host: host_value,
239
- database: db_value,
240
- username: user_value,
241
- password: passwd_value
242
- }
243
- Mysql2::Client.new( h )
244
- rescue => e
245
- @engine.log_exception e
246
- @engine.heap.it.set_to false
247
- return false
248
- end
249
- return true
250
- end
251
-
252
- end
253
- end
254
- end
@@ -1,269 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
- #
4
- # A SQL database query.
5
- # Relies on a database connection object.
6
- #
7
-
8
- module Gloo
9
- module Objs
10
- class Query < Gloo::Core::Obj
11
-
12
- KEYWORD = 'query'.freeze
13
- KEYWORD_SHORT = 'sql'.freeze
14
-
15
- DB = 'database'.freeze
16
- SQL = 'sql'.freeze
17
- RESULT = 'result'.freeze
18
- PARAMS = 'params'.freeze
19
- SIMPLE_LIST = 'simple_list'.freeze
20
-
21
- DB_MISSING_ERR = 'The database connection is missing!'.freeze
22
-
23
- #
24
- # The name of the object type.
25
- #
26
- def self.typename
27
- return KEYWORD
28
- end
29
-
30
- #
31
- # The short name of the object type.
32
- #
33
- def self.short_typename
34
- return KEYWORD_SHORT
35
- end
36
-
37
- #
38
- # Get the result container if it exists.
39
- #
40
- def get_result_can
41
- result_can = find_child RESULT
42
- result_can = Gloo::Objs::Alias.resolve_alias( @engine, result_can )
43
- return result_can
44
- end
45
-
46
- # ---------------------------------------------------------------------
47
- # Children
48
- # ---------------------------------------------------------------------
49
-
50
- #
51
- # Does this object have children to add when an object
52
- # is created in interactive mode?
53
- # This does not apply during obj load, etc.
54
- #
55
- def add_children_on_create?
56
- return true
57
- end
58
-
59
- #
60
- # Add children to this object.
61
- # This is used by containers to add children needed
62
- # for default configurations.
63
- #
64
- def add_default_children
65
- fac = @engine.factory
66
- fac.create_alias DB, nil, self
67
- fac.create_string SQL, nil, self
68
- fac.create_can RESULT, self
69
- end
70
-
71
- # ---------------------------------------------------------------------
72
- # Messages
73
- # ---------------------------------------------------------------------
74
-
75
- #
76
- # Get a list of message names that this object receives.
77
- #
78
- def self.messages
79
- return super + [ 'run' ]
80
- end
81
-
82
- #
83
- # Run the query and process the results.
84
- #
85
- def msg_run
86
- db = db_obj
87
- return unless db
88
-
89
- begin
90
- clear_results
91
-
92
- log_query sql_value, param_array
93
- result = db.query( sql_value, param_array )
94
- process_result( result, db )
95
- rescue => e
96
- @engine.log_exception e
97
- return
98
- end
99
- end
100
-
101
- #
102
- # Run the query and return the results.
103
- #
104
- def run_query
105
- db = db_obj
106
- return unless db
107
-
108
- begin
109
- log_query sql_value, param_array
110
-
111
- db_start = ::Time.now
112
- result = db.query( sql_value, param_array )
113
- db_done = ::Time.now
114
- elapsed = ( ( db_done - db_start ) * 1000.0 ).round(2)
115
-
116
- app = @engine.running_app
117
- app.add_db_time elapsed if app
118
- return result
119
- rescue => e
120
- @engine.log_exception e
121
- return
122
- end
123
- end
124
-
125
- #
126
- # Write the query to the log.
127
- #
128
- def log_query sql, params
129
- @engine.log.info "SQL PARAMS: #{params}" if params
130
- @engine.log.info "SQL: #{sql}"
131
- end
132
-
133
-
134
- # ---------------------------------------------------------------------
135
- # Output as simple list
136
- # ---------------------------------------------------------------------
137
-
138
- #
139
- # Should the output be put in a simple list?
140
- #
141
- def simple_list?
142
- o = find_child SIMPLE_LIST
143
- return false unless o
144
-
145
- return o.value
146
- end
147
-
148
-
149
- # ---------------------------------------------------------------------
150
- # Private functions
151
- # ---------------------------------------------------------------------
152
-
153
- private
154
-
155
- #
156
- # Get the database connection.
157
- #
158
- def db_obj
159
- o = find_child DB
160
-
161
- unless o
162
- @engine.err DB_MISSING_ERR
163
- return nil
164
- end
165
-
166
- return Gloo::Objs::Alias.resolve_alias( @engine, o )
167
- end
168
-
169
- #
170
- # Get the SQL from the child object.
171
- # Returns nil if there is none.
172
- #
173
- def sql_value
174
- o = find_child SQL
175
- return nil unless o
176
-
177
- o = Gloo::Objs::Alias.resolve_alias( @engine, o )
178
- return o.value
179
- end
180
-
181
- #
182
- # Do something with the result of the SQL Query call.
183
- # If there's a result container, we'll create objects in it.
184
- # If not, we'll just show the output in the console.
185
- #
186
- def process_result( result, db )
187
- return if result.nil?
188
-
189
- query_result = db.get_query_result( result )
190
- return unless query_result
191
- return unless query_result.has_data_to_show?
192
-
193
- result_can = get_result_can
194
-
195
- if result_can
196
- if simple_list?
197
- query_result.update_result_container_simple result_can
198
- else
199
- query_result.update_result_container result_can
200
- end
201
- else
202
- query_result.show
203
- end
204
- end
205
-
206
- #
207
- # Get the array of parameters.
208
- # If there is no PARAM container of if it is empty,
209
- # we'll return a nil value.
210
- #
211
- def param_array
212
- o = find_child PARAMS
213
- return nil unless o
214
-
215
- return nil if o.child_count.zero?
216
-
217
- params = []
218
- o.children.each do |p|
219
- p = Gloo::Objs::Alias.resolve_alias( @engine, p )
220
- params << p.sql_value
221
- end
222
-
223
- return params
224
- end
225
-
226
- #
227
- # Clear out results container.
228
- # Prevents data from the last use being used in this
229
- # one if no data was found.
230
- #
231
- def clear_results
232
- result_can = get_result_can
233
- return unless result_can
234
- return unless result_can.child_count.positive?
235
-
236
- if result_is_values?
237
- clear_values
238
- else
239
- get_result_can.delete_children
240
- end
241
- end
242
-
243
- #
244
- # Is the result container a list of values?
245
- # If not it is a list of rows.
246
- #
247
- def result_is_values?
248
- first_child = get_result_can.children.first
249
-
250
- if first_child && first_child&.is_container?
251
- return false
252
- end
253
-
254
- return true
255
- end
256
-
257
- #
258
- # Clear out the values in the results container.
259
- #
260
- def clear_values
261
- get_result_can.children.each do |c|
262
- c = Gloo::Objs::Alias.resolve_alias( @engine, c )
263
- c.value = nil
264
- end
265
- end
266
-
267
- end
268
- end
269
- end
@@ -1,158 +0,0 @@
1
- # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
- # Copyright:: Copyright (c) 2022 Eric Crane. All rights reserved.
3
- #
4
- # The result of a SQL database query.
5
- #
6
-
7
- module Gloo
8
- module Objs
9
- class QueryResult
10
-
11
- DB = 'database'.freeze
12
- SQL = 'sql'.freeze
13
- RESULT = 'result'.freeze
14
- PARAMS = 'params'.freeze
15
-
16
-
17
- # ---------------------------------------------------------------------
18
- # Set up the Result
19
- # ---------------------------------------------------------------------
20
-
21
- #
22
- # Create the Result object
23
- def initialize( heads, data, engine=nil )
24
- @heads = heads
25
- @data = data
26
- @engine = engine
27
- end
28
-
29
-
30
- # ---------------------------------------------------------------------
31
- # Helper Functions
32
- # ---------------------------------------------------------------------
33
-
34
- #
35
- # Does the data contain a single row?
36
- # OR, if the result is empty, return false.
37
- #
38
- def single_row_result?
39
- if @result_can && ( @result_can.child_count == 0 )
40
- return false
41
- end
42
-
43
- return @data.count == 1
44
- end
45
-
46
- #
47
- # Does this query result have data to show?
48
- #
49
- def has_data_to_show?
50
- return false unless @heads
51
- return false unless @data
52
- return false if @heads.count == 0
53
- return false if @data.count == 0
54
-
55
- return true
56
- end
57
-
58
-
59
- # ---------------------------------------------------------------------
60
- # Show Results
61
- # ---------------------------------------------------------------------
62
-
63
- #
64
- # Show the result of the query
65
- #
66
- def show
67
- single_row_result? ? show_single_row : show_rows
68
- end
69
-
70
- #
71
- # Show a single row in a vertical, form style view.
72
- #
73
- def show_single_row
74
- arr = []
75
- row = @data[0]
76
- @heads.each_with_index do |h, i|
77
- arr << [ h, row[i] ]
78
- end
79
- @engine.platform.table.show [ 'Field', 'Value' ], arr
80
- end
81
-
82
- #
83
- # Show multiple rows in a table view.
84
- #
85
- def show_rows
86
- @engine.platform.table.show @heads, @data
87
- end
88
-
89
- # ---------------------------------------------------------------------
90
- # Update results in object(s)
91
- # ---------------------------------------------------------------------
92
-
93
- #
94
- # Update the result container with the data from the query.
95
- #
96
- def update_result_container( in_can )
97
- @result_can = in_can
98
- single_row_result? ? update_single_row : update_rows
99
- end
100
-
101
- #
102
- # Update the result container with the data from the query.
103
- #
104
- def update_result_container_simple( in_can )
105
- @result_can = in_can
106
- single_row_result? ? update_single_row : update_rows_simple
107
- end
108
-
109
- #
110
- # The result has a single row.
111
- # Map values from the result set to objects that are present.
112
- #
113
- def update_single_row
114
- row = @data[0]
115
- @heads.each_with_index do |h, i|
116
- child = @result_can.find_child h
117
- child = Gloo::Objs::Alias.resolve_alias( @engine, child )
118
- child.set_value row[i] if child
119
- end
120
- end
121
-
122
- #
123
- # Put all rows in the result object.
124
- #
125
- def update_rows
126
- @data.each_with_index do |row, i|
127
- can = @result_can.find_add_child( i.to_s, 'can' )
128
- row.each_with_index do |v, i|
129
- o = can.find_add_child( @heads[i], 'untyped' )
130
- o.set_value v
131
- end
132
- end
133
- end
134
-
135
- #
136
- # Put all rows in the result object.
137
- #
138
- def update_rows_simple
139
- @data.each do |row|
140
- row.each do |val|
141
- o = @result_can.find_add_child( val, 'untyped' )
142
- o.set_value val
143
- end
144
- end
145
- end
146
-
147
-
148
- # ---------------------------------------------------------------------
149
- # Private functions
150
- # ---------------------------------------------------------------------
151
-
152
- private
153
-
154
-
155
-
156
- end
157
- end
158
- end