Module: Facter::Util::Bigbigpuppetfacts
- Defined in:
- lib/facter/util/bigbigpuppetfacts.rb
Overview
Module for fact compression, compatible with Facter Cache
Class Attribute Summary collapse
- .namedelim ⇒ Object
-
.pipeprocess_stats ⇒ Object
Returns the value of attribute pipeprocess_stats.
Class Method Summary collapse
-
.autoload_declare ⇒ Object
def value(user_query, compressmethod_to_use = ‘auto’) value_direct = Facter.value(user_query).
- .checkmethod(method, fallback_method = ['plain']) ⇒ Object
- .checkmethod_geterrormsg ⇒ Object
- .checkmethod_seterrormsg(msg = @const_default_error_msg) ⇒ Object
- .compress(data, method) ⇒ Object
-
.compress_cleansemethods(compressmethods_chosen) ⇒ Object
Remove Invalid CompressMethods.
- .compress_precheck?(methods) ⇒ Boolean
- .compressed_factname_dump(factname, compressmethod) ⇒ Object
- .compressed_factname_info(factname, _compressmethod) ⇒ Object
- .compressed_factnames(factname, compressmethod) ⇒ Object
-
.compressmethods ⇒ Object
-
denote sub compression methods.
- .decompress(data, method) ⇒ Object
-
.decompress_cleansemethods(decompressmethods_chosen) ⇒ Object
Remove Invalid DecompressMethods.
- .decompress_precheck?(methods) ⇒ Boolean
- .decompressmethods ⇒ Object
- .namedelim_ ⇒ Object
-
.pipeprocess(data, processpipe, _info: {}) ⇒ Object
rubocop:disable Lint/UnderscorePrefixedVariableName.
- .set_namedelim_=(delim) ⇒ Object
- .summarise(srcdata, summariseoptions, summarisedversion = {}) ⇒ Object
- .testdata ⇒ Object
- .use_compressmethod(compressmethod_chosen) ⇒ Object
Class Attribute Details
.namedelim ⇒ Object
42 43 44 45 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 42 def namedelim @namedelim = '_' if @namedelim.nil? # Used to be . @namedelim end |
.pipeprocess_stats ⇒ Object
Returns the value of attribute pipeprocess_stats.
472 473 474 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 472 def pipeprocess_stats @pipeprocess_stats end |
Class Method Details
.autoload_declare ⇒ Object
def value(user_query, compressmethod_to_use = ‘auto’)
value_direct = Facter.value(user_query)
compressmethod_to_use = @compressmethod if compressmethod_to_use == 'auto'
if %r{-dump.}.match?(user_query)
clear_value_direct = value_direct
value_direct = user_query.gsub(%r{.}, '_') ### System will use the key to know the compression
end
case value_direct
when %r{^bbpf_xz@}
value_direct = XZ.compress(value_direct.gsub(%r{^bbpf_xz@}, ''))
when %r{^bbpf_xz_base64@}
value_direct = XZ.decompress(Base64.decode64(value_direct.gsub(%r{^bbpf_xz_base64@}, '')))
value_direct = JSON.parse(value_direct)
when %r{xz_base64}
value_direct = clear_value_direct
value_direct = XZ.decompress(Base64.decode64(value_direct))
value_direct = JSON.parse(value_direct)
else
case compressmethod_to_use
when 'xz'
value_direct = XZ.compress(value_direct)
when 'xz_base64'
value_direct = XZ.decompress(Base64.decode64(value_direct))
value_direct = JSON.parse(value_direct)
else
value_direct
end
end
value_direct
end
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 94 def autoload_declare lib_path = File.join(File.dirname(__FILE__), './bzip2-ffi-1.1.0/lib/') $LOAD_PATH << lib_path unless $LOAD_PATH.include?(lib_path) lib_path = File.join(File.dirname(__FILE__), './rbzip2-0.3.0/lib/') $LOAD_PATH << lib_path unless $LOAD_PATH.include?(lib_path) lib_path = File.join(File.dirname(__FILE__), './ruby-xz-1.0.0/lib/') $LOAD_PATH << lib_path unless $LOAD_PATH.include?(lib_path) lib_path = File.join(File.dirname(__FILE__), './seven_zip_ruby-1.3.0/lib/') $LOAD_PATH << lib_path unless $LOAD_PATH.include?(lib_path) lib_path = File.join(File.dirname(__FILE__), './simple_compress-0.0.1/lib/') $LOAD_PATH << lib_path unless $LOAD_PATH.include?(lib_path) lib_path = File.dirname(__FILE__) $LOAD_PATH << lib_path unless $LOAD_PATH.include?(lib_path) lib_path = File.join(File.dirname(__FILE__), '../../') $LOAD_PATH << lib_path unless $LOAD_PATH.include?(lib_path) autoload :XZ, 'xz' autoload :RBzip2, 'rbzip2' autoload :SevenZipRuby, 'seven_zip_ruby' autoload :SimpleCompress, 'simple_compress' autoload :Zlib, 'zlib' autoload :Bzip2, 'bzip2/ffi' autoload :Open3, 'open3' end |
.checkmethod(method, fallback_method = ['plain']) ⇒ Object
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 545 def checkmethod(method, fallback_method = ['plain']) autoload_declare if fallback_method.is_a? String fallback_method = fallback_method.split(',') # fallback_method += ['plain'] end if method.is_a? String method = method.split(',') end method += fallback_method method = method.reject { |x| x.nil? || x.empty? }.reduce(nil) do |selectmethod, method2test| if selectmethod.nil? || selectmethod.empty? begin checkmethod_seterrormsg unless method2test == '::error' testdataend = decompress(compress(testdata, method2test), method2test) unless %r{::simulate}.match?(method2test) # %r{^::}.match?(method2test) Give a pass to internal methods...including the ::error, so we can force for an error in a testing environment selectmethod = method2test if testdata == testdataend || %r{::simulate}.match?(method2test) || %r{^::}.match?(method2test) || Regexp.new("#{namedelim}::").match?(method2test) rescue LoadError => e selectmethod = nil checkmethod_seterrormsg(e) rescue => e selectmethod = nil checkmethod_seterrormsg(e) end end selectmethod end method end |
.checkmethod_geterrormsg ⇒ Object
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 520 def checkmethod_geterrormsg @const_default_error_msg ||= 'FATAL ERROR During Processing: Please use another processing method.' return nil if @checkmethod_errormsg_.nil? || @checkmethod_errormsg_.is_a?(String) && @checkmethod_errormsg_.empty? if @checkmethod_errormsg_.is_a?(String) && @checkmethod_errormsg_ == @const_default_error_msg @checkmethod_errormsg_ else e = @checkmethod_errormsg_ errorjson = {} errorjson['value'] = @const_default_error_msg errorjson['exceptiontype'] = e.class.to_s errorjson['message'] = "Error during processing: #{$ERROR_INFO}\n" \ "#{e.}\n" \ "Backtrace:\n\t#{e.backtrace.join("\n\t")}" JSON.generate(errorjson) end end |
.checkmethod_seterrormsg(msg = @const_default_error_msg) ⇒ Object
541 542 543 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 541 def checkmethod_seterrormsg(msg = @const_default_error_msg) @checkmethod_errormsg_ = msg end |
.compress(data, method) ⇒ Object
465 466 467 468 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 465 def compress(data, method) methodprocs = method.split(namedelim_).map { |m| compressmethods[m] } pipeprocess(data, methodprocs, _info: { 'm' => method, 'compress' => true }) end |
.compress_cleansemethods(compressmethods_chosen) ⇒ Object
Remove Invalid CompressMethods
457 458 459 460 461 462 463 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 457 def compress_cleansemethods(compressmethods_chosen) ## Remove Invalid CompressMethods compressmethods_chosen = compressmethods_chosen.split(',') if compressmethods_chosen.is_a? String compressmethods_chosen.select do |method| method.split(namedelim_).map { |m| compressmethods[m] }.all? { |p| !p.nil? } end end |
.compress_precheck?(methods) ⇒ Boolean
450 451 452 453 454 455 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 450 def compress_precheck?(methods) methods = methods.split(',') if methods.is_a? String methods.all? do |method| method.split(namedelim_).map { |m| compressmethods[m] }.all? { |p| !p.nil? } end end |
.compressed_factname_dump(factname, compressmethod) ⇒ Object
582 583 584 585 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 582 def compressed_factname_dump(factname, compressmethod) factname_data = "#{factname}-dump#{namedelim}#{compressmethod.tr(namedelim_, namedelim)}" factname_data end |
.compressed_factname_info(factname, _compressmethod) ⇒ Object
577 578 579 580 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 577 def compressed_factname_info(factname, _compressmethod) factname_info = "#{factname}-info" factname_info end |
.compressed_factnames(factname, compressmethod) ⇒ Object
587 588 589 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 587 def compressed_factnames(factname, compressmethod) [ compressed_factname_info(factname, compressmethod), compressed_factname_dump(factname, compressmethod) ] end |
.compressmethods ⇒ Object
-
denote sub compression methods
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 127 def compressmethods autoload_declare { # 'bbpf_xz' => proc { |data| 'bbpf_xz@' + XZ.compress(data) }, # 'bbpf_xz_base64' => proc { |data| 'bbpf_xz_base64@' + Base64.encode64(XZ.compress(data)) }, # inbuild method is now prefix with :: '::shellout' => proc { |data, cmd1 = 'tee', cmd2 = 'tee', cmd3 = 'tee', _info: {}| Open3.pipeline_rw(cmd1, cmd2, cmd3) do |i, o, _ts| i.puts data i.close o.read end }, '::error' => proc { |_data, error_msg = '', error_msg_prefix = '', error_msg_postfix = '', _info: {}| error_msg = checkmethod_geterrormsg if error_msg.empty? error_msg = @const_default_error_msg if error_msg.nil? || error_msg.empty? error_msg_prefix + error_msg + error_msg_postfix }, '::simulateruntimeerror' => proc { |data, _info: {}| unless ENV['simulateruntimeerror'].nil? || ENV['simulateruntimeerror'].empty? raise NameError, ENV['simulateruntimeerror'] if ENV['simulateruntimeerror'].include? 'NameError' ::FFI::Library.ffi_lib ['/lib/NOSUCHTHING'] if ENV['simulateruntimeerror'].include? 'LoadError' raise StandardError, ENV['simulateruntimeerror'] if ENV['simulateruntimeerror'].include? 'ERROR' raise ENV['simulateruntimeerror'] end data }, 'simulateruntimeerror' => proc { |data, _info: {}| compressmethods['::simulateruntimeerror'].call(data) }, # 7z, zip, gzip, bzip2 or tar. 7z xz '7z::xz::shellout' => proc { |data, _info: {}| compressmethods['::shellout'].call(data, '7za -txz -an -si -so a', 'tee') }, '7z::gzip::shellout' => proc { |data, _info: {}| compressmethods['::shellout'].call(data, '7za -tgzip -an -si -so a', 'tee') }, '7z::bzip2::shellout' => proc { |data, _info: {}| compressmethods['::shellout'].call(data, '7za -tbzip2 -an -si -so a', 'tee') }, '7z::zip::shellout' => proc { |data, _info: {}| compressmethods['::shellout'].call(data, '7za -tzip -an -si -so a', 'tee') }, '7z::shellout' => proc { |data, _info: {}| compressmethods['::shellout'].call(data, '7za -txz -an -si -so a', 'tee') }, '7z::' => proc { |data, _info: {}| dfile = StringIO.new('') SevenZipRuby::Writer.open(dfile) do |szr| szr.add_data data, 'file.bin' end data = dfile.string data }, 'gz::simplecompress' => proc { |data, _info: {}| SimpleCompress.compress(data) }, 'gz::zlibgzip' => proc { |data, _info: {}| buf = StringIO.new gz = Zlib::GzipWriter.new(buf) gz.write(data) gz.close buf.string.force_encoding(Encoding::BINARY) }, 'gz::zlib' => proc { |data, _info: {}| Zlib::Deflate.deflate(data, Zlib::BEST_COMPRESSION) }, 'gz' => proc { |data, _info: {}| compressmethods['gz::zlibgzip'].call(data) }, 'xz' => proc { |data, _info: {}| XZ.compress(data) }, 'bz2::ffi' => proc { |data, _info: {}| dfile = StringIO.new('') bz2 = RBzip2::FFI::Compressor.new(dfile) # wrap the file into the compressor bz2.write data # write the raw data to the compressor bz2.close data = dfile.string data }, 'bz2::java' => proc { |data, _info: {}| dfile = StringIO.new('') bz2 = RBzip2::Java::Compressor.new(dfile) # wrap the file into the compressor bz2.write data # write the raw data to the compressor bz2.close data = dfile.string data }, 'bz2::ruby' => proc { |data, _info: {}| dfile = StringIO.new('') bz2 = RBzip2::Ruby::Compressor.new(dfile) # wrap the file into the compressor bz2.write data # write the raw data to the compressor bz2.close data = dfile.string data }, 'bz2::cmd' => proc { |data, _info: {}| compressmethods['::shellout'].call(data, 'bzip2 -z --best -s -qc ', 'tee') }, 'bz2::auto' => proc { |data, _info: {}| dfile = StringIO.new('') bz2 = RBzip2.default_adapter::Compressor.new(dfile) # wrap the file into the compressor bz2.write data # write the raw data to the compressor bz2.close data = dfile.string data }, 'bzip2' => proc { |data, _info: {}| dfile = StringIO.new('') Bzip2::FFI::Writer.write(dfile, data) data = dfile.string data }, 'bz2' => proc { |data, _info: {}| begin compressmethods['bzip2'].call(data) rescue NameError, LoadError, Bzip2::FFI::Error::MagicDataError begin compressmethods['bz2::auto'].call(data) rescue NameError, LoadError compressmethods['bz2::ruby'].call(data) end end }, 'base64' => proc { |data, _info: {}| Base64.encode64(data) }, '^json' => proc { |data, _info: {}| begin JSON.generate(data) rescue data end }, '^yaml' => proc { |data, _info: {}| begin YAML.dump(data) rescue data end }, 'bbpf' => proc { |data, _info: {}| # rubocop:disable Lint/UnderscorePrefixedVariableName _info['m'] = _info['m'].gsub(%r{bbpf_}, '') m = 'bbpf::start' + namedelim_ + (_info['m']).to_s + namedelim_ + 'bbpf::end' data = compress(data, m) _info['continue'] = false data }, # Special Method which prefix the final Data with the compression methods/process e.g. "bbpf_XX_YY" 'bbpf::start' => proc { |data, _info: {}| data }, # Special Method which prefix the final Data with the compression methods/process e.g. "bbpf_XX_YY" 'bbpf::end' => proc { |data, _info: {}| # rubocop:disable Lint/UnderscorePrefixedVariableName _info['m'].to_s + namedelim_ + 'bbpf@' + data }, # Special Method which prefix the final Data with the compression methods/process e.g. "bbpf_XX_YY" 'dataurl' => proc { |data, _info: {}| # rubocop:disable Lint/UnderscorePrefixedVariableName m = _info['m'].gsub(%r{dataurl_}, '') data = compress(data, m) data = "data:text/plain;base64,#{data.delete("\n")}" _info['continue'] = false data }, 'plain' => proc { |data, _info: {}| data }, '^nil::' => proc { |_data, _info: {}| nil } } end |
.decompress(data, method) ⇒ Object
445 446 447 448 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 445 def decompress(data, method) methodprocs = method.split(namedelim_).reverse.map { |m| decompressmethods[m] } pipeprocess(data, methodprocs, _info: { 'm' => method, 'compress' => false }) end |
.decompress_cleansemethods(decompressmethods_chosen) ⇒ Object
Remove Invalid DecompressMethods
437 438 439 440 441 442 443 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 437 def decompress_cleansemethods(decompressmethods_chosen) ## Remove Invalid DecompressMethods decompressmethods_chosen = decompressmethods_chosen.split(',') if decompressmethods_chosen.is_a? String decompressmethods_chosen.select do |method| method.split(namedelim_).map { |m| decompressmethods[m] }.all? { |p| !p.nil? } end end |
.decompress_precheck?(methods) ⇒ Boolean
430 431 432 433 434 435 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 430 def decompress_precheck?(methods) methods = methods.split(',') if methods.is_a? String methods.all? do |method| method.split(namedelim_).map { |m| decompressmethods[m] }.all? { |p| !p.nil? } end end |
.decompressmethods ⇒ Object
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 297 def decompressmethods autoload_declare { # 'bbpf_xz' => proc { |data| XZ.decompress(data.gsub(%r{^bbpf_xz@}, '')) }, # 'bbpf_xz_base64' => proc { |data| XZ.decompress(Base64.decode64(data.gsub(%r{^bbpf_xz_base64@}, ''))) }, '::shellout' => proc { |data, cmd1 = 'tee', cmd2 = 'tee', cmd3 = 'tee', _info: {}| compressmethods['::shellout'].call(data, cmd1, cmd2, cmd3) }, '::error' => proc { |data, error_msg = '', error_msg_prefix = '', error_msg_postfix = '', _info: {}| compressmethods['::error'].call(data, error_msg, error_msg_prefix, error_msg_postfix) }, '::simulateruntimeerror' => proc { |data, _info: {}| # compressmethods['::simulateruntimeerror'].call(data) data }, 'simulateruntimeerror' => proc { |data, _info: {}| # compressmethods['::simulateruntimeerror'].call(data) data }, '7z::xz::shellout' => proc { |data, _info: {}| compressmethods['::shellout'].call(data, '7za -txz -an -si -so x', 'tee') }, '7z::gzip::shellout' => proc { |data, _info: {}| compressmethods['::shellout'].call(data, '7za -tgzip -an -si -so x', 'tee') }, '7z::bzip2::shellout' => proc { |data, _info: {}| compressmethods['::shellout'].call(data, '7za -tbzip2 -an -si -so x', 'tee') }, '7z::zip::shellout' => proc { |data, _info: {}| compressmethods['::shellout'].call(data, '7za -tzip -an -si -so x', 'tee') }, '7z::shellout' => proc { |data, _info: {}| compressmethods['::shellout'].call(data, '7za -txz -an -si -so x', 'tee') }, '7z::' => proc { |data, _info: {}| dfile = StringIO.new(data) data = nil SevenZipRuby::Reader.open(dfile) do |szr| smallest_file = szr.entries.select(&:file?).min_by(&:size) ### There should be only 1 file.. So no worry.. data = szr.extract_data(smallest_file) end data }, 'gz::simplecompress' => proc { |data, _info: {}| SimpleCompress.(data) }, 'gz::zlibgzip' => proc { |data, _info: {}| buf = StringIO.new(data) z = Zlib::GzipReader.new(buf) z.read }, 'gz::zlib' => proc { |data, _info: {}| Zlib::Inflate.inflate(data) }, 'gz' => proc { |data, _info: {}| decompressmethods['gz::zlibgzip'].call(data) }, 'xz' => proc { |data, _info: {}| XZ.decompress(data) }, 'bz2::ffi' => proc { |data, _info: {}| bz2 = RBzip2::FFI::Decompressor.new(StringIO.new(data)) # wrap the file into the decompressor data = bz2.read bz2.close data }, 'bz2::java' => proc { |data, _info: {}| bz2 = RBzip2::Java::Decompressor.new(StringIO.new(data)) # wrap the file into the decompressor data = bz2.read bz2.close data }, 'bz2::ruby' => proc { |data, _info: {}| bz2 = RBzip2::Ruby::Decompressor.new(StringIO.new(data)) # wrap the file into the decompressor data = bz2.read bz2.close data }, 'bz2::auto' => proc { |data, _info: {}| bz2 = RBzip2.default_adapter::Decompressor.new(StringIO.new(data)) # wrap the file into the decompressor data = bz2.read bz2.close data }, 'bz2::cmd' => proc { |data, _info: {}| compressmethods['::shellout'].call(data, 'bzip2 -d --best -s -qc ', 'tee') }, 'bzip2' => proc { |data, _info: {}| data = Bzip2::FFI::Reader.read(StringIO.new(data)) data }, 'bz2' => proc { |data, _info: {}| begin decompressmethods['bzip2'].call(data) rescue NameError, LoadError, Bzip2::FFI::Error::MagicDataError begin decompressmethods['bz2::auto'].call(data) rescue NameError, LoadError decompressmethods['bz2::ruby'].call(data) end end }, 'base64' => proc { |data, _info: {}| Base64.decode64(data) }, '^json' => proc { |data, _info: {}| begin JSON.parse(data) rescue data end }, '^yaml' => proc { |data, _info: {}| begin YAML.safe_load(data) rescue data end }, 'bbpf' => proc { |data, _info: {}| # rubocop:disable Lint/UnderscorePrefixedVariableName m = data.match(%r{^.+bbpf@})[0] data = data.gsub(m, '') m = m.gsub(%r{.bbpf@}, '') data = decompress(data, m) _info['continue'] = false data }, # Special Method which prefix the final Data with the compression methods/process e.g. "bbpf_XX_YY" 'bbpf::start' => proc { |data, _info: {}| data }, # Special Method which prefix the final Data with the compression methods/process e.g. "bbpf_XX_YY" 'bbpf::end' => proc { |data, _info: {}| data }, # Special Method which prefix the final Data with the compression methods/process e.g. "bbpf_XX_YY" 'plain' => proc { |data, _info: {}| data }, '^nil::' => proc { |_data, _info: {}| nil } } end |
.namedelim_ ⇒ Object
51 52 53 54 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 51 def namedelim_ @namedelim_ = '_' if @namedelim_.nil? @namedelim_ end |
.pipeprocess(data, processpipe, _info: {}) ⇒ Object
rubocop:disable Lint/UnderscorePrefixedVariableName
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 474 def pipeprocess(data, processpipe, _info: {}) # rubocop:disable Lint/UnderscorePrefixedVariableName @pipeprocess_stats << data.to_s.length unless @pipeprocess_stats.nil? || data.nil? _info['continue'] = true processpipe.reduce(data) do |data__, p| if _info['continue'] o = p.call(data__, _info: _info) unless @pipeprocess_stats.nil? || data.nil? @pipeprocess_stats << if o.nil? -1 else o.to_s.length end end else o = data__ end o end end |
.set_namedelim_=(delim) ⇒ Object
47 48 49 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 47 def set_namedelim_=(delim) @namedelim_ = delim end |
.summarise(srcdata, summariseoptions, summarisedversion = {}) ⇒ Object
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 591 def summarise(srcdata, , summarisedversion = {}) return summarisedversion unless srcdata.is_a?(Hash) || srcdata.is_a?(Array) return summarisedversion if !srcdata.is_a?(Hash) && .is_a?(Hash) return summarisedversion if !srcdata.is_a?(Array) && .is_a?(Array) if .is_a? Hash .each do |k0, v0| if (k0.is_a? String) && (k0 =~ %r{^/.+/$}) ## If a regex, expand into all matches p = k0.gsub(%r{^[\./]}, '').gsub(%r{[/]$}, '') pattern2use = Regexp.new(p) keys_matches = srcdata.select { |k1, _v1| (pattern2use.match k1) || pattern2use.match(k1.to_s) }.keys # summarisedversion.merge!(hh) = {} keys_matches.each { |k_match| [k_match] = v0 } else ## If not a regex, there will only 1 match = { k0 => v0 } end .each do |k, v| if v == '*' && !srcdata[k].nil? summarisedversion[k] = srcdata[k] elsif v.is_a?(Hash) && !srcdata[k].nil? summarisedversion[k] = {} summarisedversion[k] = summarise(srcdata[k], v, summarisedversion[k]) elsif v.is_a?(Array) && !srcdata[k].nil? summarisedversion[k] = [] summarisedversion[k] = summarise(srcdata[k], v, summarisedversion[k]) elsif srcdata.key?(k) && !srcdata[k].nil? summarisedversion[k] = srcdata[k] elsif srcdata.key?(k.to_sym) && !srcdata[k.to_sym].nil? summarisedversion[k] = srcdata[k.to_sym] end end end elsif .is_a? Array summarisedversion = [] unless summarisedversion.is_a? Array srcdata.each do |x| new_e = summarise(x, [0]) summarisedversion.push(new_e) unless new_e.nil? || new_e.empty? end end summarisedversion end |
.testdata ⇒ Object
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 494 def testdata t = <<-TTTTTDATA SOOYEANISTESTINGCOMPRESSFACTWITH THIS STRING=+_` <[{ 'aaaa':'a0/s'}]>|!/? @The quick brown fox jumps over the lazy dog's back @THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG'S BACK 1234567890@ @Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.@ @\#\$#%$@^%$#^%^$&^&%*&*(&^(&^)*&^)*&`\"\\" { "a" : "", "b":null, "c":"aaaa" } TTTTTDATA t end |
.use_compressmethod(compressmethod_chosen) ⇒ Object
56 57 58 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 56 def use_compressmethod(compressmethod_chosen) @compressmethod = compressmethod_chosen end |