Top Level Namespace

Includes:
Sys

Defined Under Namespace

Modules: DOT, DeepMerge, Enumerable, FFI, Generators, HieraPuppet, Kernel, PSON, Puppet, PuppetX, RDoc, StringBlank Classes: CheckPuppet, Class, ExternalNode, Formatter, GitIgnoreSpec, Hash, Hiera, JsonCatalogEncoder, MyExternalNode, Object, PathSpec, RegexSpec, Spec, TestDeepMerge, TypeDoc, UserAttr, WindowsDaemon

Constant Summary collapse

SEPARATOR =
[Regexp.escape(File::SEPARATOR.to_s), Regexp.escape(File::ALT_SEPARATOR.to_s)].join
BASEDIR =
Dir.chdir(File.dirname(__FILE__) + "/..") { Dir.getwd }
WORKINGDIR =
"#{p.realpath}"

Instance Method Summary collapse

Instance Method Details

#_(msg) ⇒ Object

These stub the translation methods normally brought in by FastGettext. Used when Gettext could not be properly initialized.



4
5
6
# File 'lib/puppet/gettext/stubs.rb', line 4

def _(msg)
  msg
end

#dateObject

lib/trollop.rb – trollop command-line processing library

Author

William Morgan (mailto: [email protected])

Copyright

Copyright 2007 William Morgan

License

the same terms as ruby itself

2012-03: small changes made by cprice ([email protected]);

patch submitted for upstream consideration:
https://gitorious.org/trollop/mainline/merge_requests/9

2012-08: namespace changes made by Jeff McCune ([email protected])

moved Trollop into Puppet::Util::CommandLine to prevent monkey
patching the upstream trollop library if also loaded.


13
# File 'lib/puppet/util/command_line/trollop.rb', line 13

require 'date'

#log(message, level = :debug) ⇒ Object

Helper method to log to syslog; we log at level debug if no level is specified since those are the most frequent calls to this method



65
66
67
# File 'ext/regexp_nodes/regexp_nodes.rb', line 65

def log(message,level=:debug)
  Syslog.send(level,message)
end

#n_(*args, &block) ⇒ Object



8
9
10
11
# File 'lib/puppet/gettext/stubs.rb', line 8

def n_(*args, &block)
  plural = args[2] == 1 ? args[0] : args[1]
  block ? block.call : plural
end

#post_compileObject

Since:

  • 3.4.0



# File 'lib/puppet/parameter.rb', line 561

#read_node(node) ⇒ Object

Read in a pure yaml representation of our node.



62
63
64
65
66
67
68
69
# File 'ext/yaml_nodes.rb', line 62

def read_node(node)
  nodefile = File.join(YAMLDIR, "#{node}.yaml")
  if FileTest.exist?(nodefile)
    return YAML.load_file(nodefile)
  else
    raise "Could not find information for #{node}"
  end
end

#regsubstArray[String], String

Performs regexp replacement on a string or array of strings.

“‘puppet $i3 = regsubst($ipaddress,’^(\d+)\.(\d+)\.(\d+)\.(\d+)$‘,’\3’) “‘

“‘puppet $x = regsubst($ipaddress, /([0-9]+)/, ’<\1>‘, ’G’) “‘

Examples:

Get the third octet from the node’s IP address:

Put angle brackets around each octet in the node’s IP address:

Parameters:

  • target (String, Array[String])

    The string or array of strings to operate on. If an array, the replacement will be performed on each of the elements in the array, and the return value will be an array.

  • pattern (String, Regexp, Type[Regexp])

    The regular expression matching the target string. If you want it anchored at the start and or end of the string, you must do that with ^ and $ yourself.

  • replacement (String, Hash[String, String])

    Replacement string. Can contain backreferences to what was matched using \0 (whole match), \1 (first set of parentheses), and so on. If the second argument is a Hash, and the matched text is one of its keys, the corresponding value is the replacement string.

  • flags (Optional[Pattern[/^[GEIM]*$/]], Pattern[/^G?$/])

    Optional. String of single letter flags for how the regexp is interpreted (E, I, and M cannot be used if pattern is a precompiled regexp):

    - *E*         Extended regexps
    - *I*         Ignore case in regexps
    - *M*         Multiline regexps
    - *G*         Global replacement; all occurrences of the regexp in each target string will be replaced.  Without this, only the first occurrence will be replaced.
    
  • encoding (Enum['N','E','S','U'])

    Optional. How to handle multibyte characters when compiling the regexp (must not be used when pattern is a precompiled regexp). A single-character string with the following values:

    - *N*         None
    - *E*         EUC
    - *S*         SJIS
    - *U*         UTF-8
    

Returns:

  • (Array[String], String)

    The result of the substitution. Result type is the same as for the target parameter.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/puppet/functions/regsubst.rb', line 41

Puppet::Functions.create_function(:regsubst) do
  dispatch :regsubst_string do
    param          'Variant[Array[String],String]',       :target
    param          'String',                              :pattern
    param          'Variant[String,Hash[String,String]]', :replacement
    optional_param 'Optional[Pattern[/^[GEIM]*$/]]',      :flags
    optional_param "Enum['N','E','S','U']",               :encoding
  end

  dispatch :regsubst_regexp do
    param          'Variant[Array[String],String]',       :target
    param          'Variant[Regexp,Type[Regexp]]',        :pattern
    param          'Variant[String,Hash[String,String]]', :replacement
    optional_param 'Pattern[/^G?$/]',                     :flags
  end

  def regsubst_string(target, pattern, replacement, flags = nil, encoding = nil)
    re_flags = 0
    operation = :sub
    if !flags.nil?
      flags.split(//).each do |f|
        case f
        when 'G' then operation = :gsub
        when 'E' then re_flags |= Regexp::EXTENDED
        when 'I' then re_flags |= Regexp::IGNORECASE
        when 'M' then re_flags |= Regexp::MULTILINE
        end
      end
    end
    inner_regsubst(target, Regexp.compile(pattern, re_flags, encoding), replacement, operation)
  end

  def regsubst_regexp(target, pattern, replacement, flags = nil)
    pattern = (pattern.pattern || '') if pattern.is_a?(Puppet::Pops::Types::PRegexpType)
    inner_regsubst(target, pattern, replacement, flags == 'G' ? :gsub : :sub)
  end

  def inner_regsubst(target, re, replacement, op)
    target.respond_to?(op) ? target.send(op, re, replacement) : target.collect { |e| e.send(op, re, replacement) }
  end
  private :inner_regsubst
end