Module: ChefConfig::Mixin::FuzzyHostnameMatcher

Included in:
Config
Defined in:
lib/chef-config/mixin/fuzzy_hostname_matcher.rb

Instance Method Summary collapse

Instance Method Details

#fuzzy_hostname_match?(hostname, match) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/chef-config/mixin/fuzzy_hostname_matcher.rb', line 33

def fuzzy_hostname_match?(hostname, match)
  # Do greedy matching by adding wildcard if it is not specified
  match = "*" + match unless match.start_with?("*")
  Fuzzyurl.matches?(Fuzzyurl.mask(hostname: match), hostname)
end

#fuzzy_hostname_match_any?(hostname, matches) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
# File 'lib/chef-config/mixin/fuzzy_hostname_matcher.rb', line 23

def fuzzy_hostname_match_any?(hostname, matches)
  if (!hostname.nil?) && (!matches.nil?)
    return matches.to_s.split(/\s*,\s*/).compact.any? do |m|
      fuzzy_hostname_match?(hostname, m)
    end
  end

  false
end