class Puppet::Interface

@api public

Attributes

loader[R]

The autoloader instance for the face @return [Puppet::Util::Autoload] @api private

name[R]

The name of the face @return [Symbol] @api private

version[R]

The version of the face @return [SemanticPuppet::Version]

Public Class Methods

[](name, version) click to toggle source

Retrieves a face by name and version

@param name [Symbol] the name of the face @param version [String] the version of the face

@return [Puppet::Interface] the face

@api public

    # File lib/puppet/interface.rb
 94 def [](name, version)
 95   face = Puppet::Interface::FaceCollection[name, version]
 96   unless face
 97     # REVISIT (#18042) no sense in rechecking if version == :current -- josh
 98     if Puppet::Interface::FaceCollection[name, :current]
 99       raise Puppet::Error, "Could not find version #{version} of #{name}"
100     else
101       raise Puppet::Error, "Could not find Puppet Face #{name}"
102     end
103   end
104 
105   face
106 end
define(name, version, &block) click to toggle source

Defines a new Face. @todo Talk about using Faces DSL inside the block

@param name [Symbol] the name of the face @param version [String] the version of the face (this should

conform to {http://semver.org/ Semantic Versioning})

@overload define(name, version, {|| … }) @return [Puppet::Interface] The created face @api public @dsl Faces

   # File lib/puppet/interface.rb
58 def define(name, version, &block)
59   face = Puppet::Interface::FaceCollection[name, version]
60   if face.nil? then
61     face = self.new(name, version)
62     Puppet::Interface::FaceCollection.register(face)
63     # REVISIT: Shouldn't this be delayed until *after* we evaluate the
64     # current block, not done before? --daniel 2011-04-07
65     face.load_actions
66   end
67 
68   face.instance_eval(&block) if block_given?
69 
70   return face
71 end
face?(name, version) click to toggle source

Retrieves a face by name and version. Use `:current` for the version to get the most recent available version.

@param name [Symbol] the name of the face @param version [String, :current] the version of the face

@return [Puppet::Interface] the face

@api public

   # File lib/puppet/interface.rb
82 def face?(name, version)
83   Puppet::Interface::FaceCollection[name, version]
84 end
faces() click to toggle source

Lists all loaded faces @return [Array<Symbol>] The names of the loaded faces

   # File lib/puppet/interface.rb
36 def faces
37   Puppet::Interface::FaceCollection.faces
38 end
find_action(name, action, version = :current) click to toggle source

Retrieves an action for a face @param name [Symbol] The face @param action [Symbol] The action name @param version [String, :current] The version of the face @return [Puppet::Interface::Action] The action

    # File lib/puppet/interface.rb
113 def find_action(name, action, version = :current)
114   Puppet::Interface::FaceCollection.get_action_for_face(name, action, version)
115 end
new(name, version, &block) click to toggle source

@api private

    # File lib/puppet/interface.rb
152 def initialize(name, version, &block)
153   unless SemanticPuppet::Version.valid?(version)
154     raise ArgumentError, _("Cannot create face %{name} with invalid version number '%{version}'!") % { name: name.inspect, version: version }
155   end
156 
157   @name    = Puppet::Interface::FaceCollection.underscorize(name)
158   @version = SemanticPuppet::Version.parse(version)
159 
160   # The few bits of documentation we actually demand.  The default license
161   # is a favour to our end users; if you happen to get that in a core face
162   # report it as a bug, please. --daniel 2011-04-26
163   @authors  = []
164   @license  = 'All Rights Reserved'
165 
166   @loader = Puppet::Util::Autoload.new(@name, "puppet/face/#{@name}")
167   instance_eval(&block) if block_given?
168 end
register(instance) click to toggle source

Register a face @param instance [Puppet::Interface] The face @return [void] @api private

   # File lib/puppet/interface.rb
44 def register(instance)
45   Puppet::Interface::FaceCollection.register(instance)
46 end

Private Class Methods

__add_method(name, proc) click to toggle source

@return [void] @api private

    # File lib/puppet/interface.rb
235 def self.__add_method(name, proc)
236   define_method(name, proc)
237   instance_method(name)
238 end

Public Instance Methods

deprecate() click to toggle source

@return [void]

    # File lib/puppet/interface.rb
186 def deprecate
187   @deprecated = true
188 end
deprecated?() click to toggle source

@return [Boolean]

    # File lib/puppet/interface.rb
191 def deprecated?
192   @deprecated
193 end
inspect()
Alias for: to_s
load_actions() click to toggle source

Loads all actions defined in other files.

@return [void] @api private

    # File lib/puppet/interface.rb
174 def load_actions
175   loader.loadall(Puppet.lookup(:current_environment))
176 end
synopsis() click to toggle source

Returns the synopsis for the face. This shows basic usage and global options. @return [String] usage synopsis @api private

    # File lib/puppet/interface.rb
129 def synopsis
130   build_synopsis self.name, '<action>'
131 end
to_s() click to toggle source

Returns a string representation with the face's name and version @return [String]

    # File lib/puppet/interface.rb
180 def to_s
181   "Puppet::Face[#{name.inspect}, #{version.inspect}]"
182 end
Also aliased as: inspect

Private Instance Methods

__add_method(name, proc) click to toggle source

@return [void] @api private

    # File lib/puppet/interface.rb
228 def __add_method(name, proc)
229   meta_def(name, &proc)
230   method(name).unbind
231 end
__invoke_decorations(type, action, passed_args = [], passed_options = {}) click to toggle source

@return [void] @api private

    # File lib/puppet/interface.rb
207 def __invoke_decorations(type, action, passed_args = [], passed_options = {})
208   [:before, :after].member?(type) or fail "unknown decoration type #{type}"
209 
210   # Collect the decoration methods matching our pass.
211   methods = action.options.select do |name|
212     passed_options.has_key? name
213   end.map do |name|
214     action.get_option(name).__decoration_name(type)
215   end
216 
217   methods.reverse! if type == :after
218 
219   # Exceptions here should propagate up; this implements a hook we can use
220   # reasonably for option validation.
221   methods.each do |hook|
222     respond_to? hook and self.__send__(hook, action, passed_args, passed_options)
223   end
224 end