gloo-lang 0.9.4 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/gloo-lang.gemspec +1 -0
- data/lib/VERSION +1 -1
- data/lib/gloo_lang/app/args.rb +0 -1
- data/lib/gloo_lang/app/engine.rb +10 -37
- data/lib/gloo_lang/app/help.rb +2 -41
- data/lib/gloo_lang/app/log.rb +8 -10
- data/lib/gloo_lang/app/platform.rb +75 -0
- data/lib/gloo_lang/app/settings.rb +36 -13
- data/lib/gloo_lang/objs/basic/container.rb +1 -12
- data/lib/gloo_lang/objs/basic/text.rb +2 -10
- data/lib/gloo_lang/objs/data/markdown.rb +2 -7
- data/lib/gloo_lang/objs/data/table.rb +1 -29
- data/lib/gloo_lang/verbs/show.rb +3 -2
- metadata +22 -22
- data/lib/gloo_lang/objs/cli/banner.rb +0 -108
- data/lib/gloo_lang/objs/cli/bar.rb +0 -133
- data/lib/gloo_lang/objs/cli/colorize.rb +0 -73
- data/lib/gloo_lang/objs/cli/confirm.rb +0 -96
- data/lib/gloo_lang/objs/cli/menu.rb +0 -206
- data/lib/gloo_lang/objs/cli/menu_item.rb +0 -95
- data/lib/gloo_lang/objs/cli/pastel.rb +0 -97
- data/lib/gloo_lang/objs/cli/prompt.rb +0 -110
- data/lib/gloo_lang/objs/cli/select.rb +0 -126
- data/lib/gloo_lang/objs/data/mysql.rb +0 -192
- data/lib/gloo_lang/objs/data/sqlite.rb +0 -159
- data/lib/gloo_lang/objs/dev/git.rb +0 -140
- data/lib/gloo_lang/objs/dev/stats.rb +0 -120
- data/lib/gloo_lang/objs/snd/play.rb +0 -48
- data/lib/gloo_lang/objs/snd/say.rb +0 -98
- data/lib/gloo_lang/objs/system/file_handle.rb +0 -138
- data/lib/gloo_lang/objs/system/ssh_exec.rb +0 -126
- data/lib/gloo_lang/objs/system/system.rb +0 -136
- data/lib/gloo_lang/verbs/alert.rb +0 -79
- data/lib/gloo_lang/verbs/beep.rb +0 -40
- data/lib/gloo_lang/verbs/cls.rb +0 -37
@@ -1,97 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# Show colorized output with the pastel gem.
|
5
|
-
#
|
6
|
-
require 'pastel'
|
7
|
-
|
8
|
-
module GlooLang
|
9
|
-
module Objs
|
10
|
-
class Pastel < GlooLang::Core::Obj
|
11
|
-
|
12
|
-
KEYWORD = 'pastel'.freeze
|
13
|
-
KEYWORD_SHORT = 'pastel'.freeze
|
14
|
-
TEXT = 'text'.freeze
|
15
|
-
COLOR = 'color'.freeze
|
16
|
-
|
17
|
-
#
|
18
|
-
# The name of the object type.
|
19
|
-
#
|
20
|
-
def self.typename
|
21
|
-
return KEYWORD
|
22
|
-
end
|
23
|
-
|
24
|
-
#
|
25
|
-
# The short name of the object type.
|
26
|
-
#
|
27
|
-
def self.short_typename
|
28
|
-
return KEYWORD_SHORT
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# Get the text from the child object.
|
33
|
-
#
|
34
|
-
def text_value
|
35
|
-
o = find_child TEXT
|
36
|
-
return '' unless o
|
37
|
-
|
38
|
-
return o.value
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# Get the color from the child object.
|
43
|
-
#
|
44
|
-
def color_value
|
45
|
-
o = find_child COLOR
|
46
|
-
return '' unless o
|
47
|
-
|
48
|
-
return o.value
|
49
|
-
end
|
50
|
-
|
51
|
-
# ---------------------------------------------------------------------
|
52
|
-
# Children
|
53
|
-
# ---------------------------------------------------------------------
|
54
|
-
|
55
|
-
#
|
56
|
-
# Does this object have children to add when an object
|
57
|
-
# is created in interactive mode?
|
58
|
-
# This does not apply during obj load, etc.
|
59
|
-
#
|
60
|
-
def add_children_on_create?
|
61
|
-
return true
|
62
|
-
end
|
63
|
-
|
64
|
-
#
|
65
|
-
# Add children to this object.
|
66
|
-
# This is used by containers to add children needed
|
67
|
-
# for default configurations.
|
68
|
-
#
|
69
|
-
def add_default_children
|
70
|
-
fac = $engine.factory
|
71
|
-
fac.create_string TEXT, '', self
|
72
|
-
fac.create_string COLOR, '', self
|
73
|
-
end
|
74
|
-
|
75
|
-
# ---------------------------------------------------------------------
|
76
|
-
# Messages
|
77
|
-
# ---------------------------------------------------------------------
|
78
|
-
|
79
|
-
#
|
80
|
-
# Get a list of message names that this object receives.
|
81
|
-
#
|
82
|
-
def self.messages
|
83
|
-
return super + %w[show]
|
84
|
-
end
|
85
|
-
|
86
|
-
#
|
87
|
-
# Show the banner bar
|
88
|
-
#
|
89
|
-
def msg_show
|
90
|
-
pastel = ::Pastel.new
|
91
|
-
c = self.color_value.split( ' ' ).map( &:to_sym )
|
92
|
-
puts pastel.decorate( self.text_value, *c )
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
@@ -1,110 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2019 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# Show a CLI prompt and collect user input.
|
5
|
-
#
|
6
|
-
|
7
|
-
module GlooLang
|
8
|
-
module Objs
|
9
|
-
class Prompt < GlooLang::Core::Obj
|
10
|
-
|
11
|
-
KEYWORD = 'prompt'.freeze
|
12
|
-
KEYWORD_SHORT = 'ask'.freeze
|
13
|
-
PROMPT = 'prompt'.freeze
|
14
|
-
RESULT = 'result'.freeze
|
15
|
-
|
16
|
-
#
|
17
|
-
# The name of the object type.
|
18
|
-
#
|
19
|
-
def self.typename
|
20
|
-
return KEYWORD
|
21
|
-
end
|
22
|
-
|
23
|
-
#
|
24
|
-
# The short name of the object type.
|
25
|
-
#
|
26
|
-
def self.short_typename
|
27
|
-
return KEYWORD_SHORT
|
28
|
-
end
|
29
|
-
|
30
|
-
#
|
31
|
-
# Get the prompt from the child object.
|
32
|
-
# Returns nil if there is none.
|
33
|
-
#
|
34
|
-
def prompt_value
|
35
|
-
o = find_child PROMPT
|
36
|
-
return nil unless o
|
37
|
-
|
38
|
-
return o.value
|
39
|
-
end
|
40
|
-
|
41
|
-
#
|
42
|
-
# Set the result of the system call.
|
43
|
-
#
|
44
|
-
def set_result( data )
|
45
|
-
r = find_child RESULT
|
46
|
-
return nil unless r
|
47
|
-
|
48
|
-
r.set_value data
|
49
|
-
end
|
50
|
-
|
51
|
-
# ---------------------------------------------------------------------
|
52
|
-
# Children
|
53
|
-
# ---------------------------------------------------------------------
|
54
|
-
|
55
|
-
#
|
56
|
-
# Does this object have children to add when an object
|
57
|
-
# is created in interactive mode?
|
58
|
-
# This does not apply during obj load, etc.
|
59
|
-
#
|
60
|
-
def add_children_on_create?
|
61
|
-
return true
|
62
|
-
end
|
63
|
-
|
64
|
-
#
|
65
|
-
# Add children to this object.
|
66
|
-
# This is used by containers to add children needed
|
67
|
-
# for default configurations.
|
68
|
-
#
|
69
|
-
def add_default_children
|
70
|
-
fac = $engine.factory
|
71
|
-
fac.create_string PROMPT, '>', self
|
72
|
-
fac.create_string RESULT, nil, self
|
73
|
-
end
|
74
|
-
|
75
|
-
# ---------------------------------------------------------------------
|
76
|
-
# Messages
|
77
|
-
# ---------------------------------------------------------------------
|
78
|
-
|
79
|
-
#
|
80
|
-
# Get a list of message names that this object receives.
|
81
|
-
#
|
82
|
-
def self.messages
|
83
|
-
return super + %w[run multiline]
|
84
|
-
end
|
85
|
-
|
86
|
-
#
|
87
|
-
# Show a multiline prompt and get the user's input.
|
88
|
-
#
|
89
|
-
def msg_multiline
|
90
|
-
prompt = prompt_value
|
91
|
-
return unless prompt
|
92
|
-
|
93
|
-
result = $prompt.multiline( prompt )
|
94
|
-
set_result result.join
|
95
|
-
end
|
96
|
-
|
97
|
-
#
|
98
|
-
# Show the prompt and get the user's input.
|
99
|
-
#
|
100
|
-
def msg_run
|
101
|
-
prompt = prompt_value
|
102
|
-
return unless prompt
|
103
|
-
|
104
|
-
result = $prompt.ask( prompt )
|
105
|
-
set_result result
|
106
|
-
end
|
107
|
-
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
@@ -1,126 +0,0 @@
|
|
1
|
-
# Author:: Eric Crane (mailto:eric.crane@mac.com)
|
2
|
-
# Copyright:: Copyright (c) 2020 Eric Crane. All rights reserved.
|
3
|
-
#
|
4
|
-
# Show a CLI prompt and user selection from a list.
|
5
|
-
#
|
6
|
-
|
7
|
-
module GlooLang
|
8
|
-
module Objs
|
9
|
-
class Select < GlooLang::Core::Obj
|
10
|
-
|
11
|
-
KEYWORD = 'select'.freeze
|
12
|
-
KEYWORD_SHORT = 'sel'.freeze
|
13
|
-
PROMPT = 'prompt'.freeze
|
14
|
-
OPTIONS = 'options'.freeze
|
15
|
-
RESULT = 'result'.freeze
|
16
|
-
|
17
|
-
#
|
18
|
-
# The name of the object type.
|
19
|
-
#
|
20
|
-
def self.typename
|
21
|
-
return KEYWORD
|
22
|
-
end
|
23
|
-
|
24
|
-
#
|
25
|
-
# The short name of the object type.
|
26
|
-
#
|
27
|
-
def self.short_typename
|
28
|
-
return KEYWORD_SHORT
|
29
|
-
end
|
30
|
-
|
31
|
-
#
|
32
|
-
# Get the prompt from the child object.
|
33
|
-
# Returns nil if there is none.
|
34
|
-
#
|
35
|
-
def prompt_value
|
36
|
-
o = find_child PROMPT
|
37
|
-
return nil unless o
|
38
|
-
|
39
|
-
return o.value
|
40
|
-
end
|
41
|
-
|
42
|
-
#
|
43
|
-
# Get the list of options for selection.
|
44
|
-
#
|
45
|
-
def options
|
46
|
-
o = find_child OPTIONS
|
47
|
-
return [] unless o
|
48
|
-
|
49
|
-
return o.children.map( &:name )
|
50
|
-
end
|
51
|
-
|
52
|
-
#
|
53
|
-
# Get the value of the selected item.
|
54
|
-
#
|
55
|
-
def key_for_option( selected )
|
56
|
-
o = find_child OPTIONS
|
57
|
-
return nil unless o
|
58
|
-
|
59
|
-
o.children.each do |c|
|
60
|
-
return c.value if c.name == selected
|
61
|
-
end
|
62
|
-
|
63
|
-
return nil
|
64
|
-
end
|
65
|
-
|
66
|
-
#
|
67
|
-
# Set the result of the system call.
|
68
|
-
#
|
69
|
-
def set_result( data )
|
70
|
-
r = find_child RESULT
|
71
|
-
return nil unless r
|
72
|
-
|
73
|
-
r.set_value data
|
74
|
-
end
|
75
|
-
|
76
|
-
# ---------------------------------------------------------------------
|
77
|
-
# Children
|
78
|
-
# ---------------------------------------------------------------------
|
79
|
-
|
80
|
-
#
|
81
|
-
# Does this object have children to add when an object
|
82
|
-
# is created in interactive mode?
|
83
|
-
# This does not apply during obj load, etc.
|
84
|
-
#
|
85
|
-
def add_children_on_create?
|
86
|
-
return true
|
87
|
-
end
|
88
|
-
|
89
|
-
#
|
90
|
-
# Add children to this object.
|
91
|
-
# This is used by containers to add children needed
|
92
|
-
# for default configurations.
|
93
|
-
#
|
94
|
-
def add_default_children
|
95
|
-
fac = $engine.factory
|
96
|
-
fac.create_string PROMPT, '>', self
|
97
|
-
fac.create_can OPTIONS, self
|
98
|
-
fac.create_string RESULT, nil, self
|
99
|
-
end
|
100
|
-
|
101
|
-
# ---------------------------------------------------------------------
|
102
|
-
# Messages
|
103
|
-
# ---------------------------------------------------------------------
|
104
|
-
|
105
|
-
#
|
106
|
-
# Get a list of message names that this object receives.
|
107
|
-
#
|
108
|
-
def self.messages
|
109
|
-
return super + %w[run]
|
110
|
-
end
|
111
|
-
|
112
|
-
#
|
113
|
-
# Show the prompt and get the user's selection.
|
114
|
-
#
|
115
|
-
def msg_run
|
116
|
-
prompt = prompt_value
|
117
|
-
return unless prompt
|
118
|
-
|
119
|
-
per = GlooLang::App::Settings.page_size
|
120
|
-
result = $prompt.select( prompt, options, :per_page => per )
|
121
|
-
set_result self.key_for_option( result )
|
122
|
-
end
|
123
|
-
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
@@ -1,192 +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 GlooLang
|
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( 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( 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( 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( 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
|
@@ -1,159 +0,0 @@
|
|
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 GlooLang
|
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
|