Class: Puppet::Pops::Issues::Issue
Overview
Describes an issue, and can produce a message for an occurrence of the issue.
Instance Attribute Summary collapse
-
#arg_names ⇒ Object
readonly
Names that must be bound in an occurrence of the issue to be able to produce a message.
-
#demotable ⇒ Object
writeonly
If this issue can have its severity lowered to :warning, :deprecation, or :ignored.
-
#issue_code ⇒ Symbol
readonly
The issue code.
-
#message_block ⇒ Proc
readonly
A block producing the message.
Instance Method Summary collapse
-
#demotable? ⇒ Boolean
Returns true if it is allowed to demote this issue.
-
#format(hash = {}) ⇒ Object
Formats a message for an occurrence of the issue with argument bindings passed in a hash.
-
#initialize(issue_code, *args, &block) ⇒ Issue
constructor
Configures the Issue with required arguments (bound by occurrence), and a block producing a message.
Constructor Details
#initialize(issue_code, *args, &block) ⇒ Issue
Configures the Issue with required arguments (bound by occurrence), and a block producing a message.
29 30 31 32 33 34 |
# File 'lib/puppet/pops/issues.rb', line 29 def initialize issue_code, *args, &block @issue_code = issue_code @message_block = block @arg_names = args @demotable = true end |
Instance Attribute Details
#arg_names ⇒ Object (readonly)
Names that must be bound in an occurrence of the issue to be able to produce a message. These are the names in addition to requirements stipulated by the Issue formatter contract; i.e. :label`, and ‘:semantic`.
23 24 25 |
# File 'lib/puppet/pops/issues.rb', line 23 def arg_names @arg_names end |
#demotable=(value) ⇒ Object (writeonly)
If this issue can have its severity lowered to :warning, :deprecation, or :ignored
26 27 28 |
# File 'lib/puppet/pops/issues.rb', line 26 def demotable=(value) @demotable = value end |
#issue_code ⇒ Symbol (readonly)
The issue code
13 14 15 |
# File 'lib/puppet/pops/issues.rb', line 13 def issue_code @issue_code end |
#message_block ⇒ Proc (readonly)
A block producing the message
17 18 19 |
# File 'lib/puppet/pops/issues.rb', line 17 def @message_block end |
Instance Method Details
#demotable? ⇒ Boolean
Returns true if it is allowed to demote this issue
37 38 39 |
# File 'lib/puppet/pops/issues.rb', line 37 def demotable? @demotable end |
#format(hash = {}) ⇒ Object
Formats a message for an occurrence of the issue with argument bindings passed in a hash. The hash must contain a LabelProvider bound to the key ‘label` and the semantic model element bound to the key `semantic`. All required arguments as specified by `arg_names` must be bound in the given `hash`.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/puppet/pops/issues.rb', line 47 def format(hash = {}) # Create a Message Data where all hash keys become methods for convenient interpolation # in issue text. msgdata = MessageData.new(*arg_names) begin # Evaluate the message block in the msg data's binding msgdata.format(hash, &) rescue StandardError => e raise RuntimeError, _("Error while reporting issue: %{code}. %{message}") % { code: issue_code, message: e. }, caller end end |