class RspecPuppetFactsUnsupported::UnsupportedFilteringOperation
Private opertion wrapper class
Public Class Methods
new(facts_list, opts)
click to toggle source
# File lib/rspec-puppet-facts-unsupported/on_unsupported_os.rb, line 226 def initialize(facts_list, opts) @opts = opts @facts_list = facts_list end
Public Instance Methods
facts()
click to toggle source
# File lib/rspec-puppet-facts-unsupported/on_unsupported_os.rb, line 231 def facts postprocess_facts(reject_supported_os) end
Private Instance Methods
describe_os(facts)
click to toggle source
# File lib/rspec-puppet-facts-unsupported/on_unsupported_os.rb, line 267 def describe_os(facts) "#{facts[:operatingsystem].downcase}-" \ "#{facts[:operatingsystemmajrelease]}-" \ "#{facts[:hardwaremodel]}" end
operatingsystemrelease_matches?(operatingsystemrelease, candidate)
click to toggle source
# File lib/rspec-puppet-facts-unsupported/on_unsupported_os.rb, line 282 def operatingsystemrelease_matches?(operatingsystemrelease, candidate) if operatingsystemrelease.nil? true else candidate_release = candidate[:operatingsystemrelease] operatingsystemrelease.select { |elem| candidate_release.start_with?(elem) }.any? end end
postprocess_facts(facts_list)
click to toggle source
# File lib/rspec-puppet-facts-unsupported/on_unsupported_os.rb, line 248 def postprocess_facts(facts_list) os_facts_hash = {} facts_list.map do |facts| description = describe_os(Facts.new(facts)) facts.merge! RspecPuppetFacts.common_facts os_facts_hash[description] = RspecPuppetFacts.with_custom_facts(description, facts) end shuffle_and_limit(os_facts_hash) end
reject_supported_os()
click to toggle source
# File lib/rspec-puppet-facts-unsupported/on_unsupported_os.rb, line 237 def reject_supported_os metadata_supported = @opts[:supported_os] @facts_list.reject do |candidate_raw| candidate = Facts.new(candidate_raw) req = metadata_supported.select do |single_req| single_req['operatingsystem'] == candidate[:operatingsystem] end should_be_rejected?(req, candidate) end end
should_be_rejected?(req, candidate)
click to toggle source
# File lib/rspec-puppet-facts-unsupported/on_unsupported_os.rb, line 273 def should_be_rejected?(req, candidate) if req.empty? false else req = req.first operatingsystemrelease_matches?(req['operatingsystemrelease'], candidate) end end
shuffle_and_limit(os_facts_hash)
click to toggle source
# File lib/rspec-puppet-facts-unsupported/on_unsupported_os.rb, line 258 def shuffle_and_limit(os_facts_hash) randomizer = @opts[:randomizer] as_array = os_facts_hash.to_a as_array = as_array.sort_by { |os, _| os } as_array = as_array.shuffle(random: randomizer.get) as_array = as_array[0..@opts[:limit]] Hash[*as_array.flatten] end