Class: Puppet::Interface

Inherits:
Object show all
Extended by:
ActionManager, OptionManager
Includes:
ActionManager, FullDocs, OptionManager, Util
Defined in:
lib/puppet/interface.rb,
lib/puppet/interface/documentation.rb

Defined Under Namespace

Modules: ActionManager, DocGen, FaceCollection, FullDocs, OptionManager, TinyDocs Classes: Action, ActionBuilder, Option, OptionBuilder

Constant Summary

Constants included from Util

Util::AbsolutePathPosix, Util::AbsolutePathWindows, Util::DEFAULT_POSIX_MODE, Util::DEFAULT_WINDOWS_MODE, Util::PUPPET_STACK_INSERTION_FRAME, Util::RFC_3986_URI_REGEX

Constants included from Util::POSIX

Util::POSIX::LOCALE_ENV_VARS, Util::POSIX::USER_ENV_VARS

Constants included from Util::SymbolicFileMode

Util::SymbolicFileMode::SetGIDBit, Util::SymbolicFileMode::SetUIDBit, Util::SymbolicFileMode::StickyBit, Util::SymbolicFileMode::SymbolicMode, Util::SymbolicFileMode::SymbolicSpecialToBit

Instance Attribute Summary collapse

Attributes included from FullDocs

#copyright_owner, #copyright_years

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActionManager

action, action?, actions, deactivate_action, get_action, get_default_action

Methods included from OptionManager

add_option, all_display_global_options, display_global_options, get_option, option, option?, options, walk_inheritance_tree

Methods included from Util

absolute_path?, benchmark, chuser, clear_environment, default_env, deterministic_rand, deterministic_rand_int, exit_on_fail, format_backtrace_array, format_puppetstack_frame, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, resolve_stackframe, safe_posix_fork, set_env, symbolizehash, thinmark, uri_encode, uri_query_encode, uri_to_path, which, withenv, withumask

Methods included from Util::POSIX

#get_posix_field, #gid, groups_of, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Methods included from Util::SymbolicFileMode

#normalize_symbolic_mode, #symbolic_mode_to_int, #valid_symbolic_mode?

Methods included from FullDocs

#author, #author=, #authors, #copyright, #examples, #license, #munge_copyright_year, #notes, #short_description

Methods included from DocGen

#attr_doc, strip_whitespace

Methods included from TinyDocs

#build_synopsis, #description, #summary

Constructor Details

#initialize(name, version, &block) ⇒ Interface

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.

Returns a new instance of Interface.



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/puppet/interface.rb', line 151

def initialize(name, version, &block)
  unless SemanticPuppet::Version.valid?(version)
    raise ArgumentError, _("Cannot create face %{name} with invalid version number '%{version}'!") % { name: name.inspect, version: version }
  end

  @name    = Puppet::Interface::FaceCollection.underscorize(name)
  @version = SemanticPuppet::Version.parse(version)

  # 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
  @authors  = []
  @license  = 'All Rights Reserved'

  @loader = Puppet::Util::Autoload.new(@name, "puppet/face/#{@name}")
  instance_eval(&block) if block_given?
end

Instance Attribute Details

#nameSymbol (readonly)

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.

The name of the face

Returns:

  • (Symbol)


138
139
140
# File 'lib/puppet/interface.rb', line 138

def name
  @name
end

#versionSemanticPuppet::Version (readonly)

The version of the face

Returns:

  • (SemanticPuppet::Version)


142
143
144
# File 'lib/puppet/interface.rb', line 142

def version
  @version
end

Class Method Details

.[](name, version) ⇒ Puppet::Interface

Retrieves a face by name and version

Parameters:

  • name (Symbol)

    the name of the face

  • version (String)

    the version of the face

Returns:



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/puppet/interface.rb', line 93

def [](name, version)
  face = Puppet::Interface::FaceCollection[name, version]
  unless face
    # REVISIT (#18042) no sense in rechecking if version == :current -- josh
    if Puppet::Interface::FaceCollection[name, :current]
      raise Puppet::Error, "Could not find version #{version} of #{name}"
    else
      raise Puppet::Error, "Could not find Puppet Face #{name}"
    end
  end

  face
end

.define(name, version, {|| ... }) ⇒ Puppet::Interface

TODO:

Talk about using Faces DSL inside the block

Defines a new Face.

Parameters:

  • name (Symbol)

    the name of the face

  • version (String)

    the version of the face (this should conform to / Semantic Versioning)

Returns:



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/puppet/interface.rb', line 57

def define(name, version, &block)
  face = Puppet::Interface::FaceCollection[name, version]
  if face.nil? then
    face = self.new(name, version)
    Puppet::Interface::FaceCollection.register(face)
    # REVISIT: Shouldn't this be delayed until *after* we evaluate the
    # current block, not done before? --daniel 2011-04-07
    face.load_actions
  end

  face.instance_eval(&block) if block_given?

  return face
end

.face?(name, version) ⇒ Puppet::Interface

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

Parameters:

  • name (Symbol)

    the name of the face

  • version (String, :current)

    the version of the face

Returns:



81
82
83
# File 'lib/puppet/interface.rb', line 81

def face?(name, version)
  Puppet::Interface::FaceCollection[name, version]
end

.facesArray<Symbol>

Lists all loaded faces

Returns:

  • (Array<Symbol>)

    The names of the loaded faces



35
36
37
# File 'lib/puppet/interface.rb', line 35

def faces
  Puppet::Interface::FaceCollection.faces
end

.find_action(name, action, version = :current) ⇒ Puppet::Interface::Action

Retrieves an action for a face

Parameters:

  • name (Symbol)

    The face

  • action (Symbol)

    The action name

  • version (String, :current) (defaults to: :current)

    The version of the face

Returns:



112
113
114
# File 'lib/puppet/interface.rb', line 112

def find_action(name, action, version = :current)
  Puppet::Interface::FaceCollection.get_action_for_face(name, action, version)
end

.register(instance) ⇒ void

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.

Register a face

Parameters:



43
44
45
# File 'lib/puppet/interface.rb', line 43

def register(instance)
  Puppet::Interface::FaceCollection.register(instance)
end

Instance Method Details

#deprecatevoid

This method returns an undefined value.



185
186
187
# File 'lib/puppet/interface.rb', line 185

def deprecate
  @deprecated = true
end

#deprecated?Boolean

Returns:

  • (Boolean)


190
191
192
# File 'lib/puppet/interface.rb', line 190

def deprecated?
  @deprecated
end

#load_actionsvoid

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.

Loads all actions defined in other files.



173
174
175
# File 'lib/puppet/interface.rb', line 173

def load_actions
  loader.loadall(Puppet.lookup(:current_environment))
end

#synopsisString

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.

Returns the synopsis for the face. This shows basic usage and global options.

Returns:

  • (String)

    usage synopsis



128
129
130
# File 'lib/puppet/interface.rb', line 128

def synopsis
  build_synopsis self.name, '<action>'
end

#to_sString Also known as: inspect

Returns a string representation with the face’s name and version

Returns:

  • (String)


179
180
181
# File 'lib/puppet/interface.rb', line 179

def to_s
  "Puppet::Face[#{name.inspect}, #{version.inspect}]"
end