Class: Puppet::Interface

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

Overview

This isn't usable outside Puppet::Interface; don't load it alone.

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

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, get_action, get_default_action, script

Methods included from OptionManager

add_option, get_option, option, option?, options

Methods included from Util

absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, #execfail, #execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, replace_file, safe_posix_fork, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, uri_to_path, wait_for_output, which, withumask

Methods included from Util::POSIX

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

Methods included from FullDocs

#author, #author=, #authors, #copyright, #munge_copyright_year, #short_description

Methods included from DocGen

#attr_doc, strip_whitespace

Methods included from TinyDocs

#build_synopsis

Constructor Details

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

Returns a new instance of Interface.



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

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

  @name    = Puppet::Interface::FaceCollection.underscorize(name)
  @version = SemVer.new(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'

  instance_eval(&block) if block_given?
end

Instance Attribute Details

#name ⇒ Object (readonly)

Returns the value of attribute name.



89
90
91
# File 'lib/vendor/puppet/interface.rb', line 89

def name
  @name
end

#version ⇒ Object (readonly)

Returns the value of attribute version.



89
90
91
# File 'lib/vendor/puppet/interface.rb', line 89

def version
  @version
end

Class Method Details

.[](name, version) ⇒ Object



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

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

.autoloader ⇒ Object

This is just so we can search for actions. We only use its list of directories to search. Can't we utilize an external autoloader, or simply use the $LOAD_PATH? -pvb



26
27
28
# File 'lib/vendor/puppet/interface.rb', line 26

def autoloader
  @autoloader ||= Puppet::Util::Autoload.new(:application, "puppet/face")
end

.define(name, version, &block) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vendor/puppet/interface.rb', line 38

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) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/vendor/puppet/interface.rb', line 53

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

.faces ⇒ Object



30
31
32
# File 'lib/vendor/puppet/interface.rb', line 30

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

.find_action(name, action, version = :current) ⇒ Object



68
69
70
# File 'lib/vendor/puppet/interface.rb', line 68

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

.register(instance) ⇒ Object



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

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

Instance Method Details

#load_actions ⇒ Object

Try to find actions defined in other files.



109
110
111
112
113
114
115
116
117
# File 'lib/vendor/puppet/interface.rb', line 109

def load_actions
  Puppet::Interface.autoloader.search_directories.each do |dir|
    Dir.glob(File.join(dir, "puppet/face/#{name}", "*.rb")).each do |file|
      action = file.sub(dir, '').sub(/^[\\\/]/, '').sub(/\.rb/, '')
      Puppet.debug "Loading action '#{action}' for '#{name}' from '#{dir}/#{action}.rb'"
      require(action)
    end
  end
end

#set_default_format(format) ⇒ Object



73
74
75
# File 'lib/vendor/puppet/interface.rb', line 73

def set_default_format(format)
  Puppet.warning("set_default_format is deprecated (and ineffective); use render_as on your actions instead.")
end

#synopsis ⇒ Object

Documentation. We currently have to rewrite both getters because we share the same instance between build-time and the runtime instance. When that splits out this should merge into a module that both the action and face include. --daniel 2011-04-17



83
84
85
# File 'lib/vendor/puppet/interface.rb', line 83

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

#to_s ⇒ Object



119
120
121
# File 'lib/vendor/puppet/interface.rb', line 119

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