class Object

Constants

LEGACY_FACTS_REGEX
LEGACY_FACTS_STATIC

Public Instance Methods

check() click to toggle source
# File lib/puppet-lint/plugins/legacy_fact.rb, line 107
def check
  tokens.select { |r|
    Set[:VARIABLE, :UNENC_VARIABLE].include? r.type
  }.each do |token|
    if is_legacy_fact(normalize_fact(token.value))
      notify :warning, {
        :message => 'legacy fact used',
        :line    => token.line,
        :column  => token.column,
        :token   => token,
      }
    end
  end
end
find_regex_fact(fact) click to toggle source
# File lib/puppet-lint/plugins/legacy_fact.rb, line 138
def find_regex_fact(fact)
  LEGACY_FACTS_REGEX.each do |pattern, replacement|
    if (md = pattern.match(fact))
      return replacement % md.captures
    end
  end

  nil
end
find_static_fact(fact) click to toggle source
# File lib/puppet-lint/plugins/legacy_fact.rb, line 134
def find_static_fact(fact)
  LEGACY_FACTS_STATIC[fact]
end
fix(problem) click to toggle source
# File lib/puppet-lint/plugins/legacy_fact.rb, line 122
def fix(problem)
  replacement = replacement_fact(normalize_fact(problem[:token].value))
  raise PuppetLint::NoFix if replacement.nil? || replacement.empty?
  problem[:token].value = replacement
end
is_legacy_fact(fact) click to toggle source
# File lib/puppet-lint/plugins/legacy_fact.rb, line 148
def is_legacy_fact(fact)
  !find_static_fact(fact).nil? || !find_regex_fact(fact).nil?
end
normalize_fact(fact) click to toggle source
# File lib/puppet-lint/plugins/legacy_fact.rb, line 130
def normalize_fact(fact)
  fact.gsub(/^(::)?(.+)$/, '\2').gsub(/^facts\[("|')(.+)\1\]/, '\2')
end
replacement_fact(fact) click to toggle source
# File lib/puppet-lint/plugins/legacy_fact.rb, line 152
def replacement_fact(fact)
  find_static_fact(fact) || find_regex_fact(fact)
end