Class: Storazzo::Media::Storazzo::Media::AbstractRicDisk
- Inherits:
-
Object
- Object
- Storazzo::Media::Storazzo::Media::AbstractRicDisk
- Extended by:
- Common
- Defined in:
- lib/storazzo/media/abstract_ric_disk.rb
Direct Known Subclasses
Constant Summary
Constants included from Colors
Instance Attribute Summary collapse
-
#description ⇒ Object
attr_accessor :name, :description, :ricdisk_file, :local_mountpoint, :wr, :path, :ricdisk_file_empty, :size, :active_dirs.
Class Method Summary collapse
-
.abstract_class_mandatory_methods ⇒ Object
# Todo check on instances these 3 methods exist.
- .default_stats_filename ⇒ Object
-
.DirFactory(path) ⇒ Object
TODO: use a proper Factory pattern.
- .list_all ⇒ Object
- .list_all_with_type ⇒ Object
- .super_duper_list_all_with_type ⇒ Object
Instance Method Summary collapse
- #check_implemented_correctly ⇒ Object
- #get_local_mountpoint ⇒ Object
-
#initialize(_local_mount) ⇒ AbstractRicDisk
constructor
Abstract methods START.
- #parse(_opts = {}) ⇒ Object
-
#parse_block_storage_folder(opts = {}) ⇒ Object
Putting here since its same code for MountPoint or generic folder.
-
#stats_file_smart_fullpath ⇒ Object
Automated methods now…
-
#stats_filename_default_fullpath ⇒ Object
if not writeable we need to pick another from stats_file_smart_fullpath().
- #to_s(verbose = false) ⇒ Object
- #to_verbose_s ⇒ Object
-
#unique_id ⇒ Object
Needs to be some unique id based on its thingy, but might change in the future: Solutions: PHILOSOPHY::ID.
- #validate(opts = {}) ⇒ Object
- #writeable? ⇒ Boolean
Methods included from Common
bug, deb, err, fatal, if_deb?, linux?, mac?, ppp, pverbose, warn
Methods included from Colors
#azure, #blue, #deb2, #gray, #green, #orange, #pgreen, #pred, #purple, #pwhite, #pyellow, #red, #white, #yellow
Constructor Details
#initialize(_local_mount) ⇒ AbstractRicDisk
Abstract methods START
40 41 42 43 44 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 40 def initialize(_local_mount) deb "[AbstractRicDisk.init()] Some child of AbstractRicDisk (#{self}) called me! Yummie." # disable when you dont need me anymore.. @description ||= 'Not provided' # validate end |
Instance Attribute Details
#description ⇒ Object
attr_accessor :name, :description, :ricdisk_file, :local_mountpoint, :wr, :path, :ricdisk_file_empty, :size, :active_dirs
35 36 37 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 35 def description @description end |
Class Method Details
.abstract_class_mandatory_methods ⇒ Object
# Todo check on instances these 3 methods exist
131 132 133 134 135 136 137 138 139 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 131 def self.abstract_class_mandatory_methods %w[ self.list_all self.list_all_with_type local_mountpoint parse writeable? ] end |
.default_stats_filename ⇒ Object
150 151 152 153 154 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 150 def self.default_stats_filename raise 'Unknown Storazzo::RicDiskStatsFile.default_name 1!!' if Storazzo::RicDiskStatsFile.default_name.nil? Storazzo::RicDiskStatsFile.default_name end |
.DirFactory(path) ⇒ Object
TODO: use a proper Factory pattern.
177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 177 def self.DirFactory(path) raise "I need a path/directory string: #{path}" unless path.is_a?(String) deb 'TODO: if coincides with MountPoint, instance THAT' # if path in Storazzo::Media::MountPoint.list_all_mount_points # then return ... if path =~ %r{^gs://} deb 'Smells like GCS' return GcsBucket.new(path) end deb 'Smells like LocalFolder :)' LocalFolder.new(path) end |
.list_all ⇒ Object
46 47 48 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 46 def self.list_all raise "[AbstractRicDiskc::self.list_all] You should override this, says StackOverflow and Riccardo. Class=#{self.class}. Self=#{self}" end |
.list_all_with_type ⇒ Object
50 51 52 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 50 def self.list_all_with_type raise "[AbstractRicDisk::self.list_all_with_type] You should override this, says StackOverflow and Riccardo. Class=#{self.class}. Self=#{self}" end |
.super_duper_list_all_with_type ⇒ Object
54 55 56 57 58 59 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 54 def self.super_duper_list_all_with_type deb 'Would be cool to be able to enumerate them all..' GcsBucket.list_all_with_type + MountPoint.list_all_with_type + LocalFolder.list_all_with_type end |
Instance Method Details
#check_implemented_correctly ⇒ Object
76 77 78 79 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 76 def check_implemented_correctly # raise "[AbstractRicDiskc] You should override this, says StackOverflow and Riccardo" raise 'no @local_mountpoint' unless exists?(@local_mountpoint) end |
#get_local_mountpoint ⇒ Object
69 70 71 72 73 74 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 69 def get_local_mountpoint # raise "[AbstractRicDiskc::get_local_mountpoint] You should override this, says StackOverflow and Riccardo" raise 'You forgot to set local_mountpoint in the constructor for your class, you cheeky little one!' if local_mountpoint.nil? local_mountpoint end |
#parse(_opts = {}) ⇒ Object
61 62 63 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 61 def parse(_opts = {}) raise "[AbstractRicDiskc::parse] You should override this, says StackOverflow and Riccardo. Class=#{self.class}." end |
#parse_block_storage_folder(opts = {}) ⇒ Object
Putting here since its same code for MountPoint or generic folder.
142 143 144 145 146 147 148 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 142 def parse_block_storage_folder(opts = {}) # Storazzo::RicDiskUgly.calculate_stats_files(get_local_mountpoint) rd = Storazzo::RicDisk.new(self) # Storazzo::RicDisk rd.compute_stats_files(opts) # return "42" end |
#stats_file_smart_fullpath ⇒ Object
Automated methods now…
stats_file_default_location()
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 88 def stats_file_smart_fullpath # if its writeable... if not we'll think about it later. if writeable? "#{get_local_mountpoint}/#{default_stats_filename}" else # if not writeable, I will: # 1. create a dir based on its unique format. # 2. create a file of same look and feel (alternative - used a DASH) "TODO FIXME {get_local_folder}/#{unique_id}::#{default_stats_filename}" # "{get_local_folder}"/#{unique_id}/#{Storazzo::RicDiskStatsFile.default_name}" end end |
#stats_filename_default_fullpath ⇒ Object
if not writeable we need to pick another from stats_file_smart_fullpath()
157 158 159 160 161 162 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 157 def stats_filename_default_fullpath # REDUNDANT, should use stats_file_smart_fullpath instead except on the writeable? part since it would go recursive otherwise. my_stats_filename = default_stats_filename # raise "Unknown Storazzo::RicDiskStatsFile.default_name 2 !!" if Storazzo::RicDiskStatsFile.default_name.nil? "#{local_mountpoint}/#{my_stats_filename}" end |
#to_s(verbose = false) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 110 def to_s(verbose = false) return to_verbose_s if verbose readable_class = self.class.to_s.split('::').last # Storazzo::Media::LocalFolder => LocalFolder my_keys = instance_variables # wow! "S:M:#{readable_class}(path=#{path}, r/w=#{wr}, keys=#{my_keys})" end |
#to_verbose_s ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 118 def to_verbose_s h = {} h[:class] = self.class h[:unique_id] = unique_id h[:inspect] = inspect h[:to_s] = to_s h[:local_mountpoint] = local_mountpoint h[:writeable] = writeable? h[:stats_file_smart_fullpath] = stats_file_smart_fullpath h end |
#unique_id ⇒ Object
Needs to be some unique id based on its thingy, but might change in the future: Solutions: PHILOSOPHY::ID
104 105 106 107 108 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 104 def unique_id # Expand path to make it as unique as possible... hash = Digest::MD5.hexdigest(File.(get_local_mountpoint)) "MD5::v1::#{hash}" end |
#validate(opts = {}) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 164 def validate(opts = {}) opt_verbose = opts.fetch :verbose, false pverbose opt_verbose, "validate(): [BROKEN] We're trying to see if your object is valid, across 3 possible sub-classes." # 1. check for raise 'Unknown local mount ' unless local_mount.is_a?(String) # 2. check thaty writeable? is true or false my_writeable = wr raise 'Writeable is not boolean' unless my_writeable.is_a?(TrueClass) || my_writeable.is_a?(FalseClass) end |
#writeable? ⇒ Boolean
65 66 67 |
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 65 def writeable? raise "[AbstractRicDiskc::writeable] You should override this in class=#{self.class}, says StackOverflow and Riccardo" end |