yobou 1.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.
- checksums.yaml +7 -0
- data/lib/yobou.rb +71 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e93208a9692eef54c79cdedfc45f41669208c7b72b6939d7b130211fd220d86d
|
4
|
+
data.tar.gz: 20f6b80cc3528f61e70445023fe159e3fc8f72fd16c2f3da8ed4bbcbc3a5edc7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: afff8ac691741bce7ba44494464430f2a2c3f52171d36901b9a8fae2462edf3ddded8726641391ad1e929d18cdc0328b83c70e928617e5030b36a044f2f72360
|
7
|
+
data.tar.gz: 67150a005e5cab0bda3cf7978325c20d4293f8b82a6bb5e8c00c03740e364bf5f0e3a0677fdf250d85116d9fd575daec791a2a53acaf7f5ba83616ff04390973
|
data/lib/yobou.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'open3'
|
4
|
+
|
5
|
+
class Yobou
|
6
|
+
|
7
|
+
# Generates a `.sql` file using the `mysqldump` command
|
8
|
+
#
|
9
|
+
# @param host [String] the hostname of the database
|
10
|
+
# @param username [String] the username for the database connection
|
11
|
+
# @param password [String] the password for the database connection
|
12
|
+
# @param database [String] the name of the database
|
13
|
+
# @param filename [String] a path on the filesystem where the generated dump should be saved
|
14
|
+
# @return [Response] a `Response` object having a +bool+ `success` attribute and +Array<String>+ `errors` attribute
|
15
|
+
#
|
16
|
+
def self.dump(host: '127.0.0.1', username:, password:, database:, filename:)
|
17
|
+
command = "mysqldump -h #{host} -u #{username} -p#{password} #{database} > #{filename}"
|
18
|
+
Open3.popen3(command) do |_stdin, _stdout, stderr, wait_thr|
|
19
|
+
raise "Failed to dump database: #{stderr.read}" unless wait_thr.value.success?
|
20
|
+
end
|
21
|
+
|
22
|
+
Response.new(true)
|
23
|
+
rescue StandardError => e
|
24
|
+
Response.new(false, [e.message])
|
25
|
+
end
|
26
|
+
|
27
|
+
# Loads a `.sql` file using the `mysql` command
|
28
|
+
#
|
29
|
+
# @param host [String] the hostname of the database
|
30
|
+
# @param username [String] the username for the database connection
|
31
|
+
# @param password [String] the password for the database connection
|
32
|
+
# @param database [String] the name of the database
|
33
|
+
# @param filename [String] the path on the filesystem to the .sql file that should be loaded
|
34
|
+
# @param drop_existing [Boolean] whether an existing database with the same name should be dropped before loading the SQL file
|
35
|
+
# @return [Response] a `Response` object having a +bool+ `success` attribute and +Array<String>+ `errors` attribute
|
36
|
+
#
|
37
|
+
# noinspection RubyMismatchedReturnType
|
38
|
+
def self.load(host: '127.0.0.1', username:, password:, database:, filename:, drop_existing: true)
|
39
|
+
if drop_existing
|
40
|
+
command = "mysql -h #{host} -u #{username} -p#{password} -e \"DROP DATABASE IF EXISTS #{database}\""
|
41
|
+
Open3.popen3(command) do |_stdin, _stdout, stderr, wait_thr|
|
42
|
+
raise "Failed to drop database: #{stderr.read}" unless wait_thr.value.success?
|
43
|
+
end
|
44
|
+
command = "mysql -h #{host} -u #{username} -p#{password} -e \"CREATE DATABASE #{database}\""
|
45
|
+
Open3.popen3(command) do |_stdin, _stdout, stderr, wait_thr|
|
46
|
+
raise "Failed to create database: #{stderr.read}" unless wait_thr.value.success?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
command = "mysql -h #{host} -u #{username} -p#{password} #{database} < #{filename}"
|
50
|
+
Open3.popen3(command) do |_stdin, _stdout, stderr, wait_thr|
|
51
|
+
raise "Failed to load database: #{stderr.read}" unless wait_thr.value.success?
|
52
|
+
end
|
53
|
+
|
54
|
+
Response.new(true)
|
55
|
+
rescue StandardError => e
|
56
|
+
Response.new(false, [e.message])
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
class Response
|
62
|
+
attr_accessor :success, :errors
|
63
|
+
|
64
|
+
def initialize(success, errors = [])
|
65
|
+
@success = success
|
66
|
+
@errors = errors
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yobou
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vincenzo Strumbo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-expectations
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-mocks
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: mysql2
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A simple mysql/mysqldump wrapper
|
70
|
+
email:
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- lib/yobou.rb
|
76
|
+
homepage: https://rubygems.org/gems/yobou
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubygems_version: 3.3.7
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: A simple mysql/mysqldump wrapper
|
99
|
+
test_files: []
|