Class: Storazzo::Media::AbstractRicDisk

Inherits:
Object
  • Object
show all
Extended by:
Common
Defined in:
lib/storazzo/media/abstract_ric_disk.rb

Direct Known Subclasses

GcsBucket, LocalFolder, MountPoint

Constant Summary

Constants included from Colors

Colors::PREPEND_ME

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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



37
38
39
40
41
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 37

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

#descriptionObject

attr_accessor :name, :description, :ricdisk_file, :local_mountpoint, :wr, :path, :ricdisk_file_empty, :size, :active_dirs



32
33
34
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 32

def description
  @description
end

Class Method Details

.abstract_class_mandatory_methodsObject

# Todo check on instances these 3 methods exist



128
129
130
131
132
133
134
135
136
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 128

def self.abstract_class_mandatory_methods
  %w[
    self.list_all
    self.list_all_with_type
    local_mountpoint
    parse
    writeable?
  ]
end

.default_stats_filenameObject



147
148
149
150
151
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 147

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.



174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 174

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_allObject



43
44
45
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 43

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_typeObject



47
48
49
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 47

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_typeObject



51
52
53
54
55
56
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 51

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_correctlyObject



73
74
75
76
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 73

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_mountpointObject



66
67
68
69
70
71
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 66

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



58
59
60
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 58

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.



139
140
141
142
143
144
145
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 139

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_fullpathObject

Automated methods now…

stats_file_default_location()



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 85

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_fullpathObject

if not writeable we need to pick another from stats_file_smart_fullpath()



154
155
156
157
158
159
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 154

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



107
108
109
110
111
112
113
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 107

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_sObject



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 115

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_idObject

Needs to be some unique id based on its thingy, but might change in the future: Solutions: PHILOSOPHY::ID



101
102
103
104
105
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 101

def unique_id
  # Expand path to make it as unique as possible...
  hash = Digest::MD5.hexdigest(File.expand_path(get_local_mountpoint))
  "MD5::v1::#{hash}"
end

#validate(opts = {}) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 161

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

Returns:

  • (Boolean)


62
63
64
# File 'lib/storazzo/media/abstract_ric_disk.rb', line 62

def writeable?
  raise "[AbstractRicDiskc::writeable] You should override this in class=#{self.class}, says StackOverflow and Riccardo"
end