Module: Facter::Util::Bigbigpuppetfacter
- Defined in:
- lib/facter/util/bigbigpuppetfacts.rb
Overview
Module to Help in Resolution when using Bigbigpuppetfacter for setting Compression Method.
Instance Method Summary collapse
- #compress(value, method = 'auto', bypass_shellcommands = nil) ⇒ Object
- #compressmethod_used ⇒ Object
- #decompress(_compressed_value, method = 'auto') ⇒ Object
- #use_compressmethod(compressmethod_chosen) ⇒ Object
- #use_compressmethod_fallback(compressmethod_chosen = nil) ⇒ Object
Instance Method Details
#compress(value, method = 'auto', bypass_shellcommands = nil) ⇒ Object
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 675 def compress(value, method = 'auto', bypass_shellcommands = nil) if block_given? yield(method) end unless bypass_shellcommands.nil? || bypass_shellcommands.empty? return Facter::Core::Execution.execute(bypass_shellcommands) end @compressmethod_fallback = '^nil::' if @compressmethod_fallback.nil? || @compressmethod_fallback.empty? method = @compressmethod if method == 'auto' && !@compressmethod.nil? method = nil if method == 'auto' method = [] if method.nil? || method.empty? method = Facter::Util::Bigbigpuppetfacts.checkmethod(method, @compressmethod_fallback) if method.nil? && @compressmethod_fallback == '{yield}' @compressmethod_fallback_proc.call(value) else return nil if method.nil? if !value.is_a?(String) && !%r{^[\^]}.match?(method) method = '^json' + Facter::Util::Bigbigpuppetfacts.namedelim_ + method end begin Facter::Util::Bigbigpuppetfacts.compress(value, method) rescue NameError, LoadError => e Facter::Util::Bigbigpuppetfacts.checkmethod_seterrormsg(e) Facter::Util::Bigbigpuppetfacts.compressmethods['::error'].call(value) rescue => e Facter::Util::Bigbigpuppetfacts.checkmethod_seterrormsg(e) Facter::Util::Bigbigpuppetfacts.compressmethods['::error'].call(value) end end end |
#compressmethod_used ⇒ Object
638 639 640 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 638 def compressmethod_used @compressmethod end |
#decompress(_compressed_value, method = 'auto') ⇒ Object
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 715 def decompress(_compressed_value, method = 'auto') if block_given? yield(method) end @compressmethod_fallback = '^nil::' if @compressmethod_fallback.nil? || @compressmethod_fallback.empty? method = @compressmethod if method == 'auto' && !@compressmethod.nil? method = nil if method == 'auto' method = [] if method.nil? || method.empty? method = Facter::Util::Bigbigpuppetfacts.checkmethod(method, @compressmethod_fallback) return nil if method.nil? begin Facter::Util::Bigbigpuppetfacts.decompress(value, method) rescue NameError, LoadError => e Facter::Util::Bigbigpuppetfacts.checkmethod_seterrormsg(e) Facter::Util::Bigbigpuppetfacts.decompressmethods['::error'].call(value) rescue => e Facter::Util::Bigbigpuppetfacts.checkmethod_seterrormsg(e) Facter::Util::Bigbigpuppetfacts.decompressmethods['::error'].call(value) end end |
#use_compressmethod(compressmethod_chosen) ⇒ Object
642 643 644 645 646 647 648 649 650 651 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 642 def use_compressmethod(compressmethod_chosen) return if @compressmethod == compressmethod_chosen compressmethod_chosen = Facter::Util::Bigbigpuppetfacts.compress_cleansemethods(compressmethod_chosen) unless compressmethod_chosen.nil? Facter::Util::Bigbigpuppetfacts.autoload_declare compressmethod_chosen = Facter::Util::Bigbigpuppetfacts.checkmethod(compressmethod_chosen, @compressmethod_fallback) @compressmethod = compressmethod_chosen end |
#use_compressmethod_fallback(compressmethod_chosen = nil) ⇒ Object
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 |
# File 'lib/facter/util/bigbigpuppetfacts.rb', line 653 def use_compressmethod_fallback(compressmethod_chosen = nil) compressmethod_chosen = Facter::Util::Bigbigpuppetfacts.compress_cleansemethods(compressmethod_chosen) unless compressmethod_chosen.nil? @compressmethod_fallback = if compressmethod_chosen.nil? if block_given? # Use the Block if no compressmethod_chosen is given, while block is. '{yield}' else # no block and parameter...... then reset the original behaviour. '^nil::' end # fallback is valid or not based on compress_precheck? elsif Facter::Util::Bigbigpuppetfacts.compress_precheck?(compressmethod_chosen) compressmethod_chosen else '^nil::' end @compressmethod_fallback_proc = if @compressmethod_fallback == '{yield}' proc { yield } else Facter::Util::Bigbigpuppetfacts.compressmethods[@compressmethod_fallback] end end |