Method: Puppet::Interface::Action#set_rendering_method_for
- Defined in:
- lib/puppet/interface/action.rb
#set_rendering_method_for(type, proc) ⇒ 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.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/puppet/interface/action.rb', line 95 def set_rendering_method_for(type, proc) unless proc.is_a? Proc msg = if proc.nil? # TRANSLATORS 'set_rendering_method_for' and 'Proc' should not be translated _("The second argument to set_rendering_method_for must be a Proc") else # TRANSLATORS 'set_rendering_method_for' and 'Proc' should not be translated _("The second argument to set_rendering_method_for must be a Proc, not %{class_name}") % { class_name: proc.class.name } end raise ArgumentError, msg end if proc.arity != 1 and proc.arity != (@positional_arg_count + 1) msg = if proc.arity < 0 then # TRANSLATORS 'when_rendering', 'when_invoked' are method names and should not be translated _("The when_rendering method for the %{face} face %{name} action takes either just one argument,"\ " the result of when_invoked, or the result plus the %{arg_count} arguments passed to the"\ " when_invoked block, not a variable number") % { face: @face.name, name: name, arg_count: @positional_arg_count } else # TRANSLATORS 'when_rendering', 'when_invoked' are method names and should not be translated _("The when_rendering method for the %{face} face %{name} action takes either just one argument,"\ " the result of when_invoked, or the result plus the %{arg_count} arguments passed to the"\ " when_invoked block, not %{string}") % { face: @face.name, name: name, arg_count: @positional_arg_count, string: proc.arity.to_s } end raise ArgumentError, msg end unless type.is_a? Symbol raise ArgumentError, _("The rendering format must be a symbol, not %{class_name}") % { class_name: type.class.name } end if @when_rendering.has_key? type then raise ArgumentError, _("You can't define a rendering method for %{type} twice") % { type: type } end # Now, the ugly bit. We add the method to our interface object, and # retrieve it, to rotate through the dance of getting a suitable method # object out of the whole process. --daniel 2011-04-18 @when_rendering[type] = @face.__send__(:__add_method, __render_method_name_for(type), proc) end |