gloo 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62d4c3076b0a61719c6a62ef65aa793a758074e0ab306376671b445582e70822
4
- data.tar.gz: a2938182e0675a6992861da6dfea7da7a23e6998f235a9cb6b376ee823b7d8a7
3
+ metadata.gz: 795a2a504aa74f3089a84d31a2328bb390ddf1aa7f635e2ff195f8fb702c1a3b
4
+ data.tar.gz: bdd936b143644a0738b7608af0a7babd3449dfca44cbfb5eafa93ce5cafafba0
5
5
  SHA512:
6
- metadata.gz: a3de2e0895ec0da13278af8ea8e3ffca79bf69d65c503254198ad4441f2e29d84f5393db01768ec5a0458c12666de14f6e06a2d33f1005c083039b7dfa4abc80
7
- data.tar.gz: 40e4aa7fc2a957e53cccc880c8aa2e0e9061fb0dd8eb2294ca6b93866e1820b086e694b06207897daabe89747e01cca6830952c8045078a5f4aa53ddf5b588a3
6
+ metadata.gz: 86ddd2862739a3a1b7a889129d6417c546b15e59e4fb7cc86fad6452eb2edc0e2d2176fedfec2b890ec6225ceeaaaf612eb4f2d9d73d867aa68348a25c4c70dd
7
+ data.tar.gz: fa430128e804363656cfc02a07d6223db8e9f55a50efa3cace35a8095c5a3a911d837c80c769ac57060ea5e1f9e0aea4937d06680faf1a0657221b1ad168f0a0
data/gloo.gemspec CHANGED
@@ -49,6 +49,6 @@ Gem::Specification.new do |spec|
49
49
  spec.add_dependency 'json', '~> 2.1', '>= 2.1.0'
50
50
  spec.add_dependency 'openssl', '~> 2.1', '>= 2.1.0'
51
51
  spec.add_dependency 'net-ssh', '~> 6.1', '>= 6.1.0'
52
- # spec.add_dependency 'mysql2', '~> 0.5', '>= 0.5.3'
53
- # spec.add_dependency 'sqlite3', '~> 1.4', '>= 1.4.2'
52
+ spec.add_dependency 'mysql2', '~> 0.5', '>= 0.5.3'
53
+ spec.add_dependency 'sqlite3', '~> 1.4', '>= 1.4.2'
54
54
  end
data/lib/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -0,0 +1,192 @@
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 < GlooLang::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
+ # DB functions (all database connections)
95
+ # ---------------------------------------------------------------------
96
+
97
+ #
98
+ # Open a connection and execute the SQL statement.
99
+ # Return the resulting data.
100
+ #
101
+ def query( sql, params = nil )
102
+ h = {
103
+ host: host_value,
104
+ database: db_value,
105
+ username: user_value,
106
+ password: passwd_value
107
+ }
108
+ client = Mysql2::Client.new( h )
109
+ return client.query( sql ) unless params
110
+
111
+ pst = client.prepare( sql )
112
+ return pst.execute( *params )
113
+ end
114
+
115
+ # ---------------------------------------------------------------------
116
+ # Private functions
117
+ # ---------------------------------------------------------------------
118
+
119
+ private
120
+
121
+ #
122
+ # Get the host from the child object.
123
+ # Returns nil if there is none.
124
+ #
125
+ def host_value
126
+ o = find_child HOST
127
+ return nil unless o
128
+
129
+ o = GlooLang::Objs::Alias.resolve_alias( @engine, o )
130
+ return o.value
131
+ end
132
+
133
+ #
134
+ # Get the Database name from the child object.
135
+ # Returns nil if there is none.
136
+ #
137
+ def db_value
138
+ o = find_child DB
139
+ return nil unless o
140
+
141
+ o = GlooLang::Objs::Alias.resolve_alias( @engine, o )
142
+ return o.value
143
+ end
144
+
145
+ #
146
+ # Get the Username from the child object.
147
+ # Returns nil if there is none.
148
+ #
149
+ def user_value
150
+ o = find_child USER
151
+ return nil unless o
152
+
153
+ o = GlooLang::Objs::Alias.resolve_alias( @engine, o )
154
+ return o.value
155
+ end
156
+
157
+ #
158
+ # Get the Password name from the child object.
159
+ # Returns nil if there is none.
160
+ #
161
+ def passwd_value
162
+ o = find_child PASSWD
163
+ return nil unless o
164
+
165
+ o = GlooLang::Objs::Alias.resolve_alias( @engine, o )
166
+ return o.value
167
+ end
168
+
169
+ #
170
+ # Try the connection and make sure it works.
171
+ # Returns true if we can establish a connection.
172
+ #
173
+ def connects?
174
+ begin
175
+ h = {
176
+ host: host_value,
177
+ database: db_value,
178
+ username: user_value,
179
+ password: passwd_value
180
+ }
181
+ Mysql2::Client.new( h )
182
+ rescue => e
183
+ @engine.err e.message
184
+ @engine.heap.it.set_to false
185
+ return false
186
+ end
187
+ return true
188
+ end
189
+
190
+ end
191
+ end
192
+ end
@@ -0,0 +1,159 @@
1
+ # Author:: Eric Crane (mailto:eric.crane@mac.com)
2
+ # Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
3
+ #
4
+ # A Sqlite3 database connection.
5
+ #
6
+ # https://www.rubydoc.info/gems/sqlite3/1.3.11
7
+ # https://www.devdungeon.com/content/ruby-sqlite-tutorial
8
+ #
9
+ # db.results_as_hash = true
10
+ # Set results to return as Hash object.
11
+ # This is slower but offers a huge convenience.
12
+ # Consider turning it off for high performance situations.
13
+ # Each row will have the column name as the hash key.
14
+ #
15
+ # # Alternatively, to only get one row and discard the rest,
16
+ # replace `db.query()` with `db.get_first_value()`.
17
+ #
18
+ require 'sqlite3'
19
+
20
+ module Gloo
21
+ module Objs
22
+ class Sqlite < GlooLang::Core::Obj
23
+
24
+ KEYWORD = 'sqlite'.freeze
25
+ KEYWORD_SHORT = 'sqlite'.freeze
26
+
27
+ DB = 'database'.freeze
28
+ DEFAULT_DB = 'test.db'.freeze
29
+
30
+ DB_REQUIRED_ERR = 'The database name is required!'.freeze
31
+ DB_NOT_FOUND_ERR = 'The database file was not found!'.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 DB, DEFAULT_DB, self
68
+ end
69
+
70
+ # ---------------------------------------------------------------------
71
+ # Messages
72
+ # ---------------------------------------------------------------------
73
+
74
+ #
75
+ # Get a list of message names that this object receives.
76
+ #
77
+ def self.messages
78
+ return super + [ 'verify' ]
79
+ end
80
+
81
+ #
82
+ # Verify access to the Sqlite database specified.
83
+ #
84
+ def msg_verify
85
+ name = db_value
86
+ if name.empty?
87
+ @engine.err DB_REQUIRED_ERR
88
+ @engine.heap.it.set_to false
89
+ return
90
+ end
91
+
92
+ unless File.exist? name
93
+ @engine.err DB_NOT_FOUND_ERR
94
+ @engine.heap.it.set_to false
95
+ return
96
+ end
97
+
98
+ return unless connects?
99
+
100
+ @engine.heap.it.set_to true
101
+ end
102
+
103
+ # ---------------------------------------------------------------------
104
+ # DB functions (all database connections)
105
+ # ---------------------------------------------------------------------
106
+
107
+ #
108
+ # Open a connection and execute the SQL statement.
109
+ # Return the resulting data.
110
+ #
111
+ def query( sql, params = nil )
112
+ name = db_value
113
+ unless name
114
+ @engine.err DB_REQUIRED_ERR
115
+ return
116
+ end
117
+
118
+ db = SQLite3::Database.open name
119
+ db.results_as_hash = true
120
+ return db.query( sql, params )
121
+ end
122
+
123
+ # ---------------------------------------------------------------------
124
+ # Private functions
125
+ # ---------------------------------------------------------------------
126
+
127
+ private
128
+
129
+ #
130
+ # Get the Database file from the child object.
131
+ # Returns nil if there is none.
132
+ #
133
+ def db_value
134
+ o = find_child DB
135
+ return nil unless o
136
+
137
+ return o.value
138
+ end
139
+
140
+ #
141
+ # Try the connection and make sure it works.
142
+ # Returns true if we can connect and do a query.
143
+ #
144
+ def connects?
145
+ begin
146
+ db = SQLite3::Database.open db_value
147
+ sql = "SELECT COUNT(name) FROM sqlite_master WHERE type='table'"
148
+ db.get_first_value sql
149
+ rescue => e
150
+ @engine.err e.message
151
+ @engine.heap.it.set_to false
152
+ return false
153
+ end
154
+ return true
155
+ end
156
+
157
+ end
158
+ end
159
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gloo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Crane
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-05 00:00:00.000000000 Z
11
+ date: 2022-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -224,6 +224,46 @@ dependencies:
224
224
  - - ">="
225
225
  - !ruby/object:Gem::Version
226
226
  version: 6.1.0
227
+ - !ruby/object:Gem::Dependency
228
+ name: mysql2
229
+ requirement: !ruby/object:Gem::Requirement
230
+ requirements:
231
+ - - "~>"
232
+ - !ruby/object:Gem::Version
233
+ version: '0.5'
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: 0.5.3
237
+ type: :runtime
238
+ prerelease: false
239
+ version_requirements: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - "~>"
242
+ - !ruby/object:Gem::Version
243
+ version: '0.5'
244
+ - - ">="
245
+ - !ruby/object:Gem::Version
246
+ version: 0.5.3
247
+ - !ruby/object:Gem::Dependency
248
+ name: sqlite3
249
+ requirement: !ruby/object:Gem::Requirement
250
+ requirements:
251
+ - - "~>"
252
+ - !ruby/object:Gem::Version
253
+ version: '1.4'
254
+ - - ">="
255
+ - !ruby/object:Gem::Version
256
+ version: 1.4.2
257
+ type: :runtime
258
+ prerelease: false
259
+ version_requirements: !ruby/object:Gem::Requirement
260
+ requirements:
261
+ - - "~>"
262
+ - !ruby/object:Gem::Version
263
+ version: '1.4'
264
+ - - ">="
265
+ - !ruby/object:Gem::Version
266
+ version: 1.4.2
227
267
  description: A scripting languge to keep it all together.
228
268
  email:
229
269
  - eric.crane@mac.com
@@ -264,6 +304,8 @@ files:
264
304
  - lib/gloo/objs/cli/pastel.rb
265
305
  - lib/gloo/objs/cli/prompt.rb
266
306
  - lib/gloo/objs/cli/select.rb
307
+ - lib/gloo/objs/data/mysql.rb
308
+ - lib/gloo/objs/data/sqlite.rb
267
309
  - lib/gloo/objs/dev/git.rb
268
310
  - lib/gloo/objs/dev/stats.rb
269
311
  - lib/gloo/objs/snd/play.rb