class String

Basic implementation of 'string' % { } like we need it. needs work.

Internal: Monkey patching String.

Constants

Percent

Public Instance Methods

%(*a, &b) click to toggle source
# File lib/puppet-lint/monkeypatches/string_percent.rb, line 15
def % *a, &b
  a.flatten!

  string = case a.last
  when Hash
    expand a.pop
  else
    self
  end

  if a.empty?
    string
  else
    Percent.bind(string).call(a, &b)
  end

end
expand(opts = {}) click to toggle source
# File lib/puppet-lint/monkeypatches/string_percent.rb, line 48
def expand opts = {}
  dup.expand! opts
end
expand!(vars = {}) click to toggle source
# File lib/puppet-lint/monkeypatches/string_percent.rb, line 32
def expand! vars = {}
  loop do
    changed = false
    vars.each do |var, value|
      var = var.to_s
      var.gsub! /[^a-zA-Z0-9_]/, ''
      [
        /\%\{#{ var }\}/,
      ].each do |pat|
        changed = gsub! pat, "#{ value }"
      end
    end
    break unless changed
  end
  self
end
prepend(lead) click to toggle source

Internal: Prepends a String to self.

lead - The String to prepend self with.

Returns a String which is lead and self concatenated.

# File lib/puppet-lint/monkeypatches/string_prepend.rb, line 9
def prepend(lead)
  self.replace "#{lead}#{self}"
end