storazzo 0.5.1 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +7 -5
- data/LICENSE +20 -1
- data/Makefile +9 -5
- data/Rakefile +22 -9
- data/VERSION +1 -1
- data/bin/hello-storazzo +1 -0
- data/bin/ricdisk-magic +33 -30
- data/bin/stats-with-md5 +146 -176
- data/bin/storazzo +158 -0
- data/bin/storazzo-symlink.rb +1 -0
- data/bin/storazzo-util +1 -0
- data/lib/storazzo/colors.rb +77 -36
- data/lib/storazzo/common.rb +72 -65
- 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 +190 -161
- data/lib/storazzo/media/gcs_bucket.rb +78 -47
- data/lib/storazzo/media/local_folder.rb +56 -42
- data/lib/storazzo/media/mount_point.rb +22 -6
- data/lib/storazzo/ric_disk.rb +386 -383
- data/lib/storazzo/ric_disk_config.rb +229 -197
- 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 +31 -19
- data/test/benchmark/for_future_use.rb +15 -0
- data/test/benchmark/test_hashing_functions-speed.rb +17 -0
- data/test/bin/new-idea.rb +17 -0
- data/test/bin/storazzo.rb +25 -0
- data/test/media/test_abstract_ric_disk.rb +6 -4
- data/test/media/test_gcs_bucket.rb +55 -21
- data/test/media/test_local_folder.rb +28 -29
- data/test/media/test_mount_point.rb +7 -5
- data/test/test_ric_disk.rb +8 -6
- data/test/test_ric_disk_config.rb +13 -12
- 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 -22
- metadata +22 -22
@@ -1,247 +1,279 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'English'
|
4
|
+
|
1
5
|
require 'singleton'
|
2
6
|
require 'yaml'
|
3
7
|
|
4
|
-
#
|
5
|
-
Dir[File.dirname(__FILE__) + '/../lib/*.rb'].each do |file|
|
8
|
+
Dir["#{File.dirname(__FILE__)}/../lib/*.rb"].each do |file|
|
6
9
|
require File.basename(file, File.extname(file))
|
7
10
|
end
|
8
|
-
# require_all 'media/directory'
|
9
|
-
|
10
|
-
=begin
|
11
|
-
This is a singleton class. You call me this way..
|
12
|
-
You call me with:
|
13
|
-
|
14
|
-
Storazzo::RicDiskConfig.instance()
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
12
|
+
# This is a singleton class. You call me this way..
|
13
|
+
# You call me with:
|
14
|
+
#
|
15
|
+
# Storazzo::RicDiskConfig.instance()
|
16
|
+
#
|
17
|
+
# or better
|
18
|
+
#
|
19
|
+
# Storazzo::RicDiskConfig.safe_instance()
|
20
|
+
#
|
21
|
+
# Note that being a Singleton, in Unit Tests it's hard to use the /etc/storazzo_config.sample.yaml instead
|
22
|
+
# of the real one - yiikes. How do I fix it? Do I unsingleton it? :) Or do I create TWO singletons? :)
|
23
23
|
|
24
24
|
module Storazzo
|
25
25
|
# class Storazzo::Blah
|
26
26
|
# end
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
DefaultConfigLocation = File.expand_path "~/.storazzo.yaml"
|
28
|
+
module Storazzo
|
29
|
+
class RicDiskConfig
|
30
|
+
include Singleton
|
31
|
+
include Storazzo::Common
|
32
|
+
include Storazzo::Colors
|
34
33
|
|
35
|
-
|
36
|
-
File.expand_path("~/.storazzo.yaml"), # HOME
|
37
|
-
File.expand_path("./.storazzo.yaml"), # LOCAL DIR
|
38
|
-
]
|
34
|
+
DefaultConfigLocation = File.expand_path '~/.storazzo.yaml'
|
39
35
|
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
DEFAULT_CONFIG_LOCATIONS = [
|
37
|
+
File.expand_path('~/.storazzo.yaml'), # HOME
|
38
|
+
File.expand_path('./.storazzo.yaml') # LOCAL DIR
|
39
|
+
].freeze
|
43
40
|
|
44
|
-
|
41
|
+
DefaultGemLocationForTests =
|
42
|
+
"#{File.expand_path('../..', __dir__)}/etc/storazzo_config.sample.yaml"
|
45
43
|
|
46
|
-
|
44
|
+
attr_accessor :config, :config_file, :load_called, :project_id
|
47
45
|
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
# Load from the first valid config.
|
47
|
+
def load(config_path = nil, opts = {})
|
48
|
+
verbose = opts.fetch :verbose, false
|
51
49
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
50
|
+
if already_loaded? # and not self.config.nil?
|
51
|
+
pverbose verbose, "[#{self.class}] Config.Load: already loaded"
|
52
|
+
return config
|
53
|
+
end
|
54
|
+
pverbose verbose, 'Storazzo::RicDiskConfig.load(): BEGIN'
|
55
|
+
# trying default location
|
56
|
+
raise 'DefaultConfigLocation is not a string' unless DefaultConfigLocation.is_a?(String)
|
57
|
+
|
58
|
+
possible_locations = DEFAULT_CONFIG_LOCATIONS # [ default_config_locations .. , "./.storazzo.yaml"]
|
59
|
+
deb "[Config.load] Possible Locations: #{possible_locations}"
|
60
|
+
if config_path.is_a?(String)
|
61
|
+
# possible_locations = [config_path] + possible_locations # .append()
|
62
|
+
possible_locations.unshift(config_path) # append to front
|
63
|
+
# OR: possible_locations.instert(0, config_path)
|
64
|
+
pverbose verbose, "[LOAD] possible_locations: #{possible_locations}"
|
65
|
+
end
|
66
|
+
pverbose verbose, "Searching these paths in order: #{possible_locations}"
|
67
|
+
# bug "This is not always an array of sTRINGS."
|
68
|
+
raise 'possible_locations is not an array' unless possible_locations.is_a?(Array)
|
69
|
+
|
70
|
+
possible_locations.each do |possible_path|
|
71
|
+
# ASSERT is a string
|
72
|
+
raise 'possible_path is not a string' unless possible_path.is_a?(String)
|
73
|
+
|
74
|
+
deb "before buggy expand_path paz: '#{possible_path}''"
|
75
|
+
paz = begin
|
76
|
+
File.expand_path(possible_path)
|
77
|
+
rescue StandardError
|
78
|
+
possible_path
|
79
|
+
end
|
80
|
+
raise "Not a string: #{paz}" unless paz.is_a?(String)
|
75
81
|
|
76
|
-
|
77
|
-
paz = File.expand_path(possible_path) rescue possible_path
|
78
|
-
raise "Not a string: #{paz}" unless paz.is_a?(String)
|
82
|
+
next unless File.exist?(paz)
|
79
83
|
|
80
|
-
if File.exists?(paz)
|
81
84
|
@config_file = paz
|
82
|
-
@config = YAML.
|
85
|
+
@config = YAML.safe_load(File.read(paz)) # YAML.load(File.read("file_path"))
|
83
86
|
|
84
|
-
unless
|
85
|
-
|
87
|
+
unless begin
|
88
|
+
@config['kind'] == 'StorazzoConfig'
|
89
|
+
rescue StandardError
|
90
|
+
false
|
91
|
+
end
|
92
|
+
puts white "RicDiskConfig.load(): Sorry this is wrong Config File. Kind=#{begin
|
93
|
+
@config['kind']
|
94
|
+
rescue StandardError
|
95
|
+
$ERROR_INFO
|
96
|
+
end}"
|
86
97
|
next
|
87
98
|
end
|
88
99
|
#
|
89
100
|
# pp @config if verbose
|
90
|
-
config_ver = @config[
|
101
|
+
config_ver = @config['apiVersion']
|
91
102
|
# puts @config[:ConfigVersion]
|
92
103
|
deb("OK. Storazzo::RicDiskConfig v'#{config_ver}' parsed correctly")
|
93
|
-
# puts "[VERBOSE] RicDiskConfig.to_s: #{self}" if verbose
|
94
104
|
@load_called = true
|
95
|
-
return
|
105
|
+
return config
|
96
106
|
end
|
107
|
+
@load_called = true
|
108
|
+
# only get here if nothing is found
|
109
|
+
raise "No config found across these locations: #{possible_locations}. Consider copying and editing: #{RicDiskConfig.gem_default_config_path}"
|
97
110
|
end
|
98
|
-
@load_called = true
|
99
|
-
# only get here if nothing is found
|
100
|
-
raise "No config found across these locations: #{possible_locations}. Consider copying and editing: #{RicDiskConfig.gem_default_config_path}"
|
101
|
-
end
|
102
111
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
112
|
+
# Obsolete, call another class instead.
|
113
|
+
def load_sample_version
|
114
|
+
raise 'DEPRECATED! USE SampleRicDiskConfig.load() instead!'
|
115
|
+
end
|
107
116
|
|
108
|
-
|
109
|
-
|
117
|
+
def config_ver
|
118
|
+
raise 'I cant compute Version since I cant compute @config. Are you sure you didnt instance this Singleton without calling load?' if @config.nil?
|
110
119
|
|
111
|
-
|
112
|
-
|
113
|
-
|
120
|
+
@config['apiVersion'] # rescue :StillUnknown
|
121
|
+
# config['ConfigVersion']
|
122
|
+
end
|
114
123
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
124
|
+
def config_default_folder
|
125
|
+
# self.
|
126
|
+
@config['Config']['DefaultFolder'] # rescue "Unknown config_default_folder: #{$!}"
|
127
|
+
end
|
119
128
|
|
120
|
-
|
121
|
-
|
122
|
-
|
129
|
+
def config_project_id
|
130
|
+
@config['Config']['Backends']['GoogleCloudStorage']['ProjectId']
|
131
|
+
end
|
123
132
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
133
|
+
# doesnt work :/ alias :project_id, :config_project_id
|
134
|
+
def project_id
|
135
|
+
config_project_id
|
136
|
+
end
|
128
137
|
|
129
|
-
|
130
|
-
|
131
|
-
#
|
132
|
-
|
133
|
-
|
134
|
-
|
138
|
+
# This should return true if and only if the user has configured the YAML
|
139
|
+
# to use GCS. For now we can just say TRUE since gsutil ls returns without project_id.
|
140
|
+
# However, we might have a flag enabled in storazzo config in next versions.
|
141
|
+
def gcs_enabled?
|
142
|
+
# true
|
143
|
+
defined?(get_config['Config']['Backends']['GoogleCloudStorage'])
|
144
|
+
# get_config['Config']['Backends']['GoogleCloudStorage DOESNT EXIST']
|
145
|
+
# defined? Backends: GoogleCloudStorage
|
146
|
+
end
|
135
147
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
h[:to_s] = self.to_s
|
141
|
-
h[:class] = self.class
|
142
|
-
h[:file] = __FILE__
|
143
|
-
h[:id] = self.object_id
|
144
|
-
h[:get_bucket_paths] = self.get_bucket_paths()
|
145
|
-
h[:get_local_folders] = self.get_local_folders()
|
146
|
-
h[:config_project_id] = self.config_project_id()
|
147
|
-
return h
|
148
|
-
end
|
148
|
+
def already_loaded?
|
149
|
+
# return
|
150
|
+
load_called == true
|
151
|
+
end
|
149
152
|
|
150
|
-
|
151
|
-
|
153
|
+
def to_s
|
154
|
+
size = begin
|
155
|
+
File.size(@config_file)
|
156
|
+
rescue StandardError
|
157
|
+
-1
|
158
|
+
end
|
159
|
+
# puts yellow "DEB: #{@config["apiVersion"]}"
|
160
|
+
# "RicDiskConfig(ver=#{config_ver}, file=#{config_file}), #{white(size)} bytes" # - config_default_folder=#{self.config_default_folder}"
|
161
|
+
"POLY_#{self.class}_(ver=#{config_ver}, file=#{config_file}), #{white(size)} bytes" # - config_default_folder=#{self.config_default_folder}"
|
162
|
+
end
|
152
163
|
|
153
|
-
|
154
|
-
|
164
|
+
def to_verbose_s
|
165
|
+
h = {}
|
166
|
+
h[:description] =
|
167
|
+
'This is a Verbose Hash describing a RicDiskConfig or its child RicDiskSampleConfig to understand why it keeps failing..'
|
168
|
+
h[:to_s] = to_s
|
169
|
+
h[:class] = self.class
|
170
|
+
h[:file] = __FILE__
|
171
|
+
h[:id] = object_id
|
172
|
+
h[:get_bucket_paths] = get_bucket_paths
|
173
|
+
h[:get_local_folders] = get_local_folders
|
174
|
+
h[:config_project_id] = config_project_id
|
175
|
+
h
|
176
|
+
end
|
155
177
|
|
156
|
-
|
157
|
-
|
158
|
-
end
|
178
|
+
def get_config(opts = {})
|
179
|
+
return load(opts) if @config.nil?
|
159
180
|
|
160
|
-
|
161
|
-
|
162
|
-
# returns all folders from file which are Directories
|
163
|
-
# This method is FLAKY! Sometimes gives error.
|
164
|
-
# LocalFolderTest#test_show_all_shouldnt_fail_and_should_return_a_non_empty_array:
|
165
|
-
# TypeError: no implicit conversion of Hash into String
|
166
|
-
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:38:in `expand_path'
|
167
|
-
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:38:in `block in load'
|
168
|
-
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:37:in `each'
|
169
|
-
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:37:in `load'
|
170
|
-
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:83:in `get_config'
|
171
|
-
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:95:in `get_local_folders'
|
172
|
-
def get_local_folders
|
173
|
-
config = get_config
|
174
|
-
# puts config['Config']['AdditionalMountDirs']
|
175
|
-
config['Config']['AdditionalMountDirs'].map { |folder|
|
176
|
-
File.expand_path(folder) rescue folder # TypeError: no implicit conversion of Hash into String
|
177
|
-
}.filter { |f| File.directory?(f) }
|
178
|
-
end
|
181
|
+
@config
|
182
|
+
end
|
179
183
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
}
|
184
|
-
end
|
184
|
+
def self.gem_default_config_path
|
185
|
+
"#{Storazzo.root}/etc/storazzo_config.sample.yaml"
|
186
|
+
end
|
185
187
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
#
|
192
|
-
#
|
193
|
-
#
|
194
|
-
#
|
195
|
-
#
|
196
|
-
#
|
197
|
-
#
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
rd.write_config_yaml_to_disk(dir)
|
212
|
-
# RicDisk.write_config_yaml_to_disk(dir)
|
213
|
-
# RicDisk.calculate_stats_files (CLASS) => will become OBJECT compute_stats_files
|
214
|
-
rd.compute_stats_files() # dir is inutile # TODO
|
215
|
-
else
|
216
|
-
raise("Doesnt seem a dir to me, quitting: #{dir}")
|
188
|
+
# Storazzo::RicDiskConfig
|
189
|
+
|
190
|
+
# returns all folders from file which are Directories
|
191
|
+
# This method is FLAKY! Sometimes gives error.
|
192
|
+
# LocalFolderTest#test_show_all_shouldnt_fail_and_should_return_a_non_empty_array:
|
193
|
+
# TypeError: no implicit conversion of Hash into String
|
194
|
+
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:38:in `expand_path'
|
195
|
+
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:38:in `block in load'
|
196
|
+
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:37:in `each'
|
197
|
+
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:37:in `load'
|
198
|
+
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:83:in `get_config'
|
199
|
+
# /Users/ricc/git/storazzo/lib/storazzo/ric_disk_config.rb:95:in `get_local_folders'
|
200
|
+
def get_local_folders
|
201
|
+
config = get_config
|
202
|
+
# puts config['Config']['AdditionalMountDirs']
|
203
|
+
config['Config']['AdditionalMountDirs'].map do |folder|
|
204
|
+
File.expand_path(folder)
|
205
|
+
rescue StandardError
|
206
|
+
folder
|
207
|
+
end.filter { |f| File.directory?(f) }
|
208
|
+
end
|
209
|
+
|
210
|
+
def get_bucket_paths
|
211
|
+
get_config['Config']['Backends']['GoogleCloudStorage']['BucketPaths'].map do |complex_gcs_struct|
|
212
|
+
complex_gcs_struct['path']
|
217
213
|
end
|
218
214
|
end
|
219
|
-
# end
|
220
|
-
end # /iterate_through_file_list_for_disks
|
221
215
|
|
222
|
-
|
223
|
-
|
224
|
-
|
216
|
+
# UGLY CODE, copipasted from binary for ARGV, ex autosbrodola
|
217
|
+
def iterate_through_file_list_for_disks(files_list = [], opts = {})
|
218
|
+
verbose = opts.fetch :verbose, false
|
219
|
+
raise "[iterate_through_file_list_for_disks] Wrong input, I need an array here: #{files_list} " unless files_list.is_a?(Array)
|
220
|
+
|
221
|
+
# I decided i wont accept an emopty list, this is not how you use the gem, you lazy XXX!
|
222
|
+
# if files_list == [] # or files_list.nil? # empty -> ALL
|
223
|
+
# deb "iterate_through_file_list_for_disks(): no args provided"
|
224
|
+
# dirs = RicDisk.find_active_dirs()
|
225
|
+
# puts "DEB find_active_dirs: #{green dirs}"
|
226
|
+
# dirs.each {|dir|
|
227
|
+
# RicDisk.write_config_yaml_to_disk(dir)
|
228
|
+
# RicDisk.calculate_stats_files(dir) # dir is inutile
|
229
|
+
# } # TODO refactor in option sbrodola_afterwards=true. :)
|
230
|
+
# else
|
231
|
+
pverbose verbose,
|
232
|
+
'iterate_through_file_list_for_disks(): I consider files_list as a list of directories to parse :)'
|
233
|
+
|
234
|
+
# dirs = RicDisk.find_active_dirs()
|
235
|
+
files_list.each do |dir|
|
236
|
+
dir = File.expand_path(dir)
|
237
|
+
if File.directory?(dir)
|
238
|
+
# if dirs.include?(dir)
|
239
|
+
pverbose verbose, "iterate_through_file_list_for_disks() Legit dir: #{green dir}"
|
240
|
+
rd = RicDisk.new(Storazzo::Media::AbstractRicDisk.DirFactory(dir))
|
241
|
+
pverbose verbose, "RicDisk from Factory (woohoo): #{rd}"
|
242
|
+
rd.write_config_yaml_to_disk(dir)
|
243
|
+
# RicDisk.write_config_yaml_to_disk(dir)
|
244
|
+
# RicDisk.calculate_stats_files (CLASS) => will become OBJECT compute_stats_files
|
245
|
+
rd.compute_stats_files # dir is inutile # TODO
|
246
|
+
else
|
247
|
+
raise("Doesnt seem a dir to me, quitting: #{dir}")
|
248
|
+
end
|
249
|
+
end
|
250
|
+
# end
|
251
|
+
end
|
225
252
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
my_config.load
|
230
|
-
my_config
|
231
|
-
end
|
253
|
+
def config_hash
|
254
|
+
config['Config']
|
255
|
+
end
|
232
256
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
257
|
+
def self.safe_instance
|
258
|
+
puts 'This is a safe instance :)'
|
259
|
+
my_config = instance
|
260
|
+
my_config.load
|
261
|
+
my_config
|
262
|
+
end
|
263
|
+
|
264
|
+
def self.get_config
|
265
|
+
instance.load unless instance.load_called
|
266
|
+
instance.get_config
|
267
|
+
end
|
237
268
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
end
|
269
|
+
# # gem 'after_do'
|
270
|
+
# require 'after_do'
|
271
|
+
# Storazzo::RicDiskConfig.extend AfterDo
|
272
|
+
# Storazzo::RicDiskConfig.after :instance do # |activity| #:pause, :finish, :resurrect, :do_today, :do_another_day
|
273
|
+
# puts yellow("after INSTANCE() has been called I call LOAD!!!")
|
274
|
+
# self.load
|
275
|
+
# #persistor.save activity
|
276
|
+
# end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
@@ -1,31 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'singleton'
|
2
4
|
require 'yaml'
|
3
5
|
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
|
7
|
-
=begin
|
8
|
-
This is a singleton class. You call me this way..
|
9
|
-
You call me with:
|
10
|
-
|
11
|
-
Storazzo::RicDiskSampleConfig.instance()
|
12
|
-
|
13
|
-
=end
|
6
|
+
require_relative './common'
|
7
|
+
require_relative './ric_disk_config'
|
14
8
|
|
15
9
|
module Storazzo
|
16
|
-
|
17
|
-
#
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
10
|
+
module Storazzo
|
11
|
+
# This is a singleton class. You call me this way..
|
12
|
+
# You call me with:
|
13
|
+
#
|
14
|
+
# Storazzo::RicDiskSampleConfig.instance()
|
15
|
+
#
|
16
|
+
# It loads a sample config in local gem etc/. Usuful for testing or if no other config is found..
|
17
|
+
|
18
|
+
class RicDiskSampleConfig < Storazzo::RicDiskConfig
|
19
|
+
# include Storazzo::Common
|
20
|
+
|
21
|
+
# _sample_version
|
22
|
+
def load
|
23
|
+
deb("[RicDiskSampleConfig] Wheew 1! We're NOT destroying the world here. We're actually instancing a second Singleton which is a child of the mother, and this time doing things nicely and Rubily.")
|
24
|
+
super(DefaultGemLocationForTests, verbose: false)
|
25
|
+
end
|
26
|
+
|
27
|
+
def load_sample_version
|
28
|
+
deb white("[RicDiskSampleConfig] Wheew 2! We're NOT destroying the world here. We're actually instancing a second Singleton which is a child of the mother, and this time doing things nicely and Rubily.")
|
29
|
+
super(DefaultGemLocationForTests, verbose: false)
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
31
|
-
end
|
33
|
+
end
|
@@ -1,24 +1,26 @@
|
|
1
|
-
#
|
2
|
-
# directly in the disk: /mount/
|
3
|
-
module Storazzo
|
4
|
-
class Storazzo::RicDiskStatsFile
|
5
|
-
# Please keep these two in sync, until you fix them and DRY the behaviour.
|
6
|
-
DefaultName = "ricdisk_stats_v11.rds" # => RicDiskStatsFile
|
7
|
-
Version = "1.1" # @@version
|
1
|
+
# frozen_string_literal: true
|
8
2
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
3
|
+
module Storazzo
|
4
|
+
module Storazzo
|
5
|
+
# This class wraps the RDS file: we're going to write this RDS file
|
6
|
+
# directly in the disk: /mount/
|
7
|
+
class RicDiskStatsFile
|
8
|
+
# Please keep these two in sync, until you fix them and DRY the behaviour.
|
9
|
+
DefaultName = 'ricdisk_stats_v11.rds' # => RicDiskStatsFile
|
10
|
+
Version = '1.1' # @@version
|
13
11
|
|
14
|
-
|
12
|
+
# AttrAccessor for class - thanks StackOverflow from Android since Im in roaming :)
|
13
|
+
class << self
|
14
|
+
attr_accessor :my_default_name, :my_version # without MY it redefines whats below :/
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def self.default_name
|
18
|
+
DefaultName
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
21
|
+
def self.version
|
22
|
+
Version
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|
data/lib/storazzo/version.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# copied from https://github.com/rails/strong_parameters/edit/master/lib/strong_parameters/version.rb
|
2
4
|
# I;'m copying the DHH philosophy here.
|
3
5
|
module Storazzo
|
4
6
|
# DHH_VERSION = "0.2.3._TODOFileRead.1" # TODO file.read ../../VERSION . chomp
|
5
|
-
RICC_VERSION = File.read(
|
6
|
-
|
7
|
-
public
|
7
|
+
RICC_VERSION = File.read('../VERSION').chomp
|
8
8
|
|
9
9
|
def self.version
|
10
10
|
RICC_VERSION
|
data/lib/storazzo.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Inspired from https://guides.rubygems.org/make-your-own-gem/#introduction
|
2
4
|
|
3
5
|
module Storazzo
|
@@ -5,17 +7,17 @@ module Storazzo
|
|
5
7
|
# require 'storazzo/translator'
|
6
8
|
|
7
9
|
def latest_parser_version
|
8
|
-
|
10
|
+
'1.2'
|
9
11
|
end
|
10
12
|
|
11
13
|
# Finds RAILS_ROOT for Storazzo Gem. Copied from:
|
12
14
|
# https://stackoverflow.com/questions/10132949/finding-the-gem-root
|
13
15
|
def self.root
|
14
|
-
File.expand_path '
|
16
|
+
File.expand_path '..', __dir__
|
15
17
|
end
|
16
18
|
|
17
19
|
def self.version
|
18
|
-
File.read(
|
20
|
+
File.read("#{root}/VERSION").chomp # "10.0.0"
|
19
21
|
end
|
20
22
|
|
21
23
|
# alias_method :VERSION, :version
|
@@ -30,12 +32,9 @@ end
|
|
30
32
|
|
31
33
|
# nice to paste nice output
|
32
34
|
require 'pp'
|
33
|
-
require 'require_all'
|
34
35
|
|
35
|
-
# require_all './' , 'media/'
|
36
|
-
# require_all 'lib/**/*.rb'
|
37
36
|
# require_rel '.', 'media'
|
38
|
-
Dir[File.dirname(__FILE__)
|
37
|
+
Dir["#{File.dirname(__FILE__)}/../lib/*.rb"].each do |file|
|
39
38
|
puts "+ Requiring... #{file}"
|
40
39
|
require File.basename(file, File.extname(file))
|
41
40
|
end
|