storazzo 0.5.7 → 0.6.1
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 +4 -4
- data/Gemfile +7 -5
- data/Makefile +8 -6
- data/Rakefile +15 -13
- data/VERSION +1 -1
- data/bin/hello-storazzo +1 -0
- data/bin/ricdisk-magic +33 -30
- data/bin/stats-with-md5 +182 -157
- data/bin/storazzo +112 -114
- data/bin/storazzo-symlink.rb +1 -0
- data/lib/storazzo/colors.rb +77 -36
- data/lib/storazzo/common.rb +72 -68
- data/lib/storazzo/debug.rb +2 -0
- data/lib/storazzo/hashify.rb +7 -5
- data/lib/storazzo/main.rb +59 -49
- data/lib/storazzo/media/abstract_ric_disk.rb +188 -179
- data/lib/storazzo/media/gcs_bucket.rb +76 -58
- data/lib/storazzo/media/local_folder.rb +56 -42
- data/lib/storazzo/media/mount_point.rb +20 -12
- data/lib/storazzo/ric_disk.rb +386 -383
- data/lib/storazzo/ric_disk_config.rb +227 -209
- data/lib/storazzo/ric_disk_sample_config.rb +26 -24
- data/lib/storazzo/ric_disk_statsfile.rb +19 -17
- data/lib/storazzo/ric_disk_ugly.rb +1 -0
- data/lib/storazzo/version.rb +3 -3
- data/lib/storazzo.rb +6 -7
- data/storazzo.gemspec +24 -16
- data/test/benchmark/for_future_use.rb +4 -2
- data/test/benchmark/test_hashing_functions-speed.rb +17 -0
- data/test/bin/new-idea.rb +17 -0
- data/test/bin/storazzo.rb +22 -25
- data/test/media/test_abstract_ric_disk.rb +5 -3
- data/test/media/test_gcs_bucket.rb +24 -23
- data/test/media/test_local_folder.rb +24 -23
- data/test/media/test_mount_point.rb +6 -5
- data/test/test_ric_disk.rb +6 -4
- data/test/test_ric_disk_config.rb +12 -11
- data/test/test_ric_disk_stats_file.rb +5 -3
- data/test/test_storazzo.rb +6 -4
- data/var/test/disks/disk02-full/Rakefile +7 -5
- data/var/test/disks/ricdisk_stats_v11.rds +11 -0
- metadata +13 -21
data/bin/storazzo
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'storazzo'
|
4
|
-
#gem 'storazzo', :path => File.expand_path("../lib", __FILE__)
|
5
|
+
# gem 'storazzo', :path => File.expand_path("../lib", __FILE__)
|
5
6
|
|
6
7
|
require 'optparse'
|
7
8
|
|
@@ -9,152 +10,149 @@ extend Storazzo::Colors
|
|
9
10
|
include Storazzo::Common # instead
|
10
11
|
|
11
12
|
if RUBY_VERSION.split('.')[0] == 1
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
puts 'Refusing to launch a script form Ruby 1. Sorry Ric, its 2020 damn it!'
|
14
|
+
exit 2020
|
15
|
+
end
|
15
16
|
|
16
17
|
$PROG_VER = '0.1'
|
17
18
|
$DEBUG = ENV['DEBUG'] == 'true' # (true/false)
|
18
19
|
|
19
|
-
$actions = %w
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
$actions = %w[
|
21
|
+
show auto help
|
22
|
+
].sort
|
23
23
|
|
24
24
|
# you can't but love Ruby monkey-patching ability..
|
25
25
|
class Array
|
26
26
|
# puts "array drop"
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
def tail
|
28
|
+
drop(1) # https://stackoverflow.com/questions/3615700/ruby-what-is-the-easiest-way-to-remove-the-first-element-from-an-array
|
29
|
+
end
|
30
30
|
end
|
31
31
|
|
32
32
|
HISTORY = <<-BIG_LONG_MULTILINE
|
33
33
|
2022-0806 v0.1 First stesure
|
34
34
|
BIG_LONG_MULTILINE
|
35
35
|
|
36
|
-
|
37
|
-
$description = <<DESCRIPTION_HEREFILE.gsub(/\s+/, " ").strip
|
36
|
+
$description = <<DESCRIPTION_HEREFILE.gsub(/\s+/, ' ').strip
|
38
37
|
This util shall expose all Storazzo aPIs via CLI: show-local-dirs, ...
|
39
38
|
show GCS buckets, ...
|
40
39
|
|
41
40
|
It's also my dream to add some nice icons which are joy to the eye, like
|
42
|
-
some [ ] [x] before the list to show if its agood or bad directory and type also
|
41
|
+
some [ ] [x] before the list to show if its agood or bad directory and type also#{' '}
|
43
42
|
DESCRIPTION_HEREFILE
|
44
43
|
# >> "SELECT * FROM users ORDER BY users.id DESC"
|
45
44
|
|
46
45
|
$myconf = {
|
47
|
-
:
|
48
|
-
:
|
49
|
-
# TODO move to some class default
|
50
|
-
|
46
|
+
app_name: "Storazzo CLI: #{$PROGRAM_NAME}",
|
47
|
+
description: $description
|
48
|
+
# TODO: move to some class default
|
49
|
+
# :media_dirs => %w{/media/riccardo/ /Volumes/ /mnt/ ~/git/storazzo/var/test/
|
51
50
|
# /sobenme/giusto/per/imparare/ad/ammutolire/gli/errori/},
|
52
|
-
|
51
|
+
# :mount_types => %w{vfat ntfs},
|
53
52
|
}
|
54
53
|
|
55
54
|
def usage(comment = nil)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
55
|
+
puts white($optparse.banner)
|
56
|
+
puts($optparse.summarize)
|
57
|
+
# puts("Description: " + gray($myconf[:description]))
|
58
|
+
puts red("ERROR: #{comment}") if comment
|
59
|
+
# puts "Description: #{ $myconf[:description] }"
|
60
|
+
exit 13
|
61
|
+
end
|
63
62
|
|
64
63
|
# include it in main if you want a custome one
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
opts
|
82
|
-
|
83
|
-
opts.on('-n', '--dryrun', "Don't really execute code") { $opts[:dryrun] = true }
|
84
|
-
opts.on('-l', '--logfile FILE', 'Write log to FILE') { |file| $opts[:logfile] = file }
|
85
|
-
opts.on('-v', '--verbose', 'Output more information') { $opts[:verbose] = true }
|
86
|
-
opts.separator("Description: " + gray($myconf[:description]))
|
87
|
-
#opts.separator " -- "
|
64
|
+
# see lib_autoinit in lib/util.rb
|
65
|
+
def init
|
66
|
+
$opts = {}
|
67
|
+
# setting defaults
|
68
|
+
$opts[:verbose] = false
|
69
|
+
$opts[:dryrun] = false
|
70
|
+
$opts[:debug] = false
|
71
|
+
$opts[:force] = false
|
72
|
+
|
73
|
+
$optparse = OptionParser.new do |opts|
|
74
|
+
opts.banner = "#{$PROGRAM_NAME} v.#{$PROG_VER}\n Usage: #{File.basename $PROGRAM_NAME} [options] ACTION [file1] [file2] ..."
|
75
|
+
opts.separator "Actions: #{$actions.join ', '}"
|
76
|
+
opts.separator ' $0 show # show options and local folders '
|
77
|
+
opts.separator ' $0 auto # takes automated actions based on config and local disk. For lazy users'
|
78
|
+
opts.separator 'Options: '
|
79
|
+
opts.on('-d', '--debug', 'enables debug (DFLT=false)') do
|
80
|
+
$opts[:debug] = true
|
81
|
+
$DEBUG = true
|
88
82
|
end
|
89
|
-
$
|
83
|
+
opts.on('-f', '--force', 'force stuff (DFLT=false)') { $opts[:force] = true }
|
84
|
+
opts.on('-h', '--help', 'Display this screen') { usage }
|
85
|
+
# opts.on( '-j', '--jabba', 'Activates my Jabber powerful CLI' ) { $opts[:jabba] = true }
|
86
|
+
opts.on('-n', '--dryrun', "Don't really execute code") { $opts[:dryrun] = true }
|
87
|
+
opts.on('-l', '--logfile FILE', 'Write log to FILE') { |file| $opts[:logfile] = file }
|
88
|
+
opts.on('-v', '--verbose', 'Output more information') { $opts[:verbose] = true }
|
89
|
+
opts.separator("Description: #{gray($myconf[:description])}")
|
90
|
+
# opts.separator " -- "
|
90
91
|
end
|
92
|
+
$optparse.parse!
|
93
|
+
end
|
91
94
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
def real_program
|
104
|
-
deb("Hello world from a templated '#{yellow $0}'")
|
105
|
-
deb "+ Options are: #{gray $opts}"
|
106
|
-
deb "+ Depured args: #{azure ARGV}"
|
107
|
-
deb "+ Script-specifig super-cool conf: #{green $prog_conf_d}"
|
108
|
-
deb "+ Your configuration: #{purple $myconf.inspect}"
|
109
|
-
|
110
|
-
# Your code goes here...
|
111
|
-
puts white("Hello world from #{$myconf[:app_name]}!")
|
112
|
-
puts "Description: '''#{white $myconf[:description]}'''"
|
113
|
-
Storazzo::Main.say_hi("Note: if the version of this storazzo is behind local version youre probably using a old library.
|
114
|
-
I still need to learn how to call the binary with local/current lib/: bundle exec stiKazzi?")
|
115
|
-
|
116
|
-
$config = Storazzo::RicDiskConfig.instance()
|
117
|
-
$config.load
|
118
|
-
deb "StorazzoConfig: #{$config}"
|
119
|
-
# config.load # auto_sbrodola(ARGV)
|
120
|
-
puts yellow("ARGV: #{ARGV}")
|
121
|
-
#config.iterate_through_file_list_for_disks(ARGV)
|
122
|
-
|
123
|
-
if_deb? { Storazzo::Main.say_hi("ARGV: #{ARGV}") }
|
95
|
+
def show_action(argv)
|
96
|
+
deb "ARGV remaning is: #{argv}"
|
97
|
+
deb('TODO show_action')
|
98
|
+
# puts(white("1. Config"))
|
99
|
+
# Pry::ColorPrinter.pp $config.to_verbose_s
|
100
|
+
puts(white('2. Mounts/Dirs'))
|
101
|
+
Pry::ColorPrinter.pp Storazzo::Media::GcsBucket.list_all_with_type
|
102
|
+
pp Storazzo::Media::AbstractRicDisk.super_duper_list_all_with_type
|
103
|
+
end
|
124
104
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
usage("Unknown action1: #{argv_action}. Available actions: #{$actions}")
|
138
|
-
else
|
139
|
-
usage("Unknown action2, really strange!: '#{argv_action}'. Actions: #{$actions}")
|
140
|
-
end
|
105
|
+
def real_program
|
106
|
+
deb("Hello world from a templated '#{yellow $PROGRAM_NAME}'")
|
107
|
+
deb "+ Options are: #{gray $opts}"
|
108
|
+
deb "+ Depured args: #{azure ARGV}"
|
109
|
+
deb "+ Script-specifig super-cool conf: #{green $prog_conf_d}"
|
110
|
+
deb "+ Your configuration: #{purple $myconf.inspect}"
|
111
|
+
|
112
|
+
# Your code goes here...
|
113
|
+
puts white("Hello world from #{$myconf[:app_name]}!")
|
114
|
+
puts "Description: '''#{white $myconf[:description]}'''"
|
115
|
+
Storazzo::Main.say_hi("Note: if the version of this storazzo is behind local version youre probably using a old library.
|
116
|
+
I still need to learn how to call the binary with local/current lib/: bundle exec stiKazzi?")
|
141
117
|
|
118
|
+
$config = Storazzo::RicDiskConfig.instance
|
119
|
+
$config.load
|
120
|
+
deb "StorazzoConfig: #{$config}"
|
121
|
+
# config.load # auto_sbrodola(ARGV)
|
122
|
+
puts yellow("ARGV: #{ARGV}")
|
123
|
+
# config.iterate_through_file_list_for_disks(ARGV)
|
124
|
+
|
125
|
+
if_deb? { Storazzo::Main.say_hi("ARGV: #{ARGV}") }
|
126
|
+
|
127
|
+
usage('I need at least one argument (storazzo ACTION)') if ARGV == []
|
128
|
+
argv_action = ARGV[0]
|
129
|
+
case argv_action # first argment - action
|
130
|
+
when 'show', 'list'
|
131
|
+
show_action(ARGV.tail)
|
132
|
+
when 'auto'
|
133
|
+
auto_action(ARGV.tail)
|
134
|
+
when 'help'
|
135
|
+
usage("There you go, here's your HELP :)")
|
136
|
+
when String
|
137
|
+
usage("Unknown action1: #{argv_action}. Available actions: #{$actions}")
|
138
|
+
else
|
139
|
+
usage("Unknown action2, really strange!: '#{argv_action}'. Actions: #{$actions}")
|
142
140
|
end
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
141
|
+
end
|
142
|
+
|
143
|
+
def main(filename)
|
144
|
+
deb "I'm called by #{white filename}"
|
145
|
+
deb "HISTORY: #{gray HISTORY}"
|
146
|
+
init # Enable this to have command line parsing capabilities!
|
147
|
+
puts white("$DEBUG is #{$DEBUG}. Tu turn on, call me with -d") unless $DEBUG
|
148
|
+
# warn "[warn] template v#{$TEMPLATE_VER }: proviamo il warn che magari depreca il DEB"
|
149
|
+
real_program
|
150
|
+
|
151
|
+
if_deb? do
|
152
|
+
puts 'First I need to figure out how to bring in all the libraries in here..'
|
153
|
+
Storazzo::Main.say_hi("ARGV is: #{ARGV.join ', '}")
|
154
|
+
puts Storazzo.version
|
157
155
|
end
|
158
|
-
|
156
|
+
end
|
159
157
|
|
160
|
-
|
158
|
+
main(__FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
bin/storazzo
|
data/lib/storazzo/colors.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Use EXTEND vs INCLUDE and magically the Class will inherit instead of instance. Magical! :)
|
2
4
|
# http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/
|
3
5
|
#
|
@@ -9,41 +11,80 @@ module Storazzo
|
|
9
11
|
# needs to be defined before
|
10
12
|
end
|
11
13
|
|
12
|
-
module Storazzo
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
14
|
+
module Storazzo
|
15
|
+
module Colors
|
16
|
+
PREPEND_ME = '[Storazzo::Colors] '
|
17
|
+
|
18
|
+
def deb2(s)
|
19
|
+
puts "#DEB_OBSOLETE #{gray(s)} [include Storazzo::Common instead]" if $DEBUG
|
20
|
+
end
|
21
|
+
|
22
|
+
# colors 16
|
23
|
+
def yellow(s)
|
24
|
+
"\033[1;33m#{s}\033[0m"
|
25
|
+
end
|
26
|
+
|
27
|
+
def gray(s)
|
28
|
+
"\033[1;30m#{s}\033[0m"
|
29
|
+
end
|
30
|
+
|
31
|
+
def green(s)
|
32
|
+
"\033[1;32m#{s}\033[0m"
|
33
|
+
end
|
34
|
+
|
35
|
+
def red(s)
|
36
|
+
"\033[1;31m#{s}\033[0m"
|
37
|
+
end
|
38
|
+
|
39
|
+
def blue(s)
|
40
|
+
"\033[1;34m#{s}\033[0m"
|
41
|
+
end
|
42
|
+
|
43
|
+
def purple(s)
|
44
|
+
"\033[1;35m#{s}\033[0m"
|
45
|
+
end
|
46
|
+
|
47
|
+
def azure(s)
|
48
|
+
"\033[1;36m#{s}\033[0m"
|
49
|
+
end
|
50
|
+
|
51
|
+
def white(s)
|
52
|
+
"\033[1;37m#{s}\033[0m"
|
53
|
+
end
|
54
|
+
|
55
|
+
# colors 64k
|
56
|
+
def orange(s)
|
57
|
+
"\033[38;5;208m#{s}\033[0m"
|
58
|
+
end
|
59
|
+
|
60
|
+
# i dont undertstand why i need self :/
|
61
|
+
# SELF version because I'm just stupid or lazy or both.
|
62
|
+
# def self.yellow(s) "#{PREPEND_ME}\033[1;33m#{s}\033[0m" ; end
|
63
|
+
# def self.green(s) "#{PREPEND_ME}\033[1;32m#{s}\033[0m" ; end
|
64
|
+
# def self.gray(s) "#{PREPEND_ME}\033[1;30m#{s}\033[0m" ; end
|
65
|
+
# def self.green(s) "#{PREPEND_ME}\033[1;32m#{s}\033[0m" ; end
|
66
|
+
# def self.red(s) "#{PREPEND_ME}\033[1;31m#{s}\033[0m" ; end
|
67
|
+
# def self.blue(s) "#{PREPEND_ME}\033[1;34m#{s}\033[0m" ; end
|
68
|
+
# def self.purple(s) "#{PREPEND_ME}\033[1;35m#{s}\033[0m" ; end
|
69
|
+
# def self.azure(s) "#{PREPEND_ME}\033[1;36m#{s}\033[0m" ; end
|
70
|
+
# def self.white(s) "#{PREPEND_ME}\033[1;37m#{s}\033[0m" ; end
|
71
|
+
|
72
|
+
# p<COLOR> Carlessian functions..
|
73
|
+
def pwhite(s)
|
74
|
+
puts(white(s))
|
75
|
+
end
|
76
|
+
|
77
|
+
def pgreen(s)
|
78
|
+
puts(green(s))
|
79
|
+
end
|
80
|
+
|
81
|
+
def pred(s)
|
82
|
+
puts(red(s))
|
83
|
+
end
|
84
|
+
|
85
|
+
def pyellow(s)
|
86
|
+
puts(yellow(s))
|
87
|
+
end
|
88
|
+
end
|
48
89
|
end
|
49
90
|
# end
|
data/lib/storazzo/common.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Ric common stuff! :)
|
2
4
|
#
|
3
5
|
# Usage:
|
@@ -5,89 +7,91 @@
|
|
5
7
|
# or
|
6
8
|
# extend Storazzo::Common (def to def self.XX)
|
7
9
|
#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
🧏 🦻 🦮 🦯 🦺 🦼 🦽 🦾 🦿 🤵 👮 👷 💁 💂 🕴 🕵 🦸 🦹 🧙 🧚 🧜 🧝 🧞 🧛 🧟 👼 👿 👻 👹 👺 👽 👾 🛸 💀 ☠ 🕱 🧠 🦴 👁 👀 👂 👃 👄 🗢 👅 🦷 🦵 🦶 💭 🗬 🗭 💬 🗨 🗩 🗪 🗫 🗰 🗱 🗮 🗯 🗣 🗤 🗥 🗦 🗧 💦 💧 💢 💫 💤 💨 💥 💪 🗲 🔥 💡 💩 💯 🔟 🔰 🕲
|
29
|
-
=end
|
10
|
+
# Emoji to copy:
|
11
|
+
# 👍 👎 👌 ✌ 👋 🤝 👏 🤘 🤟 🤙 🤏 🙌 🙏 🖖 🤞 ✋ 🤚 🖐 🖑 🤲 👐 👊 🤛 🤜 🖕
|
12
|
+
# 👈 👉 👆 👇
|
13
|
+
# ☺ ☻ 😃 😄 😅 😆 😊 😎 😇 😈 😏 🤣 🤩 🤪 🥳 😁 😀 😂 🤠 🤡 🤑 🤓 🤖 kiss
|
14
|
+
# 😗 😚 😘 😙 flirting
|
15
|
+
# 😉 🤗 😍 🥰 🤤 😋 😛 😜 😝 neutral
|
16
|
+
# 😶 🙃 😐 😑 🤔 🤨 🧐 hush
|
17
|
+
# 🤭 🤫 😯 🤐 😌 😖 😕 😳 😔 🤥 🥴 shocked
|
18
|
+
# 😮 😲 🤯 tired
|
19
|
+
# 😩 😫 🥱 😪 😴 😵 sad
|
20
|
+
# ☹ 😦 😞 😥 😟 cry
|
21
|
+
# 😢 😭 sick
|
22
|
+
# 🤢 🤮 😷 🤒 🤕 🥵 🥶 fear
|
23
|
+
# 🥺 😬 😓 😰 😨 😱 angry
|
24
|
+
# 😒 😠 😡 😤 😣 😧 🤬 😸 😹 😺 😻 😼 😽 😾 😿 🙀 🙈 🙉 🙊
|
25
|
+
# [see Animal Emoji 🐰] gesture
|
26
|
+
# 🤦 🤷 🙅 🙆 🙋 🙌 🙍 🙎 🙇 🙏 activity
|
27
|
+
# 👯 💃 🕺 🤳 💇 💈 💆 🧖 🧘 🧍 🧎 👰 🤰 🤱 faces
|
28
|
+
# 👶 🧒 👦 👧 👩 👨 🧑 🧔 🧓 👴 👵 👤 👥 👪 👫 👬 👭 👱 👳 👲 🧕 👸 🤴 🎅 🤶 disabled
|
29
|
+
# 🧏 🦻 🦮 🦯 🦺 🦼 🦽 🦾 🦿 🤵 👮 👷 💁 💂 🕴 🕵 🦸 🦹 🧙 🧚 🧜 🧝 🧞 🧛 🧟 👼 👿 👻 👹 👺 👽 👾 🛸 💀 ☠ 🕱 🧠 🦴 👁 👀 👂 👃 👄 🗢 👅 🦷 🦵 🦶 💭 🗬 🗭 💬 🗨 🗩 🗪 🗫 🗰 🗱 🗮 🗯 🗣 🗤 🗥 🗦 🗧 💦 💧 💢 💫 💤 💨 💥 💪 🗲 🔥 💡 💩 💯 🔟 🔰 🕲
|
30
30
|
require_relative 'colors'
|
31
31
|
require 'pry'
|
32
32
|
|
33
|
-
module Storazzo
|
34
|
-
|
33
|
+
module Storazzo
|
34
|
+
module Common
|
35
|
+
include Storazzo::Colors
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
def deb(s)
|
38
|
+
# useless: put logic in _debug_true() # return if ENV['RUBYOPT'] == "-W0"
|
39
|
+
puts "[DEB👀] #{yellow(s)}" if _debug_true # $DEBUG
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
# this has a yield
|
43
|
+
def if_deb?
|
44
|
+
if _debug_true # $DEBUG
|
45
|
+
deb '== yield START =='
|
46
|
+
yield
|
47
|
+
deb '== yield END =='
|
48
|
+
end
|
47
49
|
end
|
48
|
-
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
def warn(s)
|
52
|
+
puts "[W⚠️RN] #{azure(s)}"
|
53
|
+
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
def err(_str)
|
56
|
+
puts "[ERR👎] #{red(s)}" # ⛔
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
def bug(s)
|
60
|
+
puts "[🐛] #{gray s}"
|
61
|
+
end
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
puts "[🦋🐛🐝🐞🐜🕷🕸🦂🦗🦟] #{gray str}" # insects: http://xahlee.info/comp/unicode_insects.html
|
66
|
-
end
|
63
|
+
def pverbose(_is_verbose, str)
|
64
|
+
# puts "[V📚RB💀S📚] #{gray str}"
|
65
|
+
return if ENV['RUBYOPT'] == '-W0'
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
Pry::ColorPrinter.pp(complex_object_to_colorize)
|
71
|
-
end
|
67
|
+
puts "[🦋🐛🐝🐞🐜🕷🕸🦂🦗🦟] #{gray str}" # insects: http://xahlee.info/comp/unicode_insects.html
|
68
|
+
end
|
72
69
|
|
73
|
-
|
74
|
-
|
75
|
-
|
70
|
+
def ppp(complex_object_to_colorize)
|
71
|
+
# TODO: i need to learn to return without printing..
|
72
|
+
Pry::ColorPrinter.pp(complex_object_to_colorize)
|
73
|
+
end
|
76
74
|
|
77
|
-
|
78
|
-
|
79
|
-
|
75
|
+
def fatal(s)
|
76
|
+
raise "[F💀TAL] #{red s}"
|
77
|
+
end
|
80
78
|
|
81
|
-
|
82
|
-
|
83
|
-
|
79
|
+
def mac?
|
80
|
+
`uname`.chomp == 'Darwin'
|
81
|
+
end
|
84
82
|
|
85
|
-
|
83
|
+
def linux?
|
84
|
+
`uname`.chomp == 'Linux'
|
85
|
+
end
|
86
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
87
|
+
private
|
88
|
+
|
89
|
+
def _debug_true
|
90
|
+
return false if ENV['RUBYOPT'] == '-W0'
|
91
91
|
|
92
|
-
|
92
|
+
$DEBUG or ENV['DEBUG'] == 'true' # but FALSE isor _debug_true
|
93
|
+
end
|
94
|
+
|
95
|
+
# puts "[DEBUG ENABLED!]" if _debug_true
|
96
|
+
end
|
93
97
|
end
|
data/lib/storazzo/debug.rb
CHANGED
data/lib/storazzo/hashify.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# copied from https://dev.to/ayushn21/how-to-generate-yaml-from-ruby-objects-without-type-annotations-4fli
|
2
4
|
module Storazzo
|
3
5
|
module Hashify
|
@@ -20,19 +22,19 @@ module Storazzo
|
|
20
22
|
value = instance_variable_get(var)
|
21
23
|
value = value.map(&:to_hash) if value.is_a? Array
|
22
24
|
|
23
|
-
hash[var.to_s.delete(
|
25
|
+
hash[var.to_s.delete('@')] = value
|
24
26
|
end
|
25
27
|
|
26
|
-
|
28
|
+
hash
|
27
29
|
end
|
28
30
|
|
29
31
|
def obj_to_hash
|
30
32
|
h = {}
|
31
33
|
puts self
|
32
|
-
|
34
|
+
instance_variables.each do |var|
|
33
35
|
# puts var
|
34
|
-
h[var.to_s.delete('@')] =
|
35
|
-
|
36
|
+
h[var.to_s.delete('@')] = instance_variable_get(var) # send(var.to_s.delete('@'))
|
37
|
+
end
|
36
38
|
h
|
37
39
|
end
|
38
40
|
|