Class: Puppet::Interface::Action Private
- Inherits:
-
Object
- Object
- Puppet::Interface::Action
- Extended by:
- DocGen
- Includes:
- FullDocs
- Defined in:
- lib/puppet/interface/action.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.
This represents an action that is attached to a face. Actions should be constructed by calling Puppet::Interface::ActionManager#action, which is available on Puppet::Interface, and then calling methods of ActionBuilder in the supplied block.
Instance Attribute Summary (collapse)
-
- (Boolean) default
private
Whether this is the default action for the face.
-
- (Symbol) render_as
private
Attributes included from FullDocs
#copyright_owner, #copyright_years
Instance Method Summary (collapse)
-
- __add_method(name, proc)
private
-
- __dup_and_rebind_to(to)
private
-
- __render_method_name_for(type)
private
-
- (Action) initialize(face, name, attrs = {})
constructor
private
A new instance of Action.
-
- (Object) set_rendering_method_for(type, proc)
private
-
- (Object) when_rendering(type)
private
Methods included from DocGen
Methods included from FullDocs
#author=, #authors, #copyright, #munge_copyright_year
Methods included from TinyDocs
#build_synopsis, #description, #summary
Constructor Details
- (Action) initialize(face, name, attrs = {}) private
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.
A new instance of Action
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/puppet/interface/action.rb', line 17 def initialize(face, name, attrs = {}) raise "#{name.inspect} is an invalid action name" unless name.to_s =~ /^[a-z]\w*$/ @face = face @name = name.to_sym # The few bits of documentation we actually demand. The default license # is a favour to our end users; if you happen to get that in a core face # report it as a bug, please. --daniel 2011-04-26 = [] @license = 'All Rights Reserved' (attrs) # @options collects the added options in the order they're declared. # @options_hash collects the options keyed by alias for quick lookups. = [] = [] = {} @when_rendering = {} end |
Instance Attribute Details
- (Boolean) default private
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.
Whether this is the default action for the face
63 64 65 |
# File 'lib/puppet/interface/action.rb', line 63 def default @default end |
- (Symbol) render_as private
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.
139 140 141 |
# File 'lib/puppet/interface/action.rb', line 139 def render_as @render_as end |
Instance Method Details
- __add_method(name, proc) (private) private
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.
This method returns an undefined value.
374 375 376 |
# File 'lib/puppet/interface/action.rb', line 374 def __add_method(name, proc) @face.__send__ :__add_method, name, proc end |
- __dup_and_rebind_to(to) private
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.
This method returns an undefined value.
44 45 46 47 48 |
# File 'lib/puppet/interface/action.rb', line 44 def __dup_and_rebind_to(to) bound_version = self.dup bound_version.instance_variable_set(:@face, to) return bound_version end |
- __render_method_name_for(type) (private) private
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.
This method returns an undefined value.
131 132 133 |
# File 'lib/puppet/interface/action.rb', line 131 def __render_method_name_for(type) :"#{name}_when_rendering_#{type}" end |
- (Object) set_rendering_method_for(type, proc) private
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.
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 |
# File 'lib/puppet/interface/action.rb', line 97 def set_rendering_method_for(type, proc) unless proc.is_a? Proc msg = "The second argument to set_rendering_method_for must be a Proc" msg += ", not #{proc.class.name}" unless proc.nil? raise ArgumentError, msg end if proc.arity != 1 and proc.arity != (@positional_arg_count + 1) msg = "the when_rendering method for the #{@face.name} face #{name} action " msg += "takes either just one argument, the result of when_invoked, " msg += "or the result plus the #{@positional_arg_count} arguments passed " msg += "to the when_invoked block, not " if proc.arity < 0 then msg += "a variable number" else msg += proc.arity.to_s end raise ArgumentError, msg end unless type.is_a? Symbol raise ArgumentError, "The rendering format must be a symbol, not #{type.class.name}" end if @when_rendering.has_key? type then raise ArgumentError, "You can't define a rendering method for #{type} twice" 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 |
- (Object) when_rendering(type) private
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.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/puppet/interface/action.rb', line 81 def when_rendering(type) unless type.is_a? Symbol raise ArgumentError, "The rendering format must be a symbol, not #{type.class.name}" end # Do we have a rendering hook for this name? return @when_rendering[type].bind(@face) if @when_rendering.has_key? type # How about by another name? alt = type.to_s.sub(/^to_/, '').to_sym return @when_rendering[alt].bind(@face) if @when_rendering.has_key? alt # Guess not, nothing to run. return nil end |