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
 93 def [](name, version)
 94   face = Puppet::Interface::FaceCollection[name, version]
 95   unless face
 96     # REVISIT (#18042) no sense in rechecking if version == :current -- josh
 97     if Puppet::Interface::FaceCollection[name, :current]
 98       raise Puppet::Error, "Could not find version #{version} of #{name}"
 99     else
100       raise Puppet::Error, "Could not find Puppet Face #{name}"
101     end
102   end
103 
104   face
105 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
57 def define(name, version, &block)
58   face = Puppet::Interface::FaceCollection[name, version]
59   if face.nil? then
60     face = self.new(name, version)
61     Puppet::Interface::FaceCollection.register(face)
62     # REVISIT: Shouldn't this be delayed until *after* we evaluate the
63     # current block, not done before? --daniel 2011-04-07
64     face.load_actions
65   end
66 
67   face.instance_eval(&block) if block_given?
68 
69   return face
70 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
81 def face?(name, version)
82   Puppet::Interface::FaceCollection[name, version]
83 end
faces() click to toggle source

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

   # File lib/puppet/interface.rb
35 def faces
36   Puppet::Interface::FaceCollection.faces
37 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
112 def find_action(name, action, version = :current)
113   Puppet::Interface::FaceCollection.get_action_for_face(name, action, version)
114 end
new(name, version, &block) click to toggle source

@api private

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

Private Class Methods

__add_method(name, proc) click to toggle source

@return [void] @api private

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

Public Instance Methods

deprecate() click to toggle source

@return [void]

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

@return [Boolean]

    # File lib/puppet/interface.rb
190 def deprecated?
191   @deprecated
192 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
173 def load_actions
174   loader.loadall(Puppet.lookup(:current_environment))
175 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
128 def synopsis
129   build_synopsis self.name, '<action>'
130 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
179 def to_s
180   "Puppet::Face[#{name.inspect}, #{version.inspect}]"
181 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
227 def __add_method(name, proc)
228   meta_def(name, &proc)
229   method(name).unbind
230 end
__invoke_decorations(type, action, passed_args = [], passed_options = {}) click to toggle source

@return [void] @api private

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