storazzo 0.4.10 → 0.5.2

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.
@@ -1,51 +1,49 @@
1
1
  # Use EXTEND vs INCLUDE and magically the Class will inherit instead of instance. Magical! :)
2
2
  # http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/
3
- #
4
- # include Storazzo::Colors
5
- # extend Storazzo::Colors
6
- #
3
+ #
4
+ # include Storazzo::Colors
5
+ # extend Storazzo::Colors
6
+ #
7
7
 
8
- module Storazzo
9
- # needs to be defined before
10
- end
8
+ module Storazzo
9
+ # needs to be defined before
10
+ end
11
11
 
12
12
  module Storazzo::Colors
13
-
14
- PREPEND_ME = "[Storazzo::Colors] "
15
-
16
-
17
- def deb2(s); puts "#DEB_OBSOLETE #{gray(s)} [include Storazzo::Common instead]" if $DEBUG; end # Use the Common instead
18
-
19
- # colors 16
20
- def yellow(s) "\033[1;33m#{s}\033[0m" ; end
21
- def gray(s) "\033[1;30m#{s}\033[0m" ; end
22
- def green(s) "\033[1;32m#{s}\033[0m" ; end
23
- def red(s) "\033[1;31m#{s}\033[0m" ; end
24
- def blue(s) "\033[1;34m#{s}\033[0m" ; end
25
- def purple(s) "\033[1;35m#{s}\033[0m" ; end
26
- def azure(s) "\033[1;36m#{s}\033[0m" ; end
27
- def white(s) "\033[1;37m#{s}\033[0m" ; end
28
-
29
- # colors 64k
30
- def orange(s) "\033[38;5;208m#{s}\033[0m" ; end
31
-
32
- # i dont undertstand why i need self :/
33
- # SELF version because I'm just stupid or lazy or both.
34
- # def self.yellow(s) "#{PREPEND_ME}\033[1;33m#{s}\033[0m" ; end
35
- # def self.green(s) "#{PREPEND_ME}\033[1;32m#{s}\033[0m" ; end
36
- # def self.gray(s) "#{PREPEND_ME}\033[1;30m#{s}\033[0m" ; end
37
- # def self.green(s) "#{PREPEND_ME}\033[1;32m#{s}\033[0m" ; end
38
- # def self.red(s) "#{PREPEND_ME}\033[1;31m#{s}\033[0m" ; end
39
- # def self.blue(s) "#{PREPEND_ME}\033[1;34m#{s}\033[0m" ; end
40
- # def self.purple(s) "#{PREPEND_ME}\033[1;35m#{s}\033[0m" ; end
41
- # def self.azure(s) "#{PREPEND_ME}\033[1;36m#{s}\033[0m" ; end
42
- # def self.white(s) "#{PREPEND_ME}\033[1;37m#{s}\033[0m" ; end
43
-
44
- # p<COLOR> Carlessian functions..
45
- def pwhite(s) puts(white(s)); end
46
- def pgreen(s) puts(green(s)); end
47
- def pred(s) puts(red(s)); end
48
- def pyellow(s) puts(yellow(s)); end
49
-
13
+ PREPEND_ME = "[Storazzo::Colors] "
14
+
15
+ def deb2(s);
16
+ puts "#DEB_OBSOLETE #{gray(s)} [include Storazzo::Common instead]" if $DEBUG; end # Use the Common instead
17
+
18
+ # colors 16
19
+ def yellow(s) "\033[1;33m#{s}\033[0m"; end
20
+ def gray(s) "\033[1;30m#{s}\033[0m"; end
21
+ def green(s) "\033[1;32m#{s}\033[0m"; end
22
+ def red(s) "\033[1;31m#{s}\033[0m"; end
23
+ def blue(s) "\033[1;34m#{s}\033[0m"; end
24
+ def purple(s) "\033[1;35m#{s}\033[0m"; end
25
+ def azure(s) "\033[1;36m#{s}\033[0m"; end
26
+ def white(s) "\033[1;37m#{s}\033[0m"; end
27
+
28
+ # colors 64k
29
+ def orange(s) "\033[38;5;208m#{s}\033[0m"; end
30
+
31
+ # i dont undertstand why i need self :/
32
+ # SELF version because I'm just stupid or lazy or both.
33
+ # def self.yellow(s) "#{PREPEND_ME}\033[1;33m#{s}\033[0m" ; end
34
+ # def self.green(s) "#{PREPEND_ME}\033[1;32m#{s}\033[0m" ; end
35
+ # def self.gray(s) "#{PREPEND_ME}\033[1;30m#{s}\033[0m" ; end
36
+ # def self.green(s) "#{PREPEND_ME}\033[1;32m#{s}\033[0m" ; end
37
+ # def self.red(s) "#{PREPEND_ME}\033[1;31m#{s}\033[0m" ; end
38
+ # def self.blue(s) "#{PREPEND_ME}\033[1;34m#{s}\033[0m" ; end
39
+ # def self.purple(s) "#{PREPEND_ME}\033[1;35m#{s}\033[0m" ; end
40
+ # def self.azure(s) "#{PREPEND_ME}\033[1;36m#{s}\033[0m" ; end
41
+ # def self.white(s) "#{PREPEND_ME}\033[1;37m#{s}\033[0m" ; end
42
+
43
+ # p<COLOR> Carlessian functions..
44
+ def pwhite(s) puts(white(s)); end
45
+ def pgreen(s) puts(green(s)); end
46
+ def pred(s) puts(red(s)); end
47
+ def pyellow(s) puts(yellow(s)); end
50
48
  end
51
- #end
49
+ # end
@@ -8,7 +8,7 @@
8
8
  =begin
9
9
  Emoji to copy:
10
10
  👍 👎 👌 ✌ 👋 🤝 👏 🤘 🤟 🤙 🤏 🙌 🙏 🖖 🤞 ✋ 🤚 🖐 🖑 🤲 👐 👊 🤛 🤜 🖕
11
- 👈 👉 👆 👇
11
+ 👈 👉 👆 👇
12
12
  ☺ ☻ 😃 😄 😅 😆 😊 😎 😇 😈 😏 🤣 🤩 🤪 🥳 😁 😀 😂 🤠 🤡 🤑 🤓 🤖 kiss
13
13
  😗 😚 😘 😙 flirting
14
14
  😉 🤗 😍 🥰 🤤 😋 😛 😜 😝 neutral
@@ -30,55 +30,61 @@
30
30
  require_relative 'colors'
31
31
  require 'pry'
32
32
 
33
- module Storazzo::Common
33
+ module Storazzo::Common
34
+ include Storazzo::Colors
34
35
 
35
- include Storazzo::Colors
36
+ def deb(s)
37
+ puts "[DEB👀] #{yellow(s)}" if _debug_true # $DEBUG
38
+ end
36
39
 
37
-
38
- def deb(s)
39
- puts "[DEB👀] #{yellow(s)}" if _debug_true # $DEBUG
40
- end
41
- # this has a yield
42
- def if_deb?()
43
- if _debug_true # $DEBUG
44
- deb "== yield START =="
45
- yield
46
- deb "== yield END =="
47
- end
48
- end
49
- def warn(s)
50
- puts "[W⚠️RN] #{azure(s)}"
51
- end
52
- def err(str)
53
- puts "[ERR👎] #{red(s)}" # ⛔
54
- end
55
- def bug(s)
56
- puts "[🐛] #{gray s}"
57
- end
58
- def pverbose(is_verbose, str)
59
- #puts "[V📚RB💀S📚] #{gray str}"
60
- puts "[🦋🐛🐝🐞🐜🕷🕸🦂🦗🦟] #{gray str}" # insects: http://xahlee.info/comp/unicode_insects.html
61
- end
62
- def ppp(complex_object_to_colorize)
63
- # TODO i need to learn to return without printing..
64
- Pry::ColorPrinter.pp(complex_object_to_colorize)
40
+ # this has a yield
41
+ def if_deb?()
42
+ if _debug_true # $DEBUG
43
+ deb "== yield START =="
44
+ yield
45
+ deb "== yield END =="
65
46
  end
47
+ end
66
48
 
67
- def fatal(s)
68
- raise "[F💀TAL] #{red s}"
69
- end
49
+ def warn(s)
50
+ puts "[W⚠️RN] #{azure(s)}"
51
+ end
70
52
 
71
- def mac?
72
- `uname`.chomp == 'Darwin'
73
- end
74
- def linux?
75
- `uname`.chomp == 'Linux'
76
- end
53
+ def err(str)
54
+ puts "[ERR👎] #{red(s)}" # ⛔
55
+ end
77
56
 
78
- private
79
- def _debug_true
80
- $DEBUG or ENV["DEBUG"] == 'true'
81
- end
57
+ def bug(s)
58
+ puts "[🐛] #{gray s}"
59
+ end
60
+
61
+ def pverbose(is_verbose, str)
62
+ # puts "[V📚RB💀S📚] #{gray str}"
63
+ puts "[🦋🐛🐝🐞🐜🕷🕸🦂🦗🦟] #{gray str}" # insects: http://xahlee.info/comp/unicode_insects.html
64
+ end
65
+
66
+ def ppp(complex_object_to_colorize)
67
+ # TODO i need to learn to return without printing..
68
+ Pry::ColorPrinter.pp(complex_object_to_colorize)
69
+ end
70
+
71
+ def fatal(s)
72
+ raise "[F💀TAL] #{red s}"
73
+ end
74
+
75
+ def mac?
76
+ `uname`.chomp == 'Darwin'
77
+ end
78
+
79
+ def linux?
80
+ `uname`.chomp == 'Linux'
81
+ end
82
+
83
+ private
84
+
85
+ def _debug_true
86
+ $DEBUG or ENV["DEBUG"] == 'true'
87
+ end
82
88
 
83
- # puts "[DEBUG ENABLED!]" if _debug_true
84
- end
89
+ # puts "[DEBUG ENABLED!]" if _debug_true
90
+ end
@@ -1,10 +1,7 @@
1
-
2
1
  # idea from https://medium.com/@leo_hetsch/ruby-modules-include-vs-prepend-vs-extend-f09837a5b073
3
2
  module Debug
4
-
5
- def log(message)
6
- # debug output
7
- puts "TODO(ricc): LOG '#{message}' on GCP :)"
8
- end
9
-
10
- end
3
+ def log(message)
4
+ # debug output
5
+ puts "TODO(ricc): LOG '#{message}' on GCP :)"
6
+ end
7
+ end
@@ -1,46 +1,47 @@
1
1
  # copied from https://dev.to/ayushn21/how-to-generate-yaml-from-ruby-objects-without-type-annotations-4fli
2
2
  module Storazzo
3
- module Hashify
4
- # Classes that include this module can exclude certain
5
- # instance variable from its hash representation by overriding
6
- # this method
7
- def ivars_excluded_from_hash
8
- [ 'this_doesnt_exist' ]
9
- end
10
-
11
- def to_hash
12
- hash = {}
13
- excluded_ivars = ivars_excluded_from_hash
14
-
15
- # Iterate over all the instance variables and store their
16
- # names and values in a hash
17
- instance_variables.each do |var|
18
- next if excluded_ivars.include? var.to_s
19
-
20
- value = instance_variable_get(var)
21
- value = value.map(&:to_hash) if value.is_a? Array
22
-
23
- hash[var.to_s.delete("@")] = value
24
- end
25
-
26
- return hash
27
- end
28
-
29
- def obj_to_hash
30
- h = {}
31
- puts self
32
- self.instance_variables.each{|var|
33
- #puts var
34
- h[var.to_s.delete('@')] = self.instance_variable_get(var) # send(var.to_s.delete('@'))
35
- }
36
- h
37
- end
38
-
39
- def to_yaml
40
- to_hash.to_yaml
41
- end
42
- def obj_to_yaml
43
- obj_to_hash.to_yaml
44
- end
3
+ module Hashify
4
+ # Classes that include this module can exclude certain
5
+ # instance variable from its hash representation by overriding
6
+ # this method
7
+ def ivars_excluded_from_hash
8
+ ['this_doesnt_exist']
45
9
  end
46
- end
10
+
11
+ def to_hash
12
+ hash = {}
13
+ excluded_ivars = ivars_excluded_from_hash
14
+
15
+ # Iterate over all the instance variables and store their
16
+ # names and values in a hash
17
+ instance_variables.each do |var|
18
+ next if excluded_ivars.include? var.to_s
19
+
20
+ value = instance_variable_get(var)
21
+ value = value.map(&:to_hash) if value.is_a? Array
22
+
23
+ hash[var.to_s.delete("@")] = value
24
+ end
25
+
26
+ return hash
27
+ end
28
+
29
+ def obj_to_hash
30
+ h = {}
31
+ puts self
32
+ self.instance_variables.each { |var|
33
+ # puts var
34
+ h[var.to_s.delete('@')] = self.instance_variable_get(var) # send(var.to_s.delete('@'))
35
+ }
36
+ h
37
+ end
38
+
39
+ def to_yaml
40
+ to_hash.to_yaml
41
+ end
42
+
43
+ def obj_to_yaml
44
+ obj_to_hash.to_yaml
45
+ end
46
+ end
47
+ end
data/lib/storazzo/main.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  # eg from RicDisk.
4
4
 
5
5
  module Storazzo
6
-
7
6
  # This is the Main Class - an entrypoint to call the meravilles hidden therein.
8
7
  #
9
8
  # Example:
@@ -13,62 +12,62 @@ module Storazzo
13
12
  # Arguments:
14
13
  # message: (String) - optional
15
14
 
16
-
17
15
  class Storazzo::Main # Can be same name as Module: https://stackoverflow.com/questions/13261474/ruby-modules-and-classes-same-name-in-structure
18
16
  require 'storazzo/colors'
19
17
  extend Storazzo::Colors
20
18
 
21
19
  # version 1.2
22
- def self.say_hi(message=nil)
20
+ def self.say_hi(message = nil)
23
21
  str = get_hi(message)
24
- puts str
25
- str
22
+ puts str
23
+ str
26
24
  end
25
+
27
26
  # salutation
28
- def self.get_hi(message=nil)
27
+ def self.get_hi(message = nil)
29
28
  str = "Hello from Storazzo v#{white Storazzo::version rescue "Error: #{$!}"}!"
30
29
  str += " Message: '#{yellow message.to_s}'" if message
31
30
  str
32
31
  end
33
32
 
34
- def self.all_mounts(opts={})
35
- opts_verbose = opts.fetch :verbose, true
33
+ def self.all_mounts(opts = {})
34
+ opts_verbose = opts.fetch :verbose, true
35
+
36
+ self.say_hi "Storazzo::Main.all_mounts(): BEGIN - RicDiskVersion is: #{Storazzo::RicDiskUgly::RICDISK_VERSION}"
36
37
 
37
- self.say_hi "Storazzo::Main.all_mounts(): BEGIN - RicDiskVersion is: #{Storazzo::RicDiskUgly::RICDISK_VERSION}"
38
-
39
- pwhite("1. First I load the config in verbose mode..")
40
- config = Storazzo::RicDiskConfig.instance
41
- config.load
42
- # puts config.object_id
43
- # puts Storazzo::RicDiskConfig.instance.object_id
44
- pwhite "TODO(ricc): show a list of all RicDisk relevant mounts" if opts_verbose
45
- #d = Storazzo::RicDisk.new
46
- config.iterate_through_file_list_for_disks() # analyze_local_system
47
- #sbrodola_ricdisk("/Volumes/")
48
- Storazzo::RicDisk.test
49
- Storazzo::RicDisk.find_active_dirs
50
- #Storazzo::RicDisk.sbrodola_ricdisk StorazzoMod::root + "./var/disks/"
51
- #sbrodola_ricdisk(StorazzoMod::root + "./var/disks/") rescue "[Storazzo::AllMount] SomeError: #{$!}"
52
- self.hi 'Storazzo::Main.all_mounts(): END'
38
+ pwhite("1. First I load the config in verbose mode..")
39
+ config = Storazzo::RicDiskConfig.instance
40
+ config.load
41
+ # puts config.object_id
42
+ # puts Storazzo::RicDiskConfig.instance.object_id
43
+ pwhite "TODO(ricc): show a list of all RicDisk relevant mounts" if opts_verbose
44
+ # d = Storazzo::RicDisk.new
45
+ config.iterate_through_file_list_for_disks() # analyze_local_system
46
+ # sbrodola_ricdisk("/Volumes/")
47
+ Storazzo::RicDisk.test
48
+ Storazzo::RicDisk.find_active_dirs
49
+ # Storazzo::RicDisk.sbrodola_ricdisk StorazzoMod::root + "./var/disks/"
50
+ # sbrodola_ricdisk(StorazzoMod::root + "./var/disks/") rescue "[Storazzo::AllMount] SomeError: #{$!}"
51
+ self.hi 'Storazzo::Main.all_mounts(): END'
53
52
  end
54
53
 
55
- def self.all_tests
56
- # include vs extend: https://stackoverflow.com/questions/15097929/ruby-module-require-and-include
57
- # => http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/
58
- #include Storazzo::Colors
59
- extend Storazzo::Colors
54
+ def self.all_tests
55
+ # include vs extend: https://stackoverflow.com/questions/15097929/ruby-module-require-and-include
56
+ # => http://www.railstips.org/blog/archives/2009/05/15/include-vs-extend-in-ruby/
57
+ # include Storazzo::Colors
58
+ extend Storazzo::Colors
60
59
 
61
- pwhite "All tests BEGIN - todo obsolete this now that I have proper Rake testing suite..."
62
- deb "Maybe debug is enabled?"
63
- say_hi
64
- # This works with EXTEND..
65
- puts(yellow "Just YELLOW 0")
66
- # This reqwuires a INCLUDE.
67
- #puts(Storazzo::Colors.yellow "Test YELLOW 1 self")
68
- #puts(Colors.yellow "Test YELLOW 1 self")
69
- #puts(Colors.green "Test YELLOW 2 ohne self")
70
- pwhite "All tests END"
71
- #puts "All tests END"
60
+ pwhite "All tests BEGIN - todo obsolete this now that I have proper Rake testing suite..."
61
+ deb "Maybe debug is enabled?"
62
+ say_hi
63
+ # This works with EXTEND..
64
+ puts(yellow "Just YELLOW 0")
65
+ # This reqwuires a INCLUDE.
66
+ # puts(Storazzo::Colors.yellow "Test YELLOW 1 self")
67
+ # puts(Colors.yellow "Test YELLOW 1 self")
68
+ # puts(Colors.green "Test YELLOW 2 ohne self")
69
+ pwhite "All tests END"
70
+ # puts "All tests END"
72
71
  end
73
72
  end
74
- end
73
+ end