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

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, get_env, get_environment, logmethods, merge_environment, path_to_uri, pretty_backtrace, replace_file, 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, #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.



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

def initialize(name, version, &block)
  unless SemanticPuppet::Version.valid?(version)
    raise ArgumentError, "Cannot create face #{name.inspect} with invalid version number '#{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)


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

def name
  @name
end

#versionSemanticPuppet::Version (readonly)

The version of the face



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

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
# File 'lib/puppet/interface.rb', line 93

def [](name, version)
  unless face = Puppet::Interface::FaceCollection[name, version]
    # 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.to_s}"
    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:



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

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.



183
184
185
# File 'lib/puppet/interface.rb', line 183

def deprecate
  @deprecated = true
end

#deprecated?Boolean

Returns:

  • (Boolean)


188
189
190
# File 'lib/puppet/interface.rb', line 188

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.



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

def load_actions
  loader.loadall
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



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

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

#to_sString

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

Returns:

  • (String)


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

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