Class: Puppet::Pops::Issues::MessageData Private

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/issues.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Provides a binding of arguments passed to Issue.format to method names available in the issue’s message producing block.

Instance Method Summary collapse

Constructor Details

#initialize(*argnames) ⇒ MessageData

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of MessageData.



65
66
67
68
69
70
71
72
# File 'lib/puppet/pops/issues.rb', line 65

def initialize *argnames
  singleton = class << self; self end
  argnames.each do |name|
    singleton.send(:define_method, name) do
      @data[name]
    end
  end
end

Instance Method Details

#format(hash, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



74
75
76
77
# File 'lib/puppet/pops/issues.rb', line 74

def format(hash, &block)
  @data = hash
  instance_eval(&block)
end

#label(*args) ⇒ LabelProvider, String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Obtains the label provider given as a key ‘:label` in the hash passed to #format. The label provider is return if no arguments are given. If given an argument, returns the result of calling #label on the label provider.

Parameters:

  • args (Object)

    one object to obtain a label for or zero arguments to obtain the label provider

Returns:

  • (LabelProvider, String)

    the label provider or label depending on if an argument is given or not

Raises:



86
87
88
# File 'lib/puppet/pops/issues.rb', line 86

def label(*args)
  args.empty? ? label_provider : label_provider.label(args[0])
end

#label_providerLabelProvider

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the label provider given as key ‘:label` in the hash passed to #format.

Returns:

Raises:



93
94
95
96
97
98
99
# File 'lib/puppet/pops/issues.rb', line 93

def label_provider
  label_provider = @data[:label]
  # TRANSLATORS ":label" is a keyword and should not be translated
  raise Puppet::Error, _('Label provider key :label must be set to produce the text of the message!') unless label_provider

  label_provider
end

#semanticObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the label provider given as a key in the hash passed to #format.

Raises:



103
104
105
106
107
108
# File 'lib/puppet/pops/issues.rb', line 103

def semantic
  # TRANSLATORS ":semantic" is a keyword and should not be translated
  raise Puppet::Error, _('Label provider key :semantic must be set to produce the text of the message!') unless @data[:semantic]

  @data[:semantic]
end